2017 © Pedro Peláez
 

library console-service-provider

console service provider for Silex

image

gridonic/console-service-provider

console service provider for Silex

  • Friday, December 26, 2014
  • by dschenk
  • Repository
  • 8 Watchers
  • 0 Stars
  • 439 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 38 Forks
  • 0 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

ConsoleServiceProvider

Provides a Symfony\Component\Console based console for Silex., (*1)

Install

The recommended way to install ConsoleServiceProvider is through composer., (*2)

You can either add it as a depedency to your project using the command line:, (*3)

$ composer require gridonic/console-service-provider

or by adding it directly to your composer.json file:, (*4)

{
    "require": {
        "gridonic/console-service-provider": "1.0.*"
    }
}

Run these two commands to install it:, (*5)

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

Now you can add the autoloader, and you will have access to the library:, (*6)

<?php
require 'vendor/autoload.php';

Register the service provider with your Silex application, (*7)

register(new ConsoleServiceProvider(), array(
    'console.name' => 'MyApplication',
    'console.version' => '1.0.0',
    'console.project_directory' => __DIR__.'/..'
));

?>

You can now copy the console executable in whatever place you see fit, and tweak it to your needs. You will need a way to fetch your silex application, the most common way is to return it from your bootstrap:, (*8)


For the rest of this document, we will assume you do have an app directory, so the console executable will be located at app/console., (*9)

Usage

Use the console just like any Symfony\Component based console:, (*10)

$ app/console my:command

Write commands

Your commands should extend Gridonic\Command\Command to have access to the 2 useful following commands:, (*11)

  • getSilexApplication, which returns the silex application
  • getProjectDirectory, which returns your project's root directory (as configured earlier)

Register commands

There are two ways of registering commands to the console application., (*12)

Directly access the console application from the console executable

Open up app/console, and stuff your commands directly into the console application:, (*13)

#!/usr/bin/env php
add(new MyCommand());
$application->run();

?>

Use the Event Dispatcher

This way is intended for use by provider developers and exposes an unobstrusive way to register commands in 3 simple steps:, (*14)

  1. Register a listener to the ConsoleEvents::INIT event
  2. Implement your program logic
  3. PROFIT!

Example:, (*15)

addListener(ConsoleEvents::INIT, function(ConsoleEvent $event) {
    $app = $event->getApplication();
    $app->add(new MyCommand());
});

?>

The Versions

26/12 2014

dev-master

9999999-dev http://gridonic.ch

console service provider for Silex

  Sources   Download

MIT

The Requires

 

console silex

26/12 2014

v0.9

0.9.0.0 http://gridonic.ch

console service provider for Silex

  Sources   Download

MIT

The Requires

 

console silex

26/12 2014

1.0.1

1.0.1.0 http://gridonic.ch

console service provider for Silex

  Sources   Download

MIT

The Requires

 

console silex

21/10 2014

dev-develop

dev-develop http://gridonic.ch

console service provider for Silex

  Sources   Download

MIT

The Requires

 

console silex

13/06 2013

v1.0

1.0.0.0 http://knplabs.com

console service provider for Silex

  Sources   Download

MIT

The Requires

 

console silex