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

Skip to content
This repository was archived by the owner on Sep 14, 2018. It is now read-only.

Commit db11b65

Browse files
committed
feature #99 Added the Symfony default ide file link web view (jeremyFreeAgent)
This PR was merged into the 2.0.x-dev branch. Discussion ---------- Added the Symfony default ide file link web view This add the feature added by symfony/symfony#19973 Commits ------- 7e7f062 Added the Symfony default ide file link web view
2 parents 488b00d + 7e7f062 commit db11b65

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

WebProfilerServiceProvider.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
4848
use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
4949
use Symfony\Component\HttpKernel\DataCollector\EventDataCollector;
50+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
5051
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
5152
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
5253
use Symfony\Component\Security\Core\Role\RoleHierarchy;
@@ -69,6 +70,8 @@ public function register(Container $app)
6970
return new TraceableEventDispatcher($dispatcher, $app['stopwatch'], $app['logger']);
7071
});
7172

73+
$baseDir = $this->getBaseDir();
74+
7275
$app['data_collector.templates'] = function ($app) {
7376
$templates = array(
7477
array('config', '@WebProfiler/Collector/config.html.twig'),
@@ -232,8 +235,8 @@ public function register(Container $app)
232235
});
233236
}
234237

235-
$app['web_profiler.controller.profiler'] = function ($app) {
236-
return new ProfilerController($app['url_generator'], $app['profiler'], $app['twig'], $app['data_collector.templates'], $app['web_profiler.debug_toolbar.position']);
238+
$app['web_profiler.controller.profiler'] = function ($app) use ($baseDir) {
239+
return new ProfilerController($app['url_generator'], $app['profiler'], $app['twig'], $app['data_collector.templates'], $app['web_profiler.debug_toolbar.position'], null, $baseDir);
237240
};
238241

239242
$app['web_profiler.controller.router'] = function ($app) {
@@ -285,7 +288,11 @@ public function register(Container $app)
285288

286289
$app['code.file_link_format'] = null;
287290

288-
$app->extend('twig', function ($twig, $app) {
291+
$app->extend('twig', function ($twig, $app) use ($baseDir) {
292+
if (class_exists('\Symfony\Component\HttpKernel\Debug\FileLinkFormatter')) {
293+
$app['code.file_link_format'] = new FileLinkFormatter($app['code.file_link_format'], $app['request_stack'], $baseDir, '/_profiler/open?file=%f&line=%l#line%l');
294+
}
295+
289296
$twig->addExtension(new CodeExtension($app['code.file_link_format'], '', $app['charset']));
290297

291298
if (class_exists('\Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension')) {
@@ -344,6 +351,7 @@ public function connect(Application $app)
344351
$controllers->get('/purge', 'web_profiler.controller.profiler:purgeAction')->bind('_profiler_purge');
345352
$controllers->get('/info/{about}', 'web_profiler.controller.profiler:infoAction')->bind('_profiler_info');
346353
$controllers->get('/phpinfo', 'web_profiler.controller.profiler:phpinfoAction')->bind('_profiler_phpinfo');
354+
$controllers->get('/open', 'web_profiler.controller.profiler:openAction')->bind('_profiler_open_file');
347355
$controllers->get('/{token}/search/results', 'web_profiler.controller.profiler:searchResultsAction')->bind('_profiler_search_results');
348356
$controllers->get('/{token}', 'web_profiler.controller.profiler:panelAction')->bind('_profiler');
349357
$controllers->get('/wdt/{token}', 'web_profiler.controller.profiler:toolbarAction')->bind('_wdt');
@@ -371,4 +379,21 @@ public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
371379
$dispatcher->addSubscriber($app['var_dumper.dump_listener']);
372380
}
373381
}
382+
383+
private function getBaseDir()
384+
{
385+
$baseDir = array();
386+
$rootDir = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
387+
$rootDir = end($rootDir)['file'];
388+
$rootDir = explode(DIRECTORY_SEPARATOR, realpath($rootDir) ?: $rootDir);
389+
$providerDir = explode(DIRECTORY_SEPARATOR, __DIR__);
390+
for ($i = 0; isset($rootDir[$i], $providerDir[$i]); ++$i) {
391+
if ($rootDir[$i] !== $providerDir[$i]) {
392+
break;
393+
}
394+
$baseDir[] = $rootDir[$i];
395+
}
396+
397+
return implode(DIRECTORY_SEPARATOR, $baseDir);
398+
}
374399
}

0 commit comments

Comments
 (0)