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

Skip to content

Commit 62f60ef

Browse files
committed
[ErrorHandler] Rework fatal error handlers
1 parent 07ba636 commit 62f60ef

32 files changed

+839
-535
lines changed

src/Symfony/Component/Debug/Exception/ClassNotFoundException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ClassNotFoundException::class, \Symfony\Component\ErrorHandler\Exception\ClassNotFoundException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ClassNotFoundException::class, \Symfony\Component\ErrorHandler\Error\ClassNotFoundError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Class (or Trait or Interface) Not Found Exception.
1818
*
1919
* @author Konstanton Myakshin <[email protected]>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ClassNotFoundException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\ClassNotFoundError instead.
2222
*/
2323
class ClassNotFoundException extends FatalErrorException
2424
{

src/Symfony/Component/Debug/Exception/OutOfMemoryException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', OutOfMemoryException::class, \Symfony\Component\ErrorHandler\Exception\OutOfMemoryException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', OutOfMemoryException::class, \Symfony\Component\ErrorHandler\Error\OutOfMemoryError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Out of memory exception.
1818
*
1919
* @author Nicolas Grekas <[email protected]>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\OutOfMemoryException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\OutOfMemoryError instead.
2222
*/
2323
class OutOfMemoryException extends FatalErrorException
2424
{

src/Symfony/Component/Debug/Exception/UndefinedFunctionException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedFunctionException::class, \Symfony\Component\ErrorHandler\Exception\UndefinedFunctionException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedFunctionException::class, \Symfony\Component\ErrorHandler\Error\UndefinedFunctionError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Undefined Function Exception.
1818
*
1919
* @author Konstanton Myakshin <[email protected]>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\UndefinedFunctionException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\UndefinedFunctionError instead.
2222
*/
2323
class UndefinedFunctionException extends FatalErrorException
2424
{

src/Symfony/Component/Debug/Exception/UndefinedMethodException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedMethodException::class, \Symfony\Component\ErrorHandler\Exception\UndefinedMethodException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedMethodException::class, \Symfony\Component\ErrorHandler\Error\UndefinedMethodError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Undefined Method Exception.
1818
*
1919
* @author Grégoire Pineau <[email protected]>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\UndefinedMethodException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\UndefinedMethodError instead.
2222
*/
2323
class UndefinedMethodException extends FatalErrorException
2424
{

src/Symfony/Component/Debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use Symfony\Component\Debug\Exception\FatalErrorException;
1515
use Symfony\Component\Debug\Exception\UndefinedFunctionException;
1616

17-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedFunctionFatalErrorHandler::class, \Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedFunctionFatalErrorHandler::class), E_USER_DEPRECATED);
17+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedFunctionFatalErrorHandler::class, \Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedFunctionErrorEnhancer::class), E_USER_DEPRECATED);
1818

1919
/**
2020
* ErrorHandler for undefined functions.
2121
*
2222
* @author Fabien Potencier <[email protected]>
2323
*
24-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedFunctionFatalErrorHandler instead.
24+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedFunctionErrorEnhancer instead.
2525
*/
2626
class UndefinedFunctionFatalErrorHandler implements FatalErrorHandlerInterface
2727
{

src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use Symfony\Component\Debug\Exception\FatalErrorException;
1515
use Symfony\Component\Debug\Exception\UndefinedMethodException;
1616

17-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedMethodFatalErrorHandler::class, \Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedMethodFatalErrorHandler::class), E_USER_DEPRECATED);
17+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedMethodFatalErrorHandler::class, \Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedMethodErrorEnhancer::class), E_USER_DEPRECATED);
1818

1919
/**
2020
* ErrorHandler for undefined methods.
2121
*
2222
* @author Grégoire Pineau <[email protected]>
2323
*
24-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedMethodFatalErrorHandler instead.
24+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedMethodErrorEnhancer instead.
2525
*/
2626
class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface
2727
{
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\ErrorHandler\Error;
13+
14+
class ClassNotFoundError extends \Error
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function __construct(string $message, \Throwable $previous)
20+
{
21+
parent::__construct($message, $previous->getCode(), $previous->getPrevious());
22+
23+
foreach ([
24+
'file' => $previous->getFile(),
25+
'line' => $previous->getLine(),
26+
'trace' => $previous->getTrace(),
27+
] as $property => $value) {
28+
$refl = new \ReflectionProperty('Error', $property);
29+
$refl->setAccessible(true);
30+
$refl->setValue($this, $value);
31+
}
32+
}
33+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\ErrorHandler\Error;
13+
14+
class ClassNotFoundFatalError extends ClassNotFoundError implements FatalErrorInterface
15+
{
16+
private $error;
17+
18+
/**
19+
* {@inheritdoc}
20+
*
21+
* @param array $error An array as returned by error_get_last()
22+
*/
23+
public function __construct(string $message, \Throwable $previous, array $error)
24+
{
25+
parent::__construct($message, $previous);
26+
27+
$this->error = $error;
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function getError(): array
34+
{
35+
return $this->error;
36+
}
37+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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\ErrorHandler\Error;
13+
14+
class FatalError extends \Error implements FatalErrorInterface
15+
{
16+
private $error;
17+
18+
/**
19+
* {@inheritdoc}
20+
*
21+
* @param array $error An array as returned by error_get_last()
22+
*/
23+
public function __construct(string $message, int $code, array $error, int $traceOffset = null, bool $traceArgs = true, array $trace = null)
24+
{
25+
parent::__construct($message, $code);
26+
27+
$this->error = $error;
28+
29+
if (null !== $trace) {
30+
if (!$traceArgs) {
31+
foreach ($trace as &$frame) {
32+
unset($frame['args'], $frame['this'], $frame);
33+
}
34+
}
35+
} elseif (null !== $traceOffset) {
36+
if (\function_exists('xdebug_get_function_stack')) {
37+
$trace = xdebug_get_function_stack();
38+
if (0 < $traceOffset) {
39+
array_splice($trace, -$traceOffset);
40+
}
41+
42+
foreach ($trace as &$frame) {
43+
if (!isset($frame['type'])) {
44+
// XDebug pre 2.1.1 doesn't currently set the call type key http://bugs.xdebug.org/view.php?id=695
45+
if (isset($frame['class'])) {
46+
$frame['type'] = '::';
47+
}
48+
} elseif ('dynamic' === $frame['type']) {
49+
$frame['type'] = '->';
50+
} elseif ('static' === $frame['type']) {
51+
$frame['type'] = '::';
52+
}
53+
54+
// XDebug also has a different name for the parameters array
55+
if (!$traceArgs) {
56+
unset($frame['params'], $frame['args']);
57+
} elseif (isset($frame['params']) && !isset($frame['args'])) {
58+
$frame['args'] = $frame['params'];
59+
unset($frame['params']);
60+
}
61+
}
62+
63+
unset($frame);
64+
$trace = array_reverse($trace);
65+
} else {
66+
$trace = [];
67+
}
68+
}
69+
70+
foreach ([
71+
'file' => $error['file'],
72+
'line' => $error['line'],
73+
'trace' => $trace,
74+
] as $property => $value) {
75+
$refl = new \ReflectionProperty('Error', $property);
76+
$refl->setAccessible(true);
77+
$refl->setValue($this, $value);
78+
}
79+
}
80+
81+
/**
82+
* {@inheritdoc}
83+
*/
84+
public function getError(): array
85+
{
86+
return $this->error;
87+
}
88+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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\ErrorHandler\Error;
13+
14+
interface FatalErrorInterface extends \Throwable
15+
{
16+
/**
17+
* @return array An array as returned by error_get_last()
18+
*/
19+
public function getError(): array;
20+
}

src/Symfony/Component/ErrorHandler/Exception/OutOfMemoryException.php renamed to src/Symfony/Component/ErrorHandler/Error/OutOfMemoryError.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\ErrorHandler\Exception;
12+
namespace Symfony\Component\ErrorHandler\Error;
1313

14-
/**
15-
* Out of memory exception.
16-
*
17-
* @author Nicolas Grekas <[email protected]>
18-
*/
19-
class OutOfMemoryException extends FatalErrorException
14+
class OutOfMemoryError extends FatalError
2015
{
2116
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\ErrorHandler\Error;
13+
14+
class UndefinedFunctionError extends \Error
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function __construct(string $message, \Throwable $previous)
20+
{
21+
parent::__construct($message, $previous->getCode(), $previous->getPrevious());
22+
23+
foreach ([
24+
'file' => $previous->getFile(),
25+
'line' => $previous->getLine(),
26+
'trace' => $previous->getTrace(),
27+
] as $property => $value) {
28+
$refl = new \ReflectionProperty('Error', $property);
29+
$refl->setAccessible(true);
30+
$refl->setValue($this, $value);
31+
}
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\ErrorHandler\Error;
13+
14+
class UndefinedMethodError extends \Error
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function __construct(string $message, \Throwable $previous)
20+
{
21+
parent::__construct($message, $previous->getCode(), $previous->getPrevious());
22+
23+
foreach ([
24+
'file' => $previous->getFile(),
25+
'line' => $previous->getLine(),
26+
'trace' => $previous->getTrace(),
27+
] as $property => $value) {
28+
$refl = new \ReflectionProperty('Error', $property);
29+
$refl->setAccessible(true);
30+
$refl->setValue($this, $value);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)