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

Commitaa5b6f9

Browse files
committed
feature#30827 [TwigBridge] Add template file link to debug:twig command (yceruto)
This PR was merged into the 4.3-dev branch.Discussion----------[TwigBridge] Add template file link to debug:twig command| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT![debug_twig_file_link](https://user-images.githubusercontent.com/2028198/55365428-8c85c680-54b2-11e9-9d4e-e4845fc7d411.png)Commits-------05e2e1e Add template file link
2 parentsa63496b +05e2e1e commitaa5b6f9

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

‎src/Symfony/Bridge/Twig/Command/DebugCommand.php‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
useSymfony\Component\Console\Output\OutputInterface;
2020
useSymfony\Component\Console\Style\SymfonyStyle;
2121
useSymfony\Component\Finder\Finder;
22+
useSymfony\Component\HttpKernel\Debug\FileLinkFormatter;
2223
useTwig\Environment;
2324
useTwig\Loader\ChainLoader;
2425
useTwig\Loader\FilesystemLoader;
@@ -38,8 +39,9 @@ class DebugCommand extends Command
3839
private$twigDefaultPath;
3940
private$rootDir;
4041
private$filesystemLoaders;
42+
private$fileLinkFormatter;
4143

42-
publicfunction__construct(Environment$twig,string$projectDir =null,array$bundlesMetadata = [],string$twigDefaultPath =null,string$rootDir =null)
44+
publicfunction__construct(Environment$twig,string$projectDir =null,array$bundlesMetadata = [],string$twigDefaultPath =null,string$rootDir =null,FileLinkFormatter$fileLinkFormatter =null)
4345
{
4446
parent::__construct();
4547

@@ -48,6 +50,7 @@ public function __construct(Environment $twig, string $projectDir = null, array
4850
$this->bundlesMetadata =$bundlesMetadata;
4951
$this->twigDefaultPath =$twigDefaultPath;
5052
$this->rootDir =$rootDir;
53+
$this->fileLinkFormatter =$fileLinkFormatter;
5154
}
5255

5356
protectedfunctionconfigure()
@@ -105,16 +108,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
105108

106109
privatefunctiondisplayPathsText(SymfonyStyle$io,string$name)
107110
{
108-
$files =$this->findTemplateFiles($name);
111+
$file =new \ArrayIterator($this->findTemplateFiles($name));
109112
$paths =$this->getLoaderPaths($name);
110113

111114
$io->section('Matched File');
112-
if ($files) {
113-
$io->success(array_shift($files));
115+
if ($file->valid()) {
116+
if ($fileLink =$this->getFileLink($file->key())) {
117+
$io->block($file->current(),'OK',sprintf('fg=black;bg=green;href=%s',$fileLink),'',true);
118+
}else {
119+
$io->success($file->current());
120+
}
121+
$file->next();
114122

115-
if ($files) {
123+
if ($file->valid()) {
116124
$io->section('Overridden Files');
117-
$io->listing($files);
125+
do {
126+
if ($fileLink =$this->getFileLink($file->key())) {
127+
$io->text(sprintf('* <href=%s>%s</>',$fileLink,$file->current()));
128+
}else {
129+
$io->text(sprintf('* %s',$file->current()));
130+
}
131+
$file->next();
132+
}while ($file->valid());
118133
}
119134
}else {
120135
$alternatives = [];
@@ -453,9 +468,9 @@ private function findTemplateFiles(string $name): array
453468

454469
if (is_file($filename)) {
455470
if (false !==$realpath =realpath($filename)) {
456-
$files[] =$this->getRelativePath($realpath);
471+
$files[$realpath] =$this->getRelativePath($realpath);
457472
}else {
458-
$files[] =$this->getRelativePath($filename);
473+
$files[$filename] =$this->getRelativePath($filename);
459474
}
460475
}
461476
}
@@ -563,4 +578,13 @@ private function getFilesystemLoaders(): array
563578

564579
return$this->filesystemLoaders;
565580
}
581+
582+
privatefunctiongetFileLink(string$absolutePath):string
583+
{
584+
if (null ===$this->fileLinkFormatter) {
585+
return'';
586+
}
587+
588+
return (string)$this->fileLinkFormatter->format($absolutePath,1);
589+
}
566590
}

‎src/Symfony/Bundle/TwigBundle/Resources/config/console.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<argument>%kernel.bundles_metadata%</argument>
1414
<argument>%twig.default_path%</argument>
1515
<argument>%kernel.root_dir%</argument>
16+
<argumenttype="service"id="debug.file_link_formatter"on-invalid="null" />
1617
<tagname="console.command"command="debug:twig" />
1718
</service>
1819

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp