47
47
use Symfony \Component \HttpKernel \DataCollector \TimeDataCollector ;
48
48
use Symfony \Component \HttpKernel \DataCollector \LoggerDataCollector ;
49
49
use Symfony \Component \HttpKernel \DataCollector \EventDataCollector ;
50
+ use Symfony \Component \HttpKernel \Debug \FileLinkFormatter ;
50
51
use Symfony \Component \HttpKernel \Debug \TraceableEventDispatcher ;
51
52
use Symfony \Component \Security \Http \Logout \LogoutUrlGenerator ;
52
53
use Symfony \Component \Security \Core \Role \RoleHierarchy ;
@@ -69,6 +70,8 @@ public function register(Container $app)
69
70
return new TraceableEventDispatcher ($ dispatcher , $ app ['stopwatch ' ], $ app ['logger ' ]);
70
71
});
71
72
73
+ $ baseDir = $ this ->getBaseDir ();
74
+
72
75
$ app ['data_collector.templates ' ] = function ($ app ) {
73
76
$ templates = array (
74
77
array ('config ' , '@WebProfiler/Collector/config.html.twig ' ),
@@ -232,8 +235,8 @@ public function register(Container $app)
232
235
});
233
236
}
234
237
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 );
237
240
};
238
241
239
242
$ app ['web_profiler.controller.router ' ] = function ($ app ) {
@@ -285,7 +288,11 @@ public function register(Container $app)
285
288
286
289
$ app ['code.file_link_format ' ] = null ;
287
290
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
+
289
296
$ twig ->addExtension (new CodeExtension ($ app ['code.file_link_format ' ], '' , $ app ['charset ' ]));
290
297
291
298
if (class_exists ('\Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension ' )) {
@@ -344,6 +351,7 @@ public function connect(Application $app)
344
351
$ controllers ->get ('/purge ' , 'web_profiler.controller.profiler:purgeAction ' )->bind ('_profiler_purge ' );
345
352
$ controllers ->get ('/info/{about} ' , 'web_profiler.controller.profiler:infoAction ' )->bind ('_profiler_info ' );
346
353
$ controllers ->get ('/phpinfo ' , 'web_profiler.controller.profiler:phpinfoAction ' )->bind ('_profiler_phpinfo ' );
354
+ $ controllers ->get ('/open ' , 'web_profiler.controller.profiler:openAction ' )->bind ('_profiler_open_file ' );
347
355
$ controllers ->get ('/{token}/search/results ' , 'web_profiler.controller.profiler:searchResultsAction ' )->bind ('_profiler_search_results ' );
348
356
$ controllers ->get ('/{token} ' , 'web_profiler.controller.profiler:panelAction ' )->bind ('_profiler ' );
349
357
$ controllers ->get ('/wdt/{token} ' , 'web_profiler.controller.profiler:toolbarAction ' )->bind ('_wdt ' );
@@ -371,4 +379,21 @@ public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
371
379
$ dispatcher ->addSubscriber ($ app ['var_dumper.dump_listener ' ]);
372
380
}
373
381
}
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
+ }
374
399
}
0 commit comments