keiii / console-service-provider
此包已被废弃,不再维护。未建议替代包。
Silex 的控制台服务提供商
2.2
2016-11-26 20:33 UTC
Requires
- php: >=5.6
- symfony/console: ~3.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.12
- phpunit/phpunit: >=4
- silex/silex: ~2.0
- symfony/twig-bridge: ~3.1
- twig/twig: ^1.24
This package is not auto-updated.
Last update: 2023-03-15 18:15:21 UTC
README
为 Silex 2 提供基于 Symfony\Component\Console
的控制台。
下载和安装
$ composer require keiii/console-service-provider
注册
#!/usr/bin/env php <?php $app = new Application(); $app->register(new ConsoleServiceProvider(), array( 'console.name' => 'MyApplication', 'console.version' => '1.0.0', )); $console = $app['console']; $console->add(new MyCommand()); $console->run();
编写命令
您的命令应扩展 KEIII\SilexConsole\Command
以访问 getSilexApplication
,该函数返回 Silex 应用程序。
用法
就像使用任何基于 Symfony\Component
的控制台一样使用控制台。
$ app/console my:command
记录异常
<?php $app['logger'] = $app::share(function () { return new MyLogger(); // \Psr\Log\LoggerInterface }); $app['console.log.listener'] = $app::share(function (Application $app) { return new \KEIII\SilexConsole\ConsoleLogListener($app['logger']); }); $app['dispatcher']->addSubscriber($app['console.log.listener']);