dev-master
9999999-devCLI commands for Pimple applications
MIT
The Requires
The Development Requires
by Julien Richarte
v1.0.0
1.0.0.0CLI commands for Pimple applications
MIT
The Requires
The Development Requires
by Julien Richarte
Wallogit.com
2017 © Pedro Peláez
CLI commands for Pimple applications
PimpleCli on Packagist, (*2)
PimpleCli is a tool that makes it easy creating command line application., (*3)
PimpleCli works with a Pimple container (eg: a Silex application) and a Console Application (eg: using http://symfony.com/doc/current/components/console/introduction.html). PimpleCli's role is to discover commands in the Pimple container to make them availlable the the Console Application., (*4)
Commands needs to be registered as a service with a name ending in '.command'. The command can be anything (class, callable, etc.) that the console application understand. When using the Symfony\Component\Console\Application command should extends Symfony\Component\Console\Command\Command. You can take a look at the Console Components documentation to get started., (*5)
Through Composer :, (*6)
{
"require": {
"gitory/pimple-cli": "~1.0"
}
}
composer.json, (*7)
{
"require": {
"silex/silex": "~2.0@dev",
"gitory/pimple-cli": "~1.0",
"symfony/console": "~2.0"
}
}
GreetCommand.php, (*8)
namespace Acme\DemoBundle\Command;
use Symfony\Component\Console\Command\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;
class GreetCommand extends Command
{
protected function configure()
{
$this
->setName('demo:greet')
->setDescription('Greet someone')
->addArgument('name', InputArgument::REQUIRED, 'Who do you want to greet?')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$text = 'Hello '.$name;
$output->writeln($text);
}
}
index.php, (*9)
require_once __DIR__.'/vendor/autoload.php';
require_once 'GreetCommand.php';
$silexApp = new Silex\Application();
$silexApp->register(new Gitory\PimpleCli\ServiceCommandServiceProvider());
// add your command as services ending in '.command' in your DI
$silexApp['user.new.command'] = function () {
return new Acme\DemoBundle\Command\GreetCommand();
};
$consoleApp = new Symfony\Component\Console\Application();
$consoleApp->addCommands($silexApp['command.resolver']->commands());
$consoleApp->run();
Launch in Cli : php index.php demo:greet John, (*10)
, (*11)
CLI commands for Pimple applications
MIT
CLI commands for Pimple applications
MIT