vaibhavpandeyvpz / consoler
Extensions for symfony/console adding support for using any container-interop/container-interop compatible package.
1.0.2
2016-04-10 10:11 UTC
Requires
- php: >=5.3.0
- container-interop/container-interop: ^1.1
- symfony/console: ^2.8
Suggests
- vaibhavpandeyvpz/katora: Minimal service container implementing container-interop/container-interop interfaces.
This package is auto-updated.
Last update: 2024-12-09 18:58:00 UTC
README
Extensions for symfony/console adding support for using any container-interop/container-interop compatible package.
Install
composer require vaibhavpandeyvpz/consoler
You may also want to install vaibhavpandeyvpz/katora to provide Interop\Container\ContainerInterface
. To do so, run following:
composer require vaibhavpandeyvpz/katora
Usage
Initialize a instance of Consoler\Application
with an Interop\Container\ContainerInterface
instance and run as usual.
#!/usr/bin/env php <?php require_once __DIR__ . '/vendor/autoload.php'; $app = new Consoler\Application(); $app->setContainer($container = new Katora\Container()); $container[PDO::class] = $container->share(function () { return new PDO(/** args */); }); $app->add(new SearchCommand()); $app->run();
Since Consoler\Command
class implements Interop\Container\ContainerInterface
, you can just extend it & use the container as below:
use Consoler\Command; use Symfony\Component\Console\Input\InputInterface as Input; use Symfony\Component\Console\Output\OutputInterface as Output; class SearchCommand extends Command { protected function execute(Input $input, Output $output) { /** @var \PDO $pdo */ $pdo = $this->get(\PDO::class); // ...more code! } }
License
See LICENSE.md file.