2010-02-17 13:54:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-02-17 13:54:36 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-02-17 13:54:36 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-02-17 13:54:36 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\HttpKernel\Debug;
|
|
|
|
|
2010-02-17 13:54:36 +00:00
|
|
|
/**
|
2010-04-07 01:51:29 +01:00
|
|
|
* ErrorHandler.
|
2010-02-17 13:54:36 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-02-17 13:54:36 +00:00
|
|
|
*/
|
|
|
|
class ErrorHandler
|
|
|
|
{
|
2011-03-23 18:47:16 +00:00
|
|
|
private $levels = array(
|
2010-05-06 12:25:53 +01:00
|
|
|
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',
|
|
|
|
);
|
2010-02-17 13:54:36 +00:00
|
|
|
|
2011-03-23 18:47:16 +00:00
|
|
|
private $level;
|
2010-02-17 13:54:36 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param integer $level The level at which the conversion to Exception is done (null to use the error_reporting() value and 0 to disable)
|
|
|
|
*/
|
|
|
|
public function __construct($level = null)
|
2010-02-17 13:54:36 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->level = null === $level ? error_reporting() : $level;
|
2010-02-17 13:54:36 +00:00
|
|
|
}
|
|
|
|
|
2010-08-10 13:58:26 +01:00
|
|
|
public function register()
|
2010-02-17 13:54:36 +00:00
|
|
|
{
|
2010-08-10 13:58:26 +01:00
|
|
|
set_error_handler(array($this, 'handle'));
|
2010-02-17 13:54:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* @throws \ErrorException When error_reporting returns error
|
|
|
|
*/
|
|
|
|
public function handle($level, $message, $file, $line, $context)
|
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if (0 === $this->level) {
|
2010-05-06 12:25:53 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-07 15:09:11 +01:00
|
|
|
if (error_reporting() & $level && $this->level & $level) {
|
2010-05-06 12:25:53 +01:00
|
|
|
throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-17 13:54:36 +00:00
|
|
|
}
|