ybscript/yb-job

PHP 脚本框架。

1.0.0 2019-01-21 01:11 UTC

This package is auto-updated.

Last update: 2024-09-11 18:36:47 UTC


README

a php script framework.

此框架支持 MC(模型和控制器)/命令/闭包。

您可以在 "/bootstrap/app.php" 中注册自己的组件。接下来,您可以使用 $app 挂载组件进行编码;

[1] 安装教程

(1) 第一种方法

1、克隆此项目

$ git clone xxxxxxxxxxxxxxxxxxxx

2、加载 vendor:

$ composer install

3、cd 根路径

$ cd yb-job

4、初始化项目

$ php init

(2) 第二种方法

1、创建项目

$ composer create-project ybscript/yb-job your-project-name

2、初始化项目

$ cd your-project-name
$ php init

前往此处,此项目已初始化。

[2] 这里有一些用法

(1)、查看所有现有脚本

$ php ybTask list

$ php ybTask

(2)、脚本服务操作

启动

$ php ybTask -p start

停止

$ php ybTask -p stop

刷新

$ php ybTask -p flash

提示

刷新操作非常重要!

当您添加脚本配置时,您需要执行它;

[3] 简单示例

1、使用闭包(/console/closureFiles/closure/example.php)

$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、使用命令(/console/commands/test/ExampleCommand.php)

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、使用控制器(/console/controllers/site/SiteController.php)

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'));
    }
}

[4] 配置新脚本

将新脚本添加到 "/config/task/handle.php";

您可以选择 swoole/crontab/nohup 的模式;

swoole 模式可以支持毫秒级;

[5] 深入研究

console: https://github.com/inhere/php-console

swoole:www.swoole.com