Create a hyperlink to interfaces/classes that can be autowired

This commit is contained in:
Serkan Yildiz 2019-03-06 23:36:16 +01:00 committed by Nicolas Grekas
parent 5b38e17863
commit a3dfcee406
2 changed files with 28 additions and 0 deletions

View File

@ -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 @@ use Symfony\Component\Console\Style\SymfonyStyle;
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 @@ EOF
}
$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 @@ EOF
}
$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());
}
}

View File

@ -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>