vaibhavpandeyvpz/consoler
Extensions for symfony/console adding support for using any container-interop/container-interop compatible package.
Install
composer require vaibhavpandeyvpz/consolerYou may also want to install vaibhavpandeyvpz/katora to provide Interop\Container\ContainerInterface. To do so, run following:
composer require vaibhavpandeyvpz/katoraUsage
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.