Skip to content
Permalink
Browse files

feature #30469 Create a hyperlink to interfaces/classes that can be a…

…utowired (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
  • Loading branch information...
nicolas-grekas committed Mar 15, 2019
2 parents 05fe6a9 + a3dfcee commit f6662539aa34a5a6b3b7271dbec57721538ad619
@@ -12,11 +12,13 @@
namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\Descriptor;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
/**
* A console command for autowiring information.
@@ -28,6 +30,15 @@
class DebugAutowiringCommand extends ContainerDebugCommand
{
protected static $defaultName = 'debug:autowiring';
private $supportsHref;
private $fileLinkFormatter;
public function __construct(string $name = null, FileLinkFormatter $fileLinkFormatter = null)
{
$this->supportsHref = method_exists(OutputFormatterStyle::class, 'setHref');
$this->fileLinkFormatter = $fileLinkFormatter;
parent::__construct($name);
}
/**
* {@inheritdoc}
@@ -101,7 +112,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$previousId = $serviceId.' $';
}
$serviceLine = sprintf('<fg=yellow>%s</>', $serviceId);
if ($this->supportsHref && '' !== $fileLink = $this->getFileLink($serviceId)) {
$serviceLine = sprintf('<fg=yellow;href=%s>%s</>', $fileLink, $serviceId);
}
if ($builder->hasAlias($serviceId)) {
$hasAlias[$serviceId] = true;
$serviceAlias = $builder->getAlias($serviceId);
@@ -118,4 +134,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$io->newLine();
}
private function getFileLink(string $class): string
{
if (null === $this->fileLinkFormatter
|| (null === $r = $this->getContainerBuilder()->getReflectionClass($class, false))) {
return '';
}
return (string) $this->fileLinkFormatter->format($r->getFileName(), $r->getStartLine());
}
}
@@ -66,6 +66,8 @@
</service>

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

0 comments on commit f666253

Please sign in to comment.
You can’t perform that action at this time.