一个专门用来写脚本跑脚本的PHP框架

框架优点

配合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'));
    }
}
复制代码
框架本身建立在Inhere\Console的支持下,MC架构,本身使用的orm是Illuminate/Database(熟悉laravel的开发者比较舒服),缓存使用开源的symfony/cache等等,如果你不喜欢这些,你随时可以使用composer来包含你自己习惯的包,之后你可以再框架中进行这些组件的注册挂载就可以很方便的使用,不注册同样可以使用,因为框架本身使用composer的psr-4的编码规范,规范使用命名空间即可同样调用;

转载于:https://juejin.im/post/5c45145d518825246b0ff4d3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值