clearcode / command-bus-console
CLI for command bus.
Installs: 1 431
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 10
Forks: 1
Open Issues: 2
Requires
- php: >=5.6
- matthiasnoback/symfony-console-form: ^1.2
- nesbot/carbon: ^1.21
- ramsey/uuid: ~3.0
- simple-bus/symfony-bridge: ^4.1
- symfony/framework-bundle: ~2.5
- symfony/yaml: ~2.5
Requires (Dev)
- behat/behat: ^3.0
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: ^0.6.1
- symfony/class-loader: ~2.1
- symfony/finder: ~2.5
- symfony/validator: ~2.5
- symfony/var-dumper: ~2.5
This package is not auto-updated.
Last update: 2024-10-26 18:33:29 UTC
README
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.
Installation
$ composer require clearcode/command-bus-console
Enable bundles in the kernel of your Symfony application.
<?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:
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
.
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.