In Symfony, when we run a command, if there is any notice or warning, Symfony shows a big red message and quits the whole program.
I want an error to be emitted to the log, but I don't want the whole program to quit. Can anyone please tell me how to achieve this. thanks.
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class NotQuitWithWarningOrNoticeCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('try:nored')
->setDescription('Avoid to show big red message')
->addArgument('type');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$type = $input->getArgument('type');
if ($type == 'warning' || !$type) {
trigger_error("a warning", E_USER_WARNING);
}
if ($type == 'notice' || !$type) {
trigger_error("a notice", E_USER_NOTICE);
}
echo "Hi there!\n";
}
}
(The code here is just to reproduce the problem. Getting a warning or notice is my scenario.)