From 46e196c10ece4ad3aa33b86b52894374928b2c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20L=C3=A9v=C3=AAque?= Date: Sat, 19 Apr 2014 15:21:17 +0200 Subject: [PATCH 1/2] don't catch error if error_reporting is 0 (when @ is used)' --- Listener/Notifier.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Listener/Notifier.php b/Listener/Notifier.php index 2285e1c..643a47c 100644 --- a/Listener/Notifier.php +++ b/Listener/Notifier.php @@ -135,6 +135,11 @@ public function onKernelRequest(GetResponseEvent $event) */ public function handlePhpError($level, $message, $file, $line, $errcontext) { + // don't catch error with error_repoting is 0 + if (0 === error_reporting()) { + return false; + } + // there would be more warning codes but they are not caught by set_error_handler // but by register_shutdown_function $warningsCodes = array(E_NOTICE, E_USER_WARNING, E_USER_NOTICE, E_STRICT, E_DEPRECATED, E_USER_DEPRECATED); From 1540a713370abfb9d5c906d997f04dee2b3367cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20L=C3=A9v=C3=AAque?= Date: Thu, 18 Dec 2014 14:46:01 +0100 Subject: [PATCH 2/2] add configuration on the silent operator --- DependencyInjection/Configuration.php | 3 +++ Listener/Notifier.php | 6 ++++-- README.md | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1f59c25..ecd7730 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -47,6 +47,9 @@ public function getConfigTreeBuilder() ->booleanNode('handlePHPErrors') ->defaultValue(false) ->end() + ->booleanNode('handleSilentErrors') + ->defaultValue(false) + ->end() ->arrayNode('ignoredClasses') ->prototype('scalar') ->treatNullLike(array()) diff --git a/Listener/Notifier.php b/Listener/Notifier.php index 643a47c..aa6a495 100644 --- a/Listener/Notifier.php +++ b/Listener/Notifier.php @@ -38,6 +38,7 @@ class Notifier private $ignoredClasses; private $reportWarnings = false; private $reportErrors = false; + private $reportSilent = false; private $repeatTimeout = false; private static $tmpBuffer = null; @@ -59,10 +60,11 @@ public function __construct(Swift_Mailer $mailer, EngineInterface $templating, $ $this->handle404 = $config['handle404']; $this->reportErrors = $config['handlePHPErrors']; $this->reportWarnings = $config['handlePHPWarnings']; + $this->reportSilent = $config['handleSilentErrors']; $this->ignoredClasses = $config['ignoredClasses']; $this->repeatTimeout = $config['repeatTimeout']; $this->errorsDir = $cacheDir.'/errors'; - + if (!is_dir($this->errorsDir)) { mkdir($this->errorsDir); } @@ -136,7 +138,7 @@ public function onKernelRequest(GetResponseEvent $event) public function handlePhpError($level, $message, $file, $line, $errcontext) { // don't catch error with error_repoting is 0 - if (0 === error_reporting()) { + if (0 === error_reporting() && false === $this->reportSilent) { return false; } diff --git a/README.md b/README.md index 67ddfb1..fe14d14 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ elao_error_notifier: mailer: your.mailer.id # default : mailer handlePHPErrors: true # catch fatal erros and email them handlePHPWarnings: true # catch warnings and email them + handleSilentErrors: false # don't catch error on method with an @ ignoredClasses: ~ ```