lokhman / silex-console
Silex 2.0+ 控制台应用程序
2.0.6
2017-03-17 15:07 UTC
Requires
- silex/silex: ~2.0
- symfony/console: ^3.2
- symfony/process: ^3.2
Suggests
- ext-pcntl: For process control in cron
- doctrine/dbal: For using Doctrine service provider
- doctrine/migrations: For using Doctrine Migrations service provider
- mtdowling/cron-expression: For using cron commands
README
为 Silex 2.0+ 微型框架提供的控制台应用程序。
此项目是
silex-tools
库的一部分。
安装
您可以使用 Composer 安装 silex-console
composer require lokhman/silex-console
文档
一个用于注册控制台命令和服务提供者的 Symfony Console 应用程序的包装类。
#!/usr/bin/env php
require __DIR__ . '/../vendor/autoload.php';
use Silex\Application;
use Silex\Provider as Providers;
use Lokhman\Silex\Console\Console;
use Lokhman\Silex\Console\Command as Commands;
use Lokhman\Silex\Console\Provider as Providers;
$app = new Application();
$app->register(new Providers\DoctrineServiceProvider());
$console = new Console($app);
// add console command
$console->add(new Commands\Session\SchemaCreateCommand());
// register console service providers
$console->registerServiceProvider(new Providers\DoctrineServiceProvider());
$console->registerServiceProvider(new Providers\DoctrineMigrationsServiceProvider(), [
'migrations.directory' => __DIR__ . '/../app/migrations',
'migrations.namespace' => 'Project\Migrations',
]);
$console->run();
控制台支持 ConfigServiceProvider
,并为所有注册的命令添加了 --env
(简写为 -e
) 选项。
定时任务命令
该库提供用于作为 cron 运行后台任务的命令。配置支持 cron 调度表达式。
$app = new Application([
'cron' => [
'task1' => [
'command' => 'app:some:command', // internal commands (always sync!)
'arguments' => ['--env' => $env], // arguments as array
'at' => '0 0 * * *', // cron expression
'output' => '&', // "&" is to redirect output to cron stdout
],
'task2' => [
'raw' => '/path/to/task2', // raw command line
'at' => '@daily', // cron expression
'output' => '/path/to/task2.log', // output to file
],
'task3' => [
'raw' => '/path/to/task3', // raw command line
'at' => '@annually', // cron expression
'output' => null, // disable output (default)
],
],
]);
$console = new Console($app);
$console->add(new Commands\Cron\RunCommand());
$console->run();
许可证
库遵循 MIT 许可证。包含的 LICENSE 文件详细说明了这一点。