框架优点
配合swoole可以实现脚本配置自动挂载crontab和nobup形式;同样使用swoole的毫秒定时器来实现毫秒级别和秒级别的脚本定制;可以使用一些简单的命令来查看以及执行编写的脚本;框架易于扩展;
源码地址:github.com/ybscript/yb…
如果有什么需要指教的地方欢迎留言;不足之处希望给予之处,会及时完善,希望最后可以有完美的框架;
可以支持三种方式来写脚本
1、使用闭包的方式来制作脚本
$console->command('demo', function (\Inhere\Console\IO\Input $in, \Inhere\Console\IO\Output $out) {
$cmd = $in->getCommand();
$out->info('hello, this is a test command: ' . $cmd);
}, 'this is message for the command');
复制代码
2、使用command的方式
class ExampleCommand extends Command
{
protected static $name = 'example';
protected static $description = 'this is test example';
/**
* do execute command
* example php ybTask example --param='hello,this param'
* @param Input $input
* @param Output $output
* @return int|mixed
*/
protected function execute($input, $output)
{
// TODO: Implement execute() method.
$output->write('hello, this in example command');
//get param
print_r($input->getOpts());
$this->write($input->getOpt('param'));
}
}
复制代码
3、使用controller方式
class SiteController extends BaseController
{
protected static $name = 'site';
protected static $description = 'this is site example';
/**
* this is test command
* example php ybTask site:test --param='hello,this param'
* use getOpt() / boolOpt() /
*/
public function testCommand()
{
var_dump(self::annotationVars());
$this->write('hello,this is site!');
//get param
print_r($this->getInput()->getOpts());
$this->write($this->getOpt('param'));
}
}
复制代码