Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 837fdf3

Browse files
Better usage of the rootDir
1 parent 4dc20d7 commit 837fdf3

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ProfilerController
3535
private $templates;
3636
private $toolbarPosition;
3737
private $cspHandler;
38-
private $kernelRootDir;
38+
private $rootDir;
3939

4040
/**
4141
* Constructor.
@@ -45,17 +45,17 @@ class ProfilerController
4545
* @param \Twig_Environment $twig The twig environment
4646
* @param array $templates The templates
4747
* @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration)
48-
* @param string $kernelRootDir The Kernel root directory
48+
* @param string $rootDir The project root directory
4949
*/
50-
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal', ContentSecurityPolicyHandler $cspHandler = null, $kernelRootDir = null)
50+
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal', ContentSecurityPolicyHandler $cspHandler = null, $rootDir = null)
5151
{
5252
$this->generator = $generator;
5353
$this->profiler = $profiler;
5454
$this->twig = $twig;
5555
$this->templates = $templates;
5656
$this->toolbarPosition = $toolbarPosition;
5757
$this->cspHandler = $cspHandler;
58-
$this->kernelRootDir = $kernelRootDir;
58+
$this->rootDir = $rootDir;
5959
}
6060

6161
/**
@@ -406,8 +406,8 @@ public function phpinfoAction()
406406
*/
407407
public function openAction(Request $request)
408408
{
409-
if (null === $this->kernelRootDir) {
410-
throw new NotFoundHttpException('KernelRootDir should be set.');
409+
if (null === $this->rootDir) {
410+
throw new NotFoundHttpException('rootDir should be set.');
411411
}
412412

413413
if ($this->profiler) {
@@ -417,7 +417,7 @@ public function openAction(Request $request)
417417
$file = $request->query->get('file');
418418
$line = $request->query->get('line');
419419

420-
$filename = dirname($this->kernelRootDir).DIRECTORY_SEPARATOR.$file;
420+
$filename = $this->rootDir.DIRECTORY_SEPARATOR.$file;
421421

422422
if (preg_match("'(^|[/\\\\])\.\.?([/\\\\]|$)'", $file) || !is_readable($filename)) {
423423
throw new NotFoundHttpException(sprintf('The file "%s" cannot be opened.', $file));

src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ public function load(array $configs, ContainerBuilder $container)
5252
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
5353
$container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED);
5454
}
55+
56+
$profilerController = $container->getDefinition('web_profiler.controller.profiler');
57+
$profilerController->replaceArgument(6, dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__)))))))));
58+
59+
$fileLinkFormatter = $container->getDefinition('debug.file_link_formatter');
60+
$fileLinkFormatter->replaceArgument(2, dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__DIR__)))))))));
5561
}
5662

5763
/**

src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<argument>%data_collector.templates%</argument>
1313
<argument>%web_profiler.debug_toolbar.position%</argument>
1414
<argument type="service" id="web_profiler.csp.handler" />
15-
<argument>%kernel.root_dir%</argument>
15+
<argument>null</argument>
1616
</service>
1717

1818
<service id="web_profiler.controller.router" class="Symfony\Bundle\WebProfilerBundle\Controller\RouterController">
@@ -52,7 +52,7 @@
5252
<service id="debug.file_link_formatter" class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter" public="false">
5353
<argument>%debug.file_link_format%</argument>
5454
<argument type="service" id="request_stack" on-invalid="ignore" />
55-
<argument>%kernel.root_dir%</argument>
55+
<argument>null</argument>
5656
<argument>/_profiler/open?file=%%f&amp;line=%%l#line%%l</argument>
5757
</service>
5858
</services>

src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private function getFileLinkFormat()
7676
if ($request instanceof Request) {
7777
return array(
7878
$request->getSchemeAndHttpHost().$request->getBaseUrl().$this->urlFormat,
79-
dirname($this->rootDir).DIRECTORY_SEPARATOR, '',
79+
$this->rootDir.DIRECTORY_SEPARATOR, '',
8080
);
8181
}
8282
}

0 commit comments

Comments
 (0)