I am running Symfony 2.7.6 dev and I have a listener set up that is supposed to trigger on console.exception, but it does not trigger, it only displays the exception in the console as usual. For testing purposes, I have incorporated a console.terminate listener, which works fine. (I have also tested console.command and that also works fine).
For the life of me I cannot figure out why the console.exception event does not fire or why the console.exception listener does not trigger.
ConsoleExceptionListener Setup in config.yml
kernel.listener.command_dispatch:
class: CompanyHidden\PortalBundle\Listener\ConsoleExceptionListener
arguments: ["@service_container", "@router"]
tags:
- { name: kernel.event_listener, event: console.exception, method: onConsoleException }
- { name: kernel.event_listener, event: console.terminate, method: onConsoleTerminate }
ConsoleExceptionListener.php
<?php
namespace CompanyHidden\PortalBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class ConsoleExceptionListener
{
private $container;
private $router;
function __construct($container, $router)
{
$this->container = $container;
$this->router = $router;
}
public function onConsoleTerminate()
{
die(">>>> TERMINATE TEST >>>>");
}
public function onConsoleException(ConsoleExceptionEvent $event)
{
die(">>> EXCEPTION TEST<<<<");
}
}
Console Command
<?php
namespace CompanyHidden\PortalBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use CompanyHidden\PortalBundle\Classes\ImapMailbox;
class getEmailsCommand extends ContainerAwareCommand
{
protected function configure()
{
$this->setName('getEmails');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$context = $this->getContainer()->get('router')->getContext();
$context->setScheme('http');
# SIMULATED TERMINATION TEST
//print ">>>> TERMINATED <<<<<\n";
//return null;
# SIMULATED EXCEPTION TEST
$null = null;
$null->getNull();
//..... Rest of Code, not relevant
}
}
?>
Console Exception Thrown (instead of triggering exception listener)
