Skip to content

Commit 014f2bb

Browse files
committed
Add a new ErrorHandler component (mirror of the Debug component)
1 parent 6ee1d92 commit 014f2bb

File tree

87 files changed

+4625
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+4625
-27
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use PHPUnit\Util\Blacklist;
1919
use Symfony\Bridge\PhpUnit\ClockMock;
2020
use Symfony\Bridge\PhpUnit\DnsMock;
21-
use Symfony\Component\Debug\DebugClassLoader;
21+
use Symfony\Component\ErrorHandler\DebugClassLoader;
2222

2323
/**
2424
* PHP 5.3 compatible trait-like shared implementation.
@@ -53,7 +53,7 @@ public function __construct(array $mockedNamespaces = array())
5353
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait'] = 2;
5454
}
5555

56-
$enableDebugClassLoader = class_exists('Symfony\Component\Debug\DebugClassLoader');
56+
$enableDebugClassLoader = class_exists('Symfony\Component\ErrorHandler\DebugClassLoader');
5757

5858
foreach ($mockedNamespaces as $type => $namespaces) {
5959
if (!\is_array($namespaces)) {

src/Symfony/Bridge/PhpUnit/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"php": ">=5.5.9"
2222
},
2323
"suggest": {
24-
"symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader"
24+
"symfony/error-handler": "For tracking deprecated interfaces usages at runtime with DebugClassLoader"
2525
},
2626
"conflict": {
2727
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2020
use Symfony\Component\Console\Output\OutputInterface;
2121
use Symfony\Component\Console\Style\SymfonyStyle;
22-
use Symfony\Component\Debug\Exception\FatalThrowableError;
2322
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
23+
use Symfony\Component\ErrorHandler\Exception\FatalThrowableError;
2424
use Symfony\Component\HttpKernel\Bundle\Bundle;
2525
use Symfony\Component\HttpKernel\Kernel;
2626
use Symfony\Component\HttpKernel\KernelInterface;

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
use Symfony\Component\Cache\DependencyInjection\CachePoolPrunerPass;
3030
use Symfony\Component\Config\Resource\ClassExistenceResource;
3131
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
32-
use Symfony\Component\Debug\ErrorHandler;
3332
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
3433
use Symfony\Component\DependencyInjection\Compiler\RegisterReverseContainerPass;
3534
use Symfony\Component\DependencyInjection\ContainerBuilder;
35+
use Symfony\Component\ErrorHandler\ErrorHandler;
3636
use Symfony\Component\ErrorRenderer\DependencyInjection\ErrorRendererPass;
3737
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
3838
use Symfony\Component\Form\DependencyInjection\FormPass;

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"symfony/asset": "<3.4",
7171
"symfony/browser-kit": "<4.3",
7272
"symfony/console": "<4.3",
73-
"symfony/debug": "<4.4",
7473
"symfony/dotenv": "<4.2",
7574
"symfony/dom-crawler": "<4.3",
7675
"symfony/form": "<4.3",

src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function provideClassNotFoundData()
100100
'file' => 'foo.php',
101101
'message' => 'Class \'UndefinedFunctionException\' not found',
102102
],
103-
"Attempted to load class \"UndefinedFunctionException\" from the global namespace.\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?",
103+
"Attempted to load class \"UndefinedFunctionException\" from the global namespace.\nDid you forget a \"use\" statement?",
104104
],
105105
[
106106
[
@@ -109,7 +109,7 @@ public function provideClassNotFoundData()
109109
'file' => 'foo.php',
110110
'message' => 'Class \'PEARClass\' not found',
111111
],
112-
"Attempted to load class \"PEARClass\" from the global namespace.\nDid you forget a \"use\" statement for \"Symfony_Component_Debug_Tests_Fixtures_PEARClass\"?",
112+
"Attempted to load class \"PEARClass\" from the global namespace.\nDid you forget a \"use\" statement?",
113113
],
114114
[
115115
[
@@ -118,7 +118,7 @@ public function provideClassNotFoundData()
118118
'file' => 'foo.php',
119119
'message' => 'Class \'Foo\\Bar\\UndefinedFunctionException\' not found',
120120
],
121-
"Attempted to load class \"UndefinedFunctionException\" from namespace \"Foo\Bar\".\nDid you forget a \"use\" statement for \"Symfony\Component\Debug\Exception\UndefinedFunctionException\"?",
121+
"Attempted to load class \"UndefinedFunctionException\" from namespace \"Foo\Bar\".\nDid you forget a \"use\" statement for another namespace?",
122122
],
123123
[
124124
[
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
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 <fabien@symfony.com>
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;
13+
14+
use Psr\Log\AbstractLogger;
15+
16+
/**
17+
* A buffering logger that stacks logs for later.
18+
*
19+
* @author Nicolas Grekas <p@tchwork.com>
20+
*/
21+
class BufferingLogger extends AbstractLogger
22+
{
23+
private $logs = [];
24+
25+
public function log($level, $message, array $context = [])
26+
{
27+
$this->logs[] = [$level, $message, $context];
28+
}
29+
30+
public function cleanLogs()
31+
{
32+
$logs = $this->logs;
33+
$this->logs = [];
34+
35+
return $logs;
36+
}
37+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
4.4.0
5+
-----
6+
7+
* added the component
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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;
13+
14+
/**
15+
* Registers all the debug tools.
16+
*
17+
* @author Fabien Potencier <fabien@symfony.com>
18+
*/
19+
class Debug
20+
{
21+
private static $enabled = false;
22+
23+
/**
24+
* Enables the debug tools.
25+
*
26+
* This method registers an error handler and an exception handler.
27+
*
28+
* @param int $errorReportingLevel The level of error reporting you want
29+
* @param bool $displayErrors Whether to display errors (for development) or just log them (for production)
30+
*/
31+
public static function enable($errorReportingLevel = E_ALL, $displayErrors = true)
32+
{
33+
if (static::$enabled) {
34+
return;
35+
}
36+
37+
static::$enabled = true;
38+
39+
if (null !== $errorReportingLevel) {
40+
error_reporting($errorReportingLevel);
41+
} else {
42+
error_reporting(E_ALL);
43+
}
44+
45+
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
46+
ini_set('display_errors', 0);
47+
ExceptionHandler::register();
48+
} elseif ($displayErrors && (!filter_var(ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN) || ini_get('error_log'))) {
49+
// CLI - display errors only if they're not already logged to STDERR
50+
ini_set('display_errors', 1);
51+
}
52+
if ($displayErrors) {
53+
ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
54+
} else {
55+
ErrorHandler::register()->throwAt(0, true);
56+
}
57+
58+
DebugClassLoader::enable();
59+
}
60+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy