coala / console-bundle
Console extension, e.g. converting foreign events to console output
This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.
Installs: 969
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- symfony/framework-bundle: >=2.1
This package is not auto-updated.
Last update: 2019-03-01 00:26:40 UTC
README
Bundle installation
composer.json
{
require: {
"coala/console-bundle": "dev-master"
}
}
AppKernel.php
<?php
$bundles = array(
new Coala\ConsoleBundle\CoalaConsoleBundle(),
);
ConsoleEventTransformer
Why do I need it?
Sometimes you start long running service commands from the console and want to display status messages from the service in real-time.
To make the service universally usable, it should throw different events on certain actions. These events can be anything, even a unique Log event.
This bundle provides you with a tool to convert "foreign" events to a MessageEvent whose output can be displayed on the console.
All you need is a little bit of configuration and some custom event transformer classes.
How do I use it?
Say, you have a service that throws a custom event AcmeOrderImportEvent with the ID "acme.order.import".
You need to implement an event transformer class that takes this AcmeOrderImportEvent and converts it to a MessageEvent provided by this bundle.
You're free to place this transformer class anywhere you wish, for example directly inside your "Command" folder.
Your transformer class should implement the interface
Coala\ConsoleBundle\ConsoleEventTransformer\Event\MessageEventTransformerInterface
.
Example (e.g. your AcmeOrderImportEvent provides a method getOrder()->getId()):
namespace App\AcmeBundle\Command; use Coala\ConsoleBundle\ConsoleEventTransformer\Event\MessageEventTransformerInterface; use Coala\ConsoleBundle\ConsoleEventTransformer\Event\MessageEvent; use App\Event\AcmeOrderImportEvent; class AcmeOrderImportEventTransformer implements MessageEventTransformerInterface { /** * @param \App\Event\AcmeOrderImportEvent $updateEvent * @return MessageEvent */ public function transform($updateEvent) { $message = "Importing order: " . $updateEvent->getOrder()->getId(); return new MessageEvent(MessageEvent::INFO, $message); } }
Then you need to register this event transformer with the service ID acme.order.import
.
This is done in your config.yml
.
coala_console: events: acme.order.import: App\AcmeBundle\Command\AcmeOrderImportEventTransformer
And finally you should change your command to extend from Coala\ConsoleBundle\ConsoleEventTransformer\Command\MessageEventCommand
:
use Coala\ConsoleBundle\Command\MessageEventCommand; class AcmeTestCommand extends MessageEventCommand { /* ... all your normal command code in here ... */ }
And you're done!