How can I listen to console events in symfony? -
i'm trying hook symfonys console events symfony standard edition (2.3), won't work.
i created listener according example , follow guides on event registration:
namespace acme\demobundle\eventlistener; use symfony\component\console\event\consolecommandevent; use symfony\component\console\consoleevents; class acmecommandlistener { public function onconsolecommand(consolecommandevent $event) { // output instance $output = $event->getoutput(); // command executed $command = $event->getcommand(); // write command $output->writeln(sprintf('before running command <info>%s</info>', $command->getname())); } } and on mailing list told me register event in service container. did this:
services: kernel.listener.command_dispatch: class: acme\demobundle\eventlistener\acmecommandlistener tags: - { name: kernel.event_listener, event: console.command } but tagging not correct , can't find correct names that. how that?
so, got it. above code in original post ist working, defined services.yml within bundle not in application config app/config.yml. means, configuration never loaded. had import configuration via container extensions:
# acme/demobundle/dependencyinjection/acmedemoextension.php namespace acme\demobundle\dependencyinjection; use symfony\component\dependencyinjection\containerbuilder; use symfony\component\config\filelocator; use symfony\component\httpkernel\dependencyinjection\extension; use symfony\component\dependencyinjection\loader; class acmedemoextension extends extension { public function load(array $configs, containerbuilder $container) { $configuration = new configuration(); $config = $this->processconfiguration($configuration, $configs); $loader = new loader\yamlfileloader($container, new filelocator(__dir__.'/../resources/config')); $loader->load('services.yml'); } } and
# acme/demobundle/dependencyinjection/configuration.php namespace acme\demobundle\dependencyinjection; use symfony\component\config\definition\builder\treebuilder; use symfony\component\config\definition\configurationinterface; class configuration implements configurationinterface { public function getconfigtreebuilder() { $treebuilder = new treebuilder(); $rootnode = $treebuilder->root('headwork_legacy'); return $treebuilder; } } though guess can leave out $configuration = new configuration(); part , configuration class.
Comments
Post a Comment