Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ff0927

Browse files
committed
[Debug] added the component (closes #6828, closes #6834, closes #7330)
1 parent 22adfdf commit 2ff0927

20 files changed

+872
-648
lines changed

UPGRADE-3.0.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ UPGRADE FROM 2.x to 3.0
33

44
### ClassLoader
55

6-
* The `UniversalClassLoader` class has been removed in favor of `ClassLoader`. The only difference is that some method
7-
names are different:
6+
* The `UniversalClassLoader` class has been removed in favor of
7+
`ClassLoader`. The only difference is that some method names are different:
88

99
* `registerNamespaces()` -> `addPrefixes()`
1010
* `registerPrefixes()` -> `addPrefixes()`
@@ -34,6 +34,16 @@ UPGRADE FROM 2.x to 3.0
3434
* `Symfony\Bridge\Monolog\Logger`
3535
* `Symfony\Component\HttpKernel\Log\NullLogger`
3636

37+
* The `Symfony\Component\HttpKernel\Kernel::init()` method has been removed.
38+
39+
* The following classes have been renamed as they have been moved to the
40+
Debug component:
41+
42+
* `Symfony\Component\HttpKernel\Debug\ErrorHandler` -> `Symfony\Component\Debug\ErrorHandler`
43+
* `Symfony\Component\HttpKernel\Debug\ExceptionHandler` -> `Symfony\Component\Debug\ExceptionHandler`
44+
* `Symfony\Component\HttpKernel\Exception\FatalErrorException` -> `Symfony\Component\Debug\Exception\FatalErrorException`
45+
* `Symfony\Component\HttpKernel\Exception\FlattenException` -> `Symfony\Component\Debug\Exception\FlattenException`
46+
3747
### Routing
3848

3949
* Some route settings have been renamed:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
4+
Tests/ProjectContainer.php
5+
Tests/classes.map
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
2.3.0
5+
-----
6+
7+
* added the component
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Debug;
13+
14+
use Symfony\Component\Debug\Exception\FatalErrorException;
15+
use Psr\Log\LoggerInterface;
16+
17+
/**
18+
* ErrorHandler.
19+
*
20+
* @author Fabien Potencier <[email protected]>
21+
*/
22+
class ErrorHandler
23+
{
24+
const TYPE_DEPRECATION = -100;
25+
26+
private $levels = array(
27+
E_WARNING => 'Warning',
28+
E_NOTICE => 'Notice',
29+
E_USER_ERROR => 'User Error',
30+
E_USER_WARNING => 'User Warning',
31+
E_USER_NOTICE => 'User Notice',
32+
E_STRICT => 'Runtime Notice',
33+
E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
34+
E_DEPRECATED => 'Deprecated',
35+
E_USER_DEPRECATED => 'User Deprecated',
36+
E_ERROR => 'Error',
37+
E_CORE_ERROR => 'Core Error',
38+
E_COMPILE_ERROR => 'Compile Error',
39+
E_PARSE => 'Parse',
40+
);
41+
42+
private $level;
43+
44+
private $reservedMemory;
45+
46+
/** @var LoggerInterface */
47+
private static $logger;
48+
49+
/**
50+
* Register the error handler.
51+
*
52+
* @param integer $level The level at which the conversion to Exception is done (null to use the error_reporting() value and 0 to disable)
53+
*
54+
* @return The registered error handler
55+
*/
56+
public static function register($level = null)
57+
{
58+
$handler = new static();
59+
$handler->setLevel($level);
60+
61+
ini_set('display_errors', 0);
62+
set_error_handler(array($handler, 'handle'));
63+
register_shutdown_function(array($handler, 'handleFatal'));
64+
$handler->reservedMemory = str_repeat('x', 10240);
65+
66+
return $handler;
67+
}
68+
69+
public function setLevel($level)
70+
{
71+
$this->level = null === $level ? error_reporting() : $level;
72+
}
73+
74+
public static function setLogger(LoggerInterface $logger)
75+
{
76+
self::$logger = $logger;
77+
}
78+
79+
/**
80+
* @throws \ErrorException When error_reporting returns error
81+
*/
82+
public function handle($level, $message, $file, $line, $context)
83+
{
84+
if (0 === $this->level) {
85+
return false;
86+
}
87+
88+
if ($level & (E_USER_DEPRECATED | E_DEPRECATED)) {
89+
if (null !== self::$logger) {
90+
$stack = version_compare(PHP_VERSION, '5.4', '<') ? array_slice(debug_backtrace(false), 0, 10) : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
91+
92+
self::$logger->warning($message, array('type' => self::TYPE_DEPRECATION, 'stack' => $stack));
93+
}
94+
95+
return true;
96+
}
97+
98+
if (error_reporting() & $level && $this->level & $level) {
99+
throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line);
100+
}
101+
102+
return false;
103+
}
104+
105+
public function handleFatal()
106+
{
107+
if (null === $error = error_get_last()) {
108+
return;
109+
}
110+
111+
unset($this->reservedMemory);
112+
$type = $error['type'];
113+
if (0 === $this->level || !in_array($type, array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) {
114+
return;
115+
}
116+
117+
// get current exception handler
118+
$exceptionHandler = set_exception_handler(function() {});
119+
restore_exception_handler();
120+
121+
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
122+
$level = isset($this->levels[$type]) ? $this->levels[$type] : $type;
123+
$message = sprintf('%s: %s in %s line %d', $level, $error['message'], $error['file'], $error['line']);
124+
$exception = new FatalErrorException($message, 0, $type, $error['file'], $error['line']);
125+
$exceptionHandler[0]->handle($exception);
126+
}
127+
}
128+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Debug\Exception;
13+
14+
/**
15+
* Fatal Error Exception.
16+
*
17+
* @author Konstanton Myakshin <[email protected]>
18+
*/
19+
class FatalErrorException extends \ErrorException
20+
{
21+
}

0 commit comments

Comments
 (0)