gitory / pimple-cli
CLI commands for Pimple applications
Installs: 21 507
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- pimple/pimple: ~3.0
Requires (Dev)
- phpspec/phpspec: ~2.0
Suggests
- silex/silex: Provide a light framework to build PHP applications
- symfony/console: The Console component allows you to create command-line commands
This package is auto-updated.
Last update: 2024-10-24 19:39:15 UTC
README
PimpleCli is a tool that makes it easy creating command line application.
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.
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.
Installation
Through Composer :
{ "require": { "gitory/pimple-cli": "~1.0" } }
Examples
Silex 2
composer.json
{ "require": { "silex/silex": "~2.0@dev", "gitory/pimple-cli": "~1.0", "symfony/console": "~2.0" } }
GreetCommand.php
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
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