2017 © Pedro Peláez
 

library command-bus-console

CLI for command bus.

image

clearcode/command-bus-console

CLI for command bus.

  • Tuesday, December 15, 2015
  • by krymen
  • Repository
  • 9 Watchers
  • 3 Stars
  • 1,421 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Build Status Scrutinizer Code Quality MIT License, (*1)

Command Bus Console

Command Bus Console is a package exposing your command bus functionality to the CLI. Command Bus Console is based on Symfony Console Form and https://github.com/SimpleBus., (*2)

Installation

$ composer require clearcode/command-bus-console

Enable bundles in the kernel of your Symfony application., (*3)

    <?php
    // app/AppKernel.php

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new SimpleBusCommandBusBundle(), // this one you probably have already registered
            new SymfonyConsoleFormBundle(),
            new Clearcode\CommandBusConsole\Bundle\CommandBusConsoleBundle(),
        );
    }

Usage

Create and register form type for your command.

Assumed that you already have a command class and its handler class, create form type class mapping your command properties:, (*4)

class SignUpType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('id', TextType::class, [
                'label' => 'Id',
            ])
            ->add('name', TextType::class, [
                'label' => 'Name',
            ])
            ->add('email', TextType::class, [
                'label' => 'email',
            ])
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults([
            'data_class' => SignUp::class,
        ]);
    }

    ...
}

And register your form type using command_bus.type with required attributes command which is FQCN of your command and alias which will be used to register console command with name command-bus:alias., (*5)

    form_type_service_id:
        class: Fully\Qualified\Class\Name\Of\SignUpType
        tags:
            - { name: form.type }
            - { name: command_bus.type, command: Fully\Qualified\Class\Name\Of\SignUp, alias: sign-up }

Run command in interactive mode

$ bin/console command-bus:sign-up
Id:
Name:
email:

[2015-12-11 10:34:55] The Fully\Qualified\Class\Name\Of\SignUp executed with success.

Run command in non interactive mode

$ bin/console command-bus:alias-for-command --no-interaction --id=1 --name=John --email=john@doe.com

[2015-12-11 10:34:55] The Fully\Qualified\Class\Name\Of\SignUp executed with success.

To Do

  • [ ] All fields should be required
  • [ ] Add generating form types on the fly
  • [ ] Add support for instantiating command objects via __construct
  • [ ] Add possibility to use any command bus implementation
    • [ ] Introduce abstraction on command bus

License

MIT, see LICENSE., (*6)

The Versions