8000 feature #12045 [Debug] add some file link format handling (nicolas-gr… · symfony/symfony@4b6776e · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b6776e

Browse files
committed
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
2 parents f3ef9d2 + c6923af commit 4b6776e

File tree

5 files changed

+52
-28
lines changed

5 files changed

+52
-28
lines changed

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,6 @@ public function load(array $configs, ContainerBuilder $container)
5757
// Property access is used by both the Form and the Validator component
5858
$loader->load('property_access.xml');
5959

60-
$loader->load('debug_prod.xml');
61-
62-
if ($container->getParameter('kernel.debug')) {
63-
$loader->load('debug.xml');
64-
65-
$definition = $container->findDefinition('debug.debug_handlers_listener');
66-
$definition->replaceArgument(0, array(new Reference('http_kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'terminateWithException'));
67-
68-
$definition = $container->findDefinition('http_kernel');
69-
$definition->replaceArgument(2, new Reference('debug.controller_resolver'));
70-
71-
// replace the regular event_dispatcher service with the debug one
72-
$definition = $container->findDefinition('event_dispatcher');
73-
$definition->setPublic(false);
74-
$container->setDefinition('debug.event_dispatcher.parent', $definition);
75-
$container->setAlias('event_dispatcher', 'debug.event_dispatcher');
76-
} else {
77-
$definition = $container->findDefinition('debug.debug_handlers_listener');
78-
10000 $definition->replaceArgument(2, E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR);
79-
}
80-
8160
$configuration = $this->getConfiguration($configs, $container);
8261
$config = $this->processConfiguration($configuration, $configs);
8362

@@ -144,6 +123,30 @@ public function load(array $configs, ContainerBuilder $container)
144123
$loader->load('serializer.xml');
145124
}
146125

126+
$loader->load('debug_prod.xml');
127+
$definition = $container->findDefinition('debug.debug_handlers_listener');
128+
129+
if ($container->hasParameter('templating.helper.code.file_link_format')) {
130+
$definition->replaceArgument(4, '%templating.helper.code.file_link_format%');
131+
}
132+
133+
if ($container->getParameter('kernel.debug')) {
134+
$loader->load('debug.xml');
135+
136+
$definition->replaceArgument(0, array(new Reference('http_kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'terminateWithException'));
137+
138+
$definition = $container->findDefinition('http_kernel');
139+
$definition->replaceArgument(2, new Reference('debug.controller_resolver'));
140+
141+
// replace the regular event_dispatcher service with the debug one
142+
$definition = $container->findDefinition('event_dispatcher');
143+
$definition->setPublic(false);
144+
$container->setDefinition('debug.event_dispatcher.parent', $definition);
145+
$container->setAlias('event_dispatcher', 'debug.event_dispatcher');
146+
} else {
147+
$definition->replaceArgument(2, E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR);
148+
}
149+
147150
$this->addClassesToCompile(array(
148151
'Symfony\\Component\\Config\\FileLocator',
149152

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<argument type="service" id="logger" on-invalid="null" />
1818
<argument /><!-- Log levels map for enabled error levels -->
1919
<argument>%kernel.debug%</argument>
20+
<argument>null</argument><!-- %templating.helper.code.file_link_format% -->
2021
</service>
2122

2223
<service id="debug.stopwatch" class="%debug.stopwatch.class%" />

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CodeHelper extends Helper
3737
*/
3838
public function __construct($fileLinkFormat, $rootDir, $charset)
3939
{
40-
$this->fileLinkFormat = empty($fileLinkFormat) ? ini_get('xdebug.file_link_format') : $fileLinkFormat;
40+
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4141
$this->rootDir = str_replace('\\', '/', $rootDir).'/';
4242
$this->charset = $charset;
4343
}

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,24 @@ class ExceptionHandler
3737
private $handler;
3838
private $caughtBuffer;
3939
private $caughtLength;
40+
private $fileLinkFormat;
4041

41-
public function __construct($debug = true)
42+
public function __construct($debug = true, $fileLinkFormat = null)
4243
{
4344
$this->debug = $debug;
45+
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4446
}
4547

4648
/**
4749
* Registers the exception handler.
4850
*
49-
* @param bool $debug
51+
* @param bool $debug
5052
*
5153
* @return ExceptionHandler The registered exception handler
5254
*/
53-
public static function register($debug = true)
55+
public static function register($debug = true, $fileLinkFormat = null)
5456
{
55-
$handler = new static($debug);
57+
$handler = new static($debug, $fileLinkFormat = null);
5658

5759
$prev = set_exception_handler(array($handler, 'handle'));
5860
if (is_array($prev) && $prev[0] instanceof ErrorHandler) {
@@ -81,6 +83,21 @@ public function setHandler($handler)
8183
return $old;
8284
}
8385

86+
/**
87+
* Sets the format for links to source files.
88+
*
89+
* @param string $format The format for links to source files
90+
*
91+
* @return string The previous file link format.
92+
*/
93+
public function setFileLinkFormat($format)
94+
{
95+
$old = $this->fileLinkFormat;
96+
$this->fileLinkFormat = $format;
97+
98+
return $old;
99+
}
100+
84101
/**
85102
* Sends a response for the given Exception.
86103
*
@@ -353,7 +370,7 @@ private function formatPath($path, $line)
353370
$path = self::utf8Htmlize($path);
354371
$file = preg_match('#[^/\\\\]*$#', $path, $file) ? $file[0] : $path;
355372

356-
if ($linkFormat = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) {
373+
if ($linkFormat = $this->fileLinkFormat) {
357374
$link = str_replace(array('%f', '%l'), array($path, $line), $linkFormat);
358375

359376
return sprintf(' in <a href="%s" title="Go to source">%s line %d</a>', $link, $file, $line);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ class DebugHandlersListener implements EventSubscriberInterface
3434
* @param LoggerInterface|null $logger A PSR-3 logger
3535
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
3636
* @param bool $debug Enables/disables debug mode
37+
* @param string $fileLinkFormat The format for links to source files
3738
*/
38-
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true)
39+
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true, $fileLinkFormat = null)
3940
{
4041
$this->exceptionHandler = $exceptionHandler;
4142
$this->logger = $logger;
4243
$this->levels = $levels;
4344
$this->debug = $debug;
45+
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4446
}
4547

4648
public function configure()
@@ -76,6 +78,7 @@ public function configure()
7678
}
7779
if ($handler instanceof ExceptionHandler) {
7880
$handler->setHandler($this->exceptionHandler);
81+
$handler->setFileLinkFormat($this->fileLinkFormat);
7982
}
8083
$this->exceptionHandler = null;
8184
}

0 commit comments

Comments
 (0)
0