feature #12045 [Debug] add some file link format handling (nicolas-grekas)
This PR was merged into the 2.6-dev branch.
Discussion
----------
[Debug] add some file link format handling
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
c6923af
[Debug] add some file link format handling
This commit is contained in:
commit
4b6776e801
@ -57,27 +57,6 @@ class FrameworkExtension extends Extension
|
|||||||
// Property access is used by both the Form and the Validator component
|
// Property access is used by both the Form and the Validator component
|
||||||
$loader->load('property_access.xml');
|
$loader->load('property_access.xml');
|
||||||
|
|
||||||
$loader->load('debug_prod.xml');
|
|
||||||
|
|
||||||
if ($container->getParameter('kernel.debug')) {
|
|
||||||
$loader->load('debug.xml');
|
|
||||||
|
|
||||||
$definition = $container->findDefinition('debug.debug_handlers_listener');
|
|
||||||
$definition->replaceArgument(0, array(new Reference('http_kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'terminateWithException'));
|
|
||||||
|
|
||||||
$definition = $container->findDefinition('http_kernel');
|
|
||||||
$definition->replaceArgument(2, new Reference('debug.controller_resolver'));
|
|
||||||
|
|
||||||
// replace the regular event_dispatcher service with the debug one
|
|
||||||
$definition = $container->findDefinition('event_dispatcher');
|
|
||||||
$definition->setPublic(false);
|
|
||||||
$container->setDefinition('debug.event_dispatcher.parent', $definition);
|
|
||||||
$container->setAlias('event_dispatcher', 'debug.event_dispatcher');
|
|
||||||
} else {
|
|
||||||
$definition = $container->findDefinition('debug.debug_handlers_listener');
|
|
||||||
$definition->replaceArgument(2, E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
$configuration = $this->getConfiguration($configs, $container);
|
$configuration = $this->getConfiguration($configs, $container);
|
||||||
$config = $this->processConfiguration($configuration, $configs);
|
$config = $this->processConfiguration($configuration, $configs);
|
||||||
|
|
||||||
@ -144,6 +123,30 @@ class FrameworkExtension extends Extension
|
|||||||
$loader->load('serializer.xml');
|
$loader->load('serializer.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$loader->load('debug_prod.xml');
|
||||||
|
$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%');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($container->getParameter('kernel.debug')) {
|
||||||
|
$loader->load('debug.xml');
|
||||||
|
|
||||||
|
$definition->replaceArgument(0, array(new Reference('http_kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'terminateWithException'));
|
||||||
|
|
||||||
|
$definition = $container->findDefinition('http_kernel');
|
||||||
|
$definition->replaceArgument(2, new Reference('debug.controller_resolver'));
|
||||||
|
|
||||||
|
// replace the regular event_dispatcher service with the debug one
|
||||||
|
$definition = $container->findDefinition('event_dispatcher');
|
||||||
|
$definition->setPublic(false);
|
||||||
|
$container->setDefinition('debug.event_dispatcher.parent', $definition);
|
||||||
|
$container->setAlias('event_dispatcher', 'debug.event_dispatcher');
|
||||||
|
} else {
|
||||||
|
$definition->replaceArgument(2, E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
$this->addClassesToCompile(array(
|
$this->addClassesToCompile(array(
|
||||||
'Symfony\\Component\\Config\\FileLocator',
|
'Symfony\\Component\\Config\\FileLocator',
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
<argument type="service" id="logger" on-invalid="null" />
|
<argument type="service" id="logger" on-invalid="null" />
|
||||||
<argument /><!-- Log levels map for enabled error levels -->
|
<argument /><!-- Log levels map for enabled error levels -->
|
||||||
<argument>%kernel.debug%</argument>
|
<argument>%kernel.debug%</argument>
|
||||||
|
<argument>null</argument><!-- %templating.helper.code.file_link_format% -->
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="debug.stopwatch" class="%debug.stopwatch.class%" />
|
<service id="debug.stopwatch" class="%debug.stopwatch.class%" />
|
||||||
|
@ -37,7 +37,7 @@ class CodeHelper extends Helper
|
|||||||
*/
|
*/
|
||||||
public function __construct($fileLinkFormat, $rootDir, $charset)
|
public function __construct($fileLinkFormat, $rootDir, $charset)
|
||||||
{
|
{
|
||||||
$this->fileLinkFormat = empty($fileLinkFormat) ? ini_get('xdebug.file_link_format') : $fileLinkFormat;
|
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
||||||
$this->rootDir = str_replace('\\', '/', $rootDir).'/';
|
$this->rootDir = str_replace('\\', '/', $rootDir).'/';
|
||||||
$this->charset = $charset;
|
$this->charset = $charset;
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,12 @@ class ExceptionHandler
|
|||||||
private $handler;
|
private $handler;
|
||||||
private $caughtBuffer;
|
private $caughtBuffer;
|
||||||
private $caughtLength;
|
private $caughtLength;
|
||||||
|
private $fileLinkFormat;
|
||||||
|
|
||||||
public function __construct($debug = true)
|
public function __construct($debug = true, $fileLinkFormat = null)
|
||||||
{
|
{
|
||||||
$this->debug = $debug;
|
$this->debug = $debug;
|
||||||
|
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,9 +52,9 @@ class ExceptionHandler
|
|||||||
*
|
*
|
||||||
* @return ExceptionHandler The registered exception handler
|
* @return ExceptionHandler The registered exception handler
|
||||||
*/
|
*/
|
||||||
public static function register($debug = true)
|
public static function register($debug = true, $fileLinkFormat = null)
|
||||||
{
|
{
|
||||||
$handler = new static($debug);
|
$handler = new static($debug, $fileLinkFormat = null);
|
||||||
|
|
||||||
$prev = set_exception_handler(array($handler, 'handle'));
|
$prev = set_exception_handler(array($handler, 'handle'));
|
||||||
if (is_array($prev) && $prev[0] instanceof ErrorHandler) {
|
if (is_array($prev) && $prev[0] instanceof ErrorHandler) {
|
||||||
@ -81,6 +83,21 @@ class ExceptionHandler
|
|||||||
return $old;
|
return $old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the format for links to source files.
|
||||||
|
*
|
||||||
|
* @param string $format The format for links to source files
|
||||||
|
*
|
||||||
|
* @return string The previous file link format.
|
||||||
|
*/
|
||||||
|
public function setFileLinkFormat($format)
|
||||||
|
{
|
||||||
|
$old = $this->fileLinkFormat;
|
||||||
|
$this->fileLinkFormat = $format;
|
||||||
|
|
||||||
|
return $old;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a response for the given Exception.
|
* Sends a response for the given Exception.
|
||||||
*
|
*
|
||||||
@ -353,7 +370,7 @@ EOF;
|
|||||||
$path = self::utf8Htmlize($path);
|
$path = self::utf8Htmlize($path);
|
||||||
$file = preg_match('#[^/\\\\]*$#', $path, $file) ? $file[0] : $path;
|
$file = preg_match('#[^/\\\\]*$#', $path, $file) ? $file[0] : $path;
|
||||||
|
|
||||||
if ($linkFormat = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) {
|
if ($linkFormat = $this->fileLinkFormat) {
|
||||||
$link = str_replace(array('%f', '%l'), array($path, $line), $linkFormat);
|
$link = str_replace(array('%f', '%l'), array($path, $line), $linkFormat);
|
||||||
|
|
||||||
return sprintf(' in <a href="%s" title="Go to source">%s line %d</a>', $link, $file, $line);
|
return sprintf(' in <a href="%s" title="Go to source">%s line %d</a>', $link, $file, $line);
|
||||||
|
@ -34,13 +34,15 @@ class DebugHandlersListener implements EventSubscriberInterface
|
|||||||
* @param LoggerInterface|null $logger A PSR-3 logger
|
* @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 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 bool $debug Enables/disables debug mode
|
||||||
|
* @param string $fileLinkFormat The format for links to source files
|
||||||
*/
|
*/
|
||||||
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true)
|
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true, $fileLinkFormat = null)
|
||||||
{
|
{
|
||||||
$this->exceptionHandler = $exceptionHandler;
|
$this->exceptionHandler = $exceptionHandler;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->levels = $levels;
|
$this->levels = $levels;
|
||||||
$this->debug = $debug;
|
$this->debug = $debug;
|
||||||
|
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configure()
|
public function configure()
|
||||||
@ -76,6 +78,7 @@ class DebugHandlersListener implements EventSubscriberInterface
|
|||||||
}
|
}
|
||||||
if ($handler instanceof ExceptionHandler) {
|
if ($handler instanceof ExceptionHandler) {
|
||||||
$handler->setHandler($this->exceptionHandler);
|
$handler->setHandler($this->exceptionHandler);
|
||||||
|
$handler->setFileLinkFormat($this->fileLinkFormat);
|
||||||
}
|
}
|
||||||
$this->exceptionHandler = null;
|
$this->exceptionHandler = null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user