Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit059b436

Browse files
committed
feature#19807 [FrameworkBundle] Add %debug.file_link_format% with remapping for IDE links (nicolas-grekas)
This PR was merged into the 3.2-dev branch.Discussion----------[FrameworkBundle] Add %debug.file_link_format% with remapping for IDE links| Q | A| ------------- | ---| Branch? | master| New feature? | yes| Tests pass? | yes| Fixed tickets |#14340| License | MIT| Doc PR |symfony/symfony-docs#6944`templating.helper.code.file_link_format` is a parameter that requires templating to be defined, but holds a concept that is used beyond templating borders.Let's make it a general parameter that can be injected easily when required.Commits-------1c4ca8c [FrameworkBundle] Add %debug.file_link_format% with remapping for IDE links
2 parents277c7fa +1c4ca8c commit059b436

File tree

20 files changed

+143
-76
lines changed

20 files changed

+143
-76
lines changed

‎src/Symfony/Bridge/Twig/Extension/CodeExtension.php‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ class CodeExtension extends \Twig_Extension
2525
/**
2626
* Constructor.
2727
*
28-
* @param string $fileLinkFormat The format for links to source files
29-
* @param string $rootDir The project root directory
30-
* @param string $charset The charset
28+
* @param string|array $fileLinkFormat The format for links to source files
29+
* @param string$rootDir The project root directory
30+
* @param string$charset The charset
3131
*/
3232
publicfunction__construct($fileLinkFormat,$rootDir,$charset)
3333
{
34-
$this->fileLinkFormat =$fileLinkFormat ?:ini_get('xdebug.file_link_format') ?:get_cfg_var('xdebug.file_link_format');
34+
$fileLinkFormat =$fileLinkFormat ?:ini_get('xdebug.file_link_format') ?:get_cfg_var('xdebug.file_link_format');
35+
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
36+
$i =max(strpos($fileLinkFormat,'%f'),strpos($fileLinkFormat,'%l'));
37+
$i =strpos($fileLinkFormat,'#',$i) ?:strlen($fileLinkFormat);
38+
$fileLinkFormat =array(substr($fileLinkFormat,0,$i),substr($fileLinkFormat,$i +1));
39+
parse_str($fileLinkFormat[1],$fileLinkFormat[1]);
40+
}
41+
$this->fileLinkFormat =$fileLinkFormat;
3542
$this->rootDir =str_replace('/',DIRECTORY_SEPARATOR,dirname($rootDir)).DIRECTORY_SEPARATOR;
3643
$this->charset =$charset;
3744
}
@@ -190,8 +197,15 @@ public function formatFile($file, $line, $text = null)
190197
*/
191198
publicfunctiongetFileLink($file,$line)
192199
{
193-
if ($this->fileLinkFormat &&is_file($file)) {
194-
returnstrtr($this->fileLinkFormat,array('%f' =>$file,'%l' =>$line));
200+
if ($this->fileLinkFormat &&file_exists($file)) {
201+
foreach ($this->fileLinkFormat[1]as$k =>$v) {
202+
if (0 ===strpos($file,$k)) {
203+
$file =substr_replace($file,$v,0,strlen($k));
204+
break;
205+
}
206+
}
207+
208+
returnstrtr($this->fileLinkFormat[0],array('%f' =>$file,'%l' =>$line));
195209
}
196210

197211
returnfalse;

‎src/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CodeExtensionTest extends \PHPUnit_Framework_TestCase
1919

2020
publicfunctiontestFormatFile()
2121
{
22-
$expected =sprintf('<a href="txmt://open?url=file://%s&amp;line=25" title="Click to open this file">%s at line 25</a>',__FILE__,__FILE__);
22+
$expected =sprintf('<a href="proto://foobar%s#&amp;line=25" title="Click to open this file">%s at line 25</a>',substr(__FILE__,5),__FILE__);
2323
$this->assertEquals($expected,$this->getExtension()->formatFile(__FILE__,25));
2424
}
2525

@@ -64,6 +64,6 @@ public function testGetName()
6464

6565
protectedfunctiongetExtension()
6666
{
67-
returnnewCodeExtension('txmt://open?url=file://%f&line=%l','/root','UTF-8');
67+
returnnewCodeExtension('proto://%f#&line=%l#'.substr(__FILE__,0,5).'=foobar','/root','UTF-8');
6868
}
6969
}

‎src/Symfony/Bundle/DebugBundle/DependencyInjection/Compiler/DumpDataCollectorPass.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ public function process(ContainerBuilder $container)
3333

3434
$definition =$container->getDefinition('data_collector.dump');
3535

36-
if ($container->hasParameter('templating.helper.code.file_link_format')) {
37-
$definition->replaceArgument(1,$container->getParameter('templating.helper.code.file_link_format'));
38-
}
39-
4036
if (!$container->hasParameter('web_profiler.debug_toolbar.mode') || WebDebugToolbarListener::DISABLED ===$container->getParameter('web_profiler.debug_toolbar.mode')) {
4137
$definition->replaceArgument(3,null);
4238
}

‎src/Symfony/Bundle/DebugBundle/Resources/config/services.xml‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
<serviceid="twig.extension.dump"class="Symfony\Bridge\Twig\Extension\DumpExtension"public="false">
99
<tagname="twig.extension" />
1010
<argumenttype="service"id="var_dumper.cloner" />
11+
<argumenttype="service"id="var_dumper.html_dumper" />
1112
</service>
1213

1314
<serviceid="data_collector.dump"class="Symfony\Component\HttpKernel\DataCollector\DumpDataCollector">
1415
<tagname="data_collector"id="dump"template="@Debug/Profiler/dump.html.twig"priority="240" />
1516
<argumenttype="service"id="debug.stopwatch"on-invalid="ignore" />
16-
<argument>null</argument><!-- %templating.helper.code.file_link_format%-->
17+
<argument>%debug.file_link_format%</argument>
1718
<argument>%kernel.charset%</argument>
1819
<argumenttype="service"id="request_stack" />
1920
<argument>null</argument><!-- var_dumper.cli_dumper when debug.dump_destination is set-->
@@ -29,6 +30,17 @@
2930
<serviceid="var_dumper.cli_dumper"class="Symfony\Component\VarDumper\Dumper\CliDumper">
3031
<argument>null</argument><!-- debug.dump_destination-->
3132
<argument>%kernel.charset%</argument>
33+
<argument>0</argument><!-- flags-->
34+
</service>
35+
<serviceid="var_dumper.html_dumper"class="Symfony\Component\VarDumper\Dumper\HtmlDumper"public="false">
36+
<argument>null</argument>
37+
<argument>%kernel.charset%</argument>
38+
<argument>0</argument><!-- flags-->
39+
<callmethod="setDisplayOptions">
40+
<argumenttype="collection">
41+
<argumentkey="fileLinkFormat">%debug.file_link_format%</argument>
42+
</argument>
43+
</call>
3244
</service>
3345
</services>
3446

‎src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/Compiler/DumpDataCollectorPassTest.php‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@
1919

2020
class DumpDataCollectorPassTestextends \PHPUnit_Framework_TestCase
2121
{
22-
publicfunctiontestProcessWithFileLinkFormatParameter()
23-
{
24-
$container =newContainerBuilder();
25-
$container->addCompilerPass(newDumpDataCollectorPass());
26-
$container->setParameter('templating.helper.code.file_link_format','file-link-format');
27-
28-
$definition =newDefinition('Symfony\Component\HttpKernel\DataCollector\DumpDataCollector',array(null,null,null,null));
29-
$container->setDefinition('data_collector.dump',$definition);
30-
31-
$container->compile();
32-
33-
$this->assertSame('file-link-format',$definition->getArgument(1));
34-
}
35-
3622
publicfunctiontestProcessWithoutFileLinkFormatParameter()
3723
{
3824
$container =newContainerBuilder();

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ public function load(array $configs, ContainerBuilder $container)
9090
$container->setParameter('kernel.trusted_proxies',$config['trusted_proxies']);
9191
$container->setParameter('kernel.default_locale',$config['default_locale']);
9292

93+
if (!$container->hasParameter('debug.file_link_format')) {
94+
if (!$container->hasParameter('templating.helper.code.file_link_format')) {
95+
$links =array(
96+
'textmate' =>'txmt://open?url=file://%%f&line=%%l',
97+
'macvim' =>'mvim://open?url=file://%%f&line=%%l',
98+
'emacs' =>'emacs://open?url=file://%%f&line=%%l',
99+
'sublime' =>'subl://open?url=file://%%f&line=%%l',
100+
);
101+
$ide =$config['ide'];
102+
103+
$container->setParameter('templating.helper.code.file_link_format',str_replace('%','%%',ini_get('xdebug.file_link_format') ?:get_cfg_var('xdebug.file_link_format')) ?: (isset($links[$ide]) ?$links[$ide] :$ide));
104+
}
105+
$container->setParameter('debug.file_link_format','%templating.helper.code.file_link_format%');
106+
}
107+
93108
if (!empty($config['test'])) {
94109
$loader->load('test.xml');
95110
}
@@ -120,7 +135,7 @@ public function load(array $configs, ContainerBuilder $container)
120135
}
121136

122137
if ($this->isConfigEnabled($container,$config['templating'])) {
123-
$this->registerTemplatingConfiguration($config['templating'],$config['ide'],$container,$loader);
138+
$this->registerTemplatingConfiguration($config['templating'],$container,$loader);
124139
}
125140

126141
$this->registerValidationConfiguration($config['validation'],$container,$loader);
@@ -431,11 +446,6 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
431446
}
432447

433448
$definition->replaceArgument(4,$debug);
434-
435-
if ($container->hasParameter('templating.helper.code.file_link_format')) {
436-
$definition->replaceArgument(5,'%templating.helper.code.file_link_format%');
437-
}
438-
439449
$definition->replaceArgument(6,$debug);
440450
}
441451

@@ -553,25 +563,13 @@ private function registerRequestConfiguration(array $config, ContainerBuilder $c
553563
* Loads the templating configuration.
554564
*
555565
* @param array $config A templating configuration array
556-
* @param string $ide
557566
* @param ContainerBuilder $container A ContainerBuilder instance
558567
* @param XmlFileLoader $loader An XmlFileLoader instance
559568
*/
560-
privatefunctionregisterTemplatingConfiguration(array$config,$ide,ContainerBuilder$container,XmlFileLoader$loader)
569+
privatefunctionregisterTemplatingConfiguration(array$config,ContainerBuilder$container,XmlFileLoader$loader)
561570
{
562571
$loader->load('templating.xml');
563572

564-
if (!$container->hasParameter('templating.helper.code.file_link_format')) {
565-
$links =array(
566-
'textmate' =>'txmt://open?url=file://%%f&line=%%l',
567-
'macvim' =>'mvim://open?url=file://%%f&line=%%l',
568-
'emacs' =>'emacs://open?url=file://%%f&line=%%l',
569-
'sublime' =>'subl://open?url=file://%%f&line=%%l',
570-
);
571-
572-
$container->setParameter('templating.helper.code.file_link_format',str_replace('%','%%',ini_get('xdebug.file_link_format') ?:get_cfg_var('xdebug.file_link_format')) ?: (isset($links[$ide]) ?$links[$ide] :$ide));
573-
}
574-
575573
$container->setParameter('fragment.renderer.hinclude.global_template',$config['hinclude_default_template']);
576574

577575
if ($container->getParameter('kernel.debug')) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<argument>-1</argument><!-- Log levels map for enabled error levels-->
1818
<argument>%debug.error_handler.throw_at%</argument>
1919
<argument>true</argument>
20-
<argument>null</argument><!-- %templating.helper.code.file_link_format%-->
20+
<argument>%debug.file_link_format%</argument>
2121
<argument>true</argument>
2222
</service>
2323

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<serviceid="templating.helper.code"class="Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper">
4646
<tagname="templating.helper"alias="code" />
47-
<argument>%templating.helper.code.file_link_format%</argument>
47+
<argument>%debug.file_link_format%</argument>
4848
<argument>%kernel.root_dir%</argument>
4949
<argument>%kernel.charset%</argument>
5050
</service>

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@ class CodeHelper extends Helper
2727
/**
2828
* Constructor.
2929
*
30-
* @param string $fileLinkFormat The format for links to source files
31-
* @param string $rootDir The project root directory
32-
* @param string $charset The charset
30+
* @param string|array $fileLinkFormat The format for links to source files
31+
* @param string$rootDir The project root directory
32+
* @param string$charset The charset
3333
*/
3434
publicfunction__construct($fileLinkFormat,$rootDir,$charset)
3535
{
36-
$this->fileLinkFormat =$fileLinkFormat ?:ini_get('xdebug.file_link_format') ?:get_cfg_var('xdebug.file_link_format');
36+
$fileLinkFormat =$fileLinkFormat ?:ini_get('xdebug.file_link_format') ?:get_cfg_var('xdebug.file_link_format');
37+
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
38+
$i =max(strpos($fileLinkFormat,'%f'),strpos($fileLinkFormat,'%l'));
39+
$i =strpos($fileLinkFormat,'#',$i) ?:strlen($fileLinkFormat);
40+
$fileLinkFormat =array(substr($fileLinkFormat,0,$i),substr($fileLinkFormat,$i +1));
41+
parse_str($fileLinkFormat[1],$fileLinkFormat[1]);
42+
}
43+
$this->fileLinkFormat =$fileLinkFormat;
3744
$this->rootDir =str_replace('\\','/',$rootDir).'/';
3845
$this->charset =$charset;
3946
}
@@ -186,7 +193,14 @@ public function formatFile($file, $line, $text = null)
186193
publicfunctiongetFileLink($file,$line)
187194
{
188195
if ($this->fileLinkFormat &&is_file($file)) {
189-
returnstrtr($this->fileLinkFormat,array('%f' =>$file,'%l' =>$line));
196+
foreach ($this->fileLinkFormat[1]as$k =>$v) {
197+
if (0 ===strpos($file,$k)) {
198+
$file =substr_replace($file,$v,0,strlen($k));
199+
break;
200+
}
201+
}
202+
203+
returnstrtr($this->fileLinkFormat[0],array('%f' =>$file,'%l' =>$line));
190204
}
191205

192206
returnfalse;

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public function testFileLinkFormat()
359359
{
360360
$container =$this->createContainerFromFile('full');
361361

362-
$this->assertEquals('file%link%format',$container->getParameter('templating.helper.code.file_link_format'));
362+
$this->assertEquals('file%link%format',$container->getParameter('debug.file_link_format'));
363363
}
364364

365365
publicfunctiontestValidationAnnotations()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp