Skip to content

Commit c3d012c

Browse files
[Debug] make screaming configurable
1 parent a8888be commit c3d012c

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,13 +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

136136
$definition->replaceArgument(0, array(new Reference('http_kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'terminateWithException'));
137+
$definition->replaceArgument(3, E_ALL | E_STRICT);
137138

138139
$definition = $container->findDefinition('http_kernel');
139140
$definition->replaceArgument(2, new Reference('debug.controller_resolver'));

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<argument /><!-- Exception handler -->
1717
<argument type="service" id="logger" on-invalid="null" />
1818
<argument /><!-- Log levels map for enabled error levels -->
19-
<argument>%kernel.debug%</argument>
19+
<argument>null</argument>
20+
<argument>true</argument>
2021
<argument>null</argument><!-- %templating.helper.code.file_link_format% -->
2122
</service>
2223

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

+25-18
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,52 @@ class DebugHandlersListener implements EventSubscriberInterface
2727
private $exceptionHandler;
2828
private $logger;
2929
private $levels;
30-
private $debug;
30+
private $throwAt;
31+
private $scream;
32+
private $fileLinkFormat;
3133

3234
/**
33-
* @param callable $exceptionHandler A handler that will be called on Exception
35+
* @param callable|null $exceptionHandler A handler that will be called on Exception
3436
* @param LoggerInterface|null $logger A PSR-3 logger
3537
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
36-
* @param bool $debug Enables/disables debug mode
38+
* @param int|null $throwAt Thrown errors in a bit field of E_* constants, or null to keep the current value
39+
* @param bool $scream Enables/disables screaming mode, where even silenced errors are logged
3740
* @param string $fileLinkFormat The format for links to source files
3841
*/
39-
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true, $fileLinkFormat = null)
42+
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $throwAt = -1, $scream = true, $fileLinkFormat = null)
4043
{
4144
$this->exceptionHandler = $exceptionHandler;
4245
$this->logger = $logger;
4346
$this->levels = $levels;
44-
$this->debug = $debug;
47+
$this->throwAt = is_numeric($throwAt) ? (int) $throwAt : (null === $throwAt ? null : ($throwAt ? -1 : null));
48+
$this->scream = (bool) $scream;
4549
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4650
}
4751

4852
public function configure()
4953
{
50-
if ($this->logger) {
51-
$handler = set_error_handler('var_dump', 0);
52-
$handler = is_array($handler) ? $handler[0] : null;
53-
restore_error_handler();
54-
if ($handler instanceof ErrorHandler) {
55-
if ($this->debug) {
56-
$handler->throwAt(-1);
57-
}
54+
$handler = set_error_handler('var_dump', 0);
55+
$handler = is_array($handler) ? $handler[0] : null;
56+
restore_error_handler();
57+
if ($handler instanceof ErrorHandler) {
58+
if ($this->logger) {
5859
$handler->setDefaultLogger($this->logger, $this->levels);
5960
if (is_array($this->levels)) {
60-
$scream = 0;
61+
$levels = 0;
6162
foreach ($this->levels as $type => $log) {
62-
$scream |= $type;
63+
$levels |= $type;
6364
}
64-
$this->levels = $scream;
65+
} else {
66+
$levels = null === $this->levels ? E_ALL | E_STRICT : $this->levels;
6567
}
66-
$handler->screamAt($this->levels);
68+
if ($this->scream) {
69+
$handler->screamAt($levels);
70+
}
71+
$this->logger = null;
72+
}
73+
if (null !== $this->throwAt) {
74+
$handler->throwAt($this->throwAt, true);
6775
}
68-
$this->logger = $this->levels = null;
6976
}
7077
if ($this->exceptionHandler) {
7178
$handler = set_exception_handler('var_dump');

0 commit comments

Comments
 (0)