8000 [Debug] make screaming configurable · nicolas-grekas/symfony@4acf5d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4acf5d3

Browse files
[Debug] make screaming configurable
1 parent 4d0ab7d commit 4acf5d3

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ public function load(array $configs, ContainerBuilder $container)
127127
$definition = $container->findDefinition('debug.debug_handlers_listener');
128128

129129
if ($container->hasParameter('templating.helper.code.file_link_format')) {
130-
$definition->replaceArgument(4, '%templating.helper.code.file_link_format%');
130+
$definition->replaceArgument(5, '%templating.helper.code.file_link_format%');
131131
}
132132

133133
if ($container->getParameter('kernel.debug')) {
134134
$loader->load('debug.xml');
135135

136+
$definition->replaceArgument(3, E_ALL | E_STRICT);
137+
136138
$definition = $container->findDefinition('http_kernel');
137139
$definition->replaceArgument(2, new Reference('debug.controller_resolver'));
138140

@@ -143,8 +145,6 @@ public function load(array $configs, ContainerBuilder $container)
143145
$container->setAlias('event_dispatcher', 'debug.event_dispatcher');
144146
} else {
145147
$definition->replaceArgument(2, E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR);
146-
147-
$container->findDefinition('debug.error_handler')->addMethodCall('throwAt', array(0));
148148
}
149149

150150
$this->addClassesToCompile(array(

src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<argument /><!-- Exception handler -->
1818
<argument type="service" id="logger" on-invalid="null" />
1919
<argument /><!-- Log levels map for enabled error levels -->
20-
<argument>%kernel.debug%</argument>
20+
<argument>0</argument>
21+
<argument>true</argument>
2122
<argument>null</argument><!-- %templating.helper.code.file_link_format% -->
2223
</service>
2324

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,25 @@ class DebugHandlersListener implements EventSubscriberInterface
3333
private $exceptionHandler;
3434
private $logger;
3535
private $levels;
36-
private $debug;
36+
private $throwAt;
37+
private $scream;
3738
private $fileLinkFormat;
3839

3940
/**
40-
* @param callable $exceptionHandler A handler that will be called on Exception
41+
* @param callable|null $exceptionHandler A handler that will be called on Exception
4142
* @param LoggerInterface|null $logger A PSR-3 logger
4243
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
43-
* @param bool $debug Enables/disables debug mode
44+
* @param int|null $throwAt Thrown errors in a bit field of E_* constants, or null to keep the current value
45+
* @param bool $scream Enables/disables screaming mode, where even silenced errors are logged
4446
* @param string $fileLinkFormat The format for links to source files
4547
*/
46-
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true, $fileLinkFormat = null)
48+
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $throwAt = -1, $scream = true, $fileLinkFormat = null)
4749
{
4850
$this->exceptionHandler = $exceptionHandler;
4951
$this->logger = $logger;
5052
$this->levels = $levels;
51-
$this->debug = $debug;
53+
$this->throwAt = is_numeric($throwAt) ? (int) $throwAt : (null === $throwAt ? null : ($throwAt ? -1 : null));
54+
$this->scream = (bool) $scream;
5255
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
5356
}
5457

@@ -66,25 +69,28 @@ public function configure(Event $event = null, $eventName = null, EventDispatche
6669
$eventDispatcher->removeListener($name, array($this, 'configure'));
6770
}
6871
}
69-
if ($this->logger) {
70-
$handler = set_error_handler('var_dump', 0);
71-
$handler = is_array($handler) ? $handler[0] : null;
72-
restore_error_handler();
73-
if ($handler instanceof ErrorHandler) {
74-
if ($this->debug) {
75-
$handler->throwAt(-1);
76-
}
72+
$handler = set_error_handler('var_dump', 0);
73+
$handler = is_array($handler) ? $handler[0] : null;
74+
restore_error_handler();
75+
if ($handler instanceof ErrorHandler) {
76+
if ($this->logger) {
7777
$handler->setDefaultLogger($this->logger, $this->levels);
7878
if (is_array($this->levels)) {
7979
$scream = 0;
8080
foreach ($this->levels as $type => $log) {
8181
$scream |= $type;
8282
}
83-
$this->levels = $scream;
83+
} else {
84+
$scream = null === $this->levels ? E_ALL | E_STRICT : $this->levels;
8485
}
85-
$handler->screamAt($this->levels);
86+
if ($this->scream) {
87+
$handler->screamAt($scream);
88+
}
89+
$this->logger = $this->levels = null;
90+
}
91+
if (null !== $this->throwAt) {
92+
$handler->throwAt($this->throwAt, true);
8693
}
87-
$this->logger = $this->levels = null;
8894
}
8995
if (!$this->exceptionHandler) {
9096
if ($event instanceof KernelEvent) {
@@ -110,7 +116,9 @@ public function configure(Event $event = null, $eventName = null, EventDispatche
110116
}
111117
if ($handler instanceof ExceptionHandler) {
112118
$handler->setHandler($this->exceptionHandler);
113-
$handler->setFileLinkFormat($this->fileLinkFormat);
119+
if (null !== $this->fileLinkFormat) {
120+
$handler->setFileLinkFormat($this->fileLinkFormat);
121+
}
114122
}
115123
$this->exceptionHandler = null;
116124
}

0 commit comments

Comments
 (0)
0