dev-master
9999999-devCLI application service provider for Silex
MIT
The Requires
service php console silex provider serviceprovider
Wallogit.com
2017 © Pedro Peláez
CLI application service provider for Silex
Provides for Silex :, (*1)
$ php bin/console cache:clear.Please check Console component documentation for more details about how to use console and build commands., (*2)
Import the provider with Composer:, (*3)
$ composer require bgaze/silex-console-provider dev-master
Clear cache commands requires cache path to be defined under cache_dir key :, (*4)
$app['cache_dir'] = __DIR__ . '/../var/cache';
Then register it in your app :, (*5)
use Bgaze\Silex\Provider\ConsoleServiceProvider; $app->register(new ConsoleServiceProvider(), ['console.name' => 'My Application', 'console.version' => 'n/a']); $app['console']->add(new \Bgaze\Silex\Console\Command\ClearCacheCommand());
Assuming your console executable is bin/console, call any of command like this :, (*6)
$ php bin/console your:command
Clear your application cache like this :, (*7)
$ php bin/console cache:clear
Your commands should extend Bgaze\Silex\Console\Command\AbstractCommand.
This base class provide acces to the current Silex application under $app protected attribute., (*8)
Here is a custom command example :, (*9)
<?php
namespace MyApp\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Bgaze\Silex\Console\Command\AbstractCommand;
class MyCommand extends AbstractCommand {
public function isEnabled() {
if (!isset($this->app['my_value'])) {
return false;
}
return parent::isEnabled();
}
protected function configure() {
$this
->setName('my:command')
->setDefinition([
new InputArgument('foo', InputArgument::REQUIRED, 'A required argument'),
new InputOption('bar', 'b', InputOption::VALUE_REQUIRED, 'An option with default value', 'Bar!')
])
->setDescription('This is a demo command ...');
}
protected function execute(InputInterface $input, OutputInterface $output) {
$foo = $input->getArgument('foo');
$output->writeln('Foo : ' . $foo);
$bar = $input->getOption('bar');
$output->writeln('Bar : ' . $bar);
}
}
This provider is heavily inspired from codito/silex-console-provider, (*10)
CLI application service provider for Silex
MIT
service php console silex provider serviceprovider