diff -r 000000000000 -r 7f95f8617b0b vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php Sat Sep 24 15:40:41 2011 +0200 @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Debug; + +/** + * ErrorHandler. + * + * @author Fabien Potencier + */ +class ErrorHandler +{ + private $levels = array( + E_WARNING => 'Warning', + E_NOTICE => 'Notice', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Runtime Notice', + E_RECOVERABLE_ERROR => 'Catchable Fatal Error', + ); + + private $level; + + /** + * Register the error handler. + * + * @param integer $level The level at which the conversion to Exception is done (null to use the error_reporting() value and 0 to disable) + * + * @return The registered error handler + */ + static public function register($level = null) + { + $handler = new static(); + $handler->setLevel($level); + + set_error_handler(array($handler, 'handle')); + + return $handler; + } + + public function setLevel($level) + { + $this->level = null === $level ? error_reporting() : $level; + } + + /** + * @throws \ErrorException When error_reporting returns error + */ + public function handle($level, $message, $file, $line, $context) + { + if (0 === $this->level) { + return false; + } + + if (error_reporting() & $level && $this->level & $level) { + throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line)); + } + + return false; + } +}