Skip to content

Commit

Permalink
[Debug] make screaming configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Oct 2, 2014
1 parent 4d0ab7d commit 4acf5d3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
Expand Up @@ -127,12 +127,14 @@ public function load(array $configs, ContainerBuilder $container)
$definition = $container->findDefinition('debug.debug_handlers_listener');

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

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

$definition->replaceArgument(3, E_ALL | E_STRICT);

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

Expand All @@ -143,8 +145,6 @@ public function load(array $configs, ContainerBuilder $container)
$container->setAlias('event_dispatcher', 'debug.event_dispatcher');
} else {
$definition->replaceArgument(2, E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR);

$container->findDefinition('debug.error_handler')->addMethodCall('throwAt', array(0));
}

$this->addClassesToCompile(array(
Expand Down
Expand Up @@ -17,7 +17,8 @@
<argument /><!-- Exception handler -->
<argument type="service" id="logger" on-invalid="null" />
<argument /><!-- Log levels map for enabled error levels -->
<argument>%kernel.debug%</argument>
<argument>0</argument>
<argument>true</argument>
<argument>null</argument><!-- %templating.helper.code.file_link_format% -->
</service>

Expand Down
Expand Up @@ -33,22 +33,25 @@ class DebugHandlersListener implements EventSubscriberInterface
private $exceptionHandler;
private $logger;
private $levels;
private $debug;
private $throwAt;
private $scream;
private $fileLinkFormat;

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

Expand All @@ -66,25 +69,28 @@ public function configure(Event $event = null, $eventName = null, EventDispatche
$eventDispatcher->removeListener($name, array($this, 'configure'));
}
}
if ($this->logger) {
$handler = set_error_handler('var_dump', 0);
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
if ($handler instanceof ErrorHandler) {
if ($this->debug) {
$handler->throwAt(-1);
}
$handler = set_error_handler('var_dump', 0);
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
if ($handler instanceof ErrorHandler) {
if ($this->logger) {
$handler->setDefaultLogger($this->logger, $this->levels);
if (is_array($this->levels)) {
$scream = 0;
foreach ($this->levels as $type => $log) {
$scream |= $type;
}
$this->levels = $scream;
} else {
$scream = null === $this->levels ? E_ALL | E_STRICT : $this->levels;
}
$handler->screamAt($this->levels);
if ($this->scream) {
$handler->screamAt($scream);
}
$this->logger = $this->levels = null;
}
if (null !== $this->throwAt) {
$handler->throwAt($this->throwAt, true);
}
$this->logger = $this->levels = null;
}
if (!$this->exceptionHandler) {
if ($event instanceof KernelEvent) {
Expand All @@ -110,7 +116,9 @@ public function configure(Event $event = null, $eventName = null, EventDispatche
}
if ($handler instanceof ExceptionHandler) {
$handler->setHandler($this->exceptionHandler);
$handler->setFileLinkFormat($this->fileLinkFormat);
if (null !== $this->fileLinkFormat) {
$handler->setFileLinkFormat($this->fileLinkFormat);
}
}
$this->exceptionHandler = null;
}
Expand Down

0 comments on commit 4acf5d3

Please sign in to comment.