ecos新命令
创建myapp,在myapp里创建lib/command目录
新建一个文件hello.php
<?php /** * myapp_command_hello(myapp->app名称,command必须的,hello对应类名) * 所有命令类都继承自base_shell_prototype类 */ class myapp_command_hello extends base_shell_prototype{ //$command_world(command必须的,world命令) var $command_world = 'helloworld';//helloworld解释作用 function command_world(){ echo "hello,world\n"; } //dos执行方式 myapp:hello world(myapp->app名称,hello->文件名, command+world->方法名) }
新建一个文件world.php
<?php class myapp_command_world extends base_shell_prototype{ var $command_3guys = '3guys'; function command_3guys($t1,$t2,$t3){ echo '1\t',$t1,'\n'; echo '1\t',$t2,'\n'; echo '1\t',$t3,'\n'; } //dos执行 myapp:world 3guys 1 2 3(myapp->app名称,world->类名,command+3guys->方法名,1 2 3->参数) }
新建一个文件one.php
<?php class myapp_command_one extends base_shell_prototype{ var $command_one = 'one'; //$command_one_options(options参数)选项数组 var $command_one_options = array( 'quietly'=>array('title'=>'项目模板','short'=>'q'),//至于这里为何这么写我也不知道 'from'=>array('title'=>'项目模板','need_value'=>1) ); function command_one(){ $options = $this->get_options(); if($options['quietly']){ echo "hello, xxx\n"; }else{ echo "hello, world --from {$options['from']}\n"; } } //dos执行 myapp:one one --from 结果 hello,world --from(没传入from参数的值) //myapp:one one --from fuck 结果 hello,world --from fuck //myapp:one one --quietly 结果 hello xxx }
新建一个文件two.php
<?php class myapp_command_two extends base_shell_prototype{ var $command_cart = "cart"; function command_cart(){ $this->output_line("cart"); $rows = array(); $rows[] = array('type'); $rows[] = array('apple'); $rows[] = array('banana'); $this->output_table($rows); } //dos执行 myapp:two cart //$this->output_line()输出一个分行 //$this->output_table 将数组输出格式化好的表格 }
注意!一个命令一个文件