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

Appearance settings

Commit f666253

Browse filesBrowse files
feature #30469 Create a hyperlink to interfaces/classes that can be autowired (SerkanYildiz)
This PR was squashed before being merged into the 4.3-dev branch (closes #30469). Discussion ---------- Create a hyperlink to interfaces/classes that can be autowired | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT Added hyperlink to definition of interfaces/classes that can be used for autowiring. But I need help with: - the aliases are becoming hyperlinks too, but shouldn't. It's outputting `<fg=yellow;href=phpstorm://open?file=filepath&line=17>Symfony\Contracts\Translation\TranslatorInterface</> <fg=cyan>(translator.default)</>` - it currently works with phpstorm because it's hardcoded but it should work with framework.ide option, but don't know what the best approach is to support that config option. Commits ------- a3dfcee Create a hyperlink to interfaces/classes that can be autowired
2 parents 05fe6a9 + a3dfcee commit f666253
Copy full SHA for f666253

File tree

2 files changed

+28
-0
lines changed
Filter options

2 files changed

+28
-0
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\Descriptor;
15+
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920
use Symfony\Component\Console\Style\SymfonyStyle;
21+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
2022

2123
/**
2224
* A console command for autowiring information.
@@ -28,6 +30,15 @@
2830
class DebugAutowiringCommand extends ContainerDebugCommand
2931
{
3032
protected static $defaultName = 'debug:autowiring';
33+
private $supportsHref;
34+
private $fileLinkFormatter;
35+
36+
public function __construct(string $name = null, FileLinkFormatter $fileLinkFormatter = null)
37+
{
38+
$this->supportsHref = method_exists(OutputFormatterStyle::class, 'setHref');
39+
$this->fileLinkFormatter = $fileLinkFormatter;
40+
parent::__construct($name);
41+
}
3142

3243
/**
3344
* {@inheritdoc}
@@ -101,7 +112,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
101112
}
102113
$previousId = $serviceId.' $';
103114
}
115+
104116
$serviceLine = sprintf('<fg=yellow>%s</>', $serviceId);
117+
if ($this->supportsHref && '' !== $fileLink = $this->getFileLink($serviceId)) {
118+
$serviceLine = sprintf('<fg=yellow;href=%s>%s</>', $fileLink, $serviceId);
119+
}
120+
105121
if ($builder->hasAlias($serviceId)) {
106122
$hasAlias[$serviceId] = true;
107123
$serviceAlias = $builder->getAlias($serviceId);
@@ -118,4 +134,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
118134
}
119135
$io->newLine();
120136
}
137+
138+
private function getFileLink(string $class): string
139+
{
140+
if (null === $this->fileLinkFormatter
141+
|| (null === $r = $this->getContainerBuilder()->getReflectionClass($class, false))) {
142+
return '';
143+
}
144+
145+
return (string) $this->fileLinkFormatter->format($r->getFileName(), $r->getStartLine());
146+
}
121147
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
</service>
6767

6868
<service id="console.command.debug_autowiring" class="Symfony\Bundle\FrameworkBundle\Command\DebugAutowiringCommand">
69+
<argument>null</argument>
70+
<argument type="service" id="debug.file_link_formatter" on-invalid="null"/>
6971
<tag name="console.command" command="debug:autowiring" />
7072
</service>
7173

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.