2017 © Pedro Peláez
 

library silex-console-provider

CLI application service provider for Silex

image

bgaze/silex-console-provider

CLI application service provider for Silex

  • Sunday, August 27, 2017
  • by Bgaze
  • Repository
  • 1 Watchers
  • 0 Stars
  • 22 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

bgaze/silex-console-provider

Provides for Silex :, (*1)

  • a handy way to create custom console commands.
  • clear cache command : $ php bin/console cache:clear.

Please check Console component documentation for more details about how to use console and build commands., (*2)

Installation

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());

Usage

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

Write commands

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);
    }

}

Credits

This provider is heavily inspired from codito/silex-console-provider, (*10)

More stuff

The Versions

27/08 2017

dev-master

9999999-dev

CLI application service provider for Silex

  Sources   Download

MIT

The Requires

 

service php console silex provider serviceprovider