2017 © Pedro PelĂĄez
 

symfony-bundle nucleus-console-bundle

Allow to create a command with a annotation on a service method

image

mpoiriert/nucleus-console-bundle

Allow to create a command with a annotation on a service method

  • Wednesday, March 26, 2014
  • by mpoiriert
  • Repository
  • 1 Watchers
  • 0 Stars
  • 690 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

nucleus-console-bundle

Build Status, (*1)

Using a annotation above a service method you are able to create a command accessible from the CLI., (*2)

To use it in your application you must register 2 bundles since there is a dependency on nucleus-bundle., (*3)

<?php

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Nucleus\Bundle\CoreBundle\NucleusCoreBundle(),
    new Nucleus\Bundle\BinderBundle\NucleusConsoleBundle(),
    // ...
);

When this is done you can use the Nucleus\Console\CommandLine annotation above any public method of your service., (*4)

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestService
{
    /**
     * Comment from the method
     *
     * @\Nucleus\Console\CommandLine(name="my:test:hello")
     *
     * @param string $name The name of the person you want to say hello to
     * @param OutputInterface $output
     * @param InputInterface $output
     * @param Command $parentCommand
     */
    public function hello($name, OutputInterface $output, InputInterface $input, Command $parentCommand)
    {
        $output->write('Hello ' . $name . ' !');
    }
}

The description of the command will be parse from the first line of the phpDoc. All the argument are treat as option (meaning you need to set it with --optionName), you can define a default value if the option is optional. The comment in front of the @param will be use by the --help of you command. You don't have any interface to respect, like Controller in symfony all the parameter will be inject according to it's name or strong typing. Since the service doesn't have to extend the Command class of symfony you can inject a "parentCommand" from where you can access everything publicly available from the Command object (like the application if you want to access helper...)., (*5)

If you don't specify a name attribute to the annotation the name of the service follow by the method name will be used., (*6)

The Versions

26/03 2014

dev-master

9999999-dev

Allow to create a command with a annotation on a service method

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Poirier ThĂ©orĂȘt

library console bundle symfony annotation nucleus