Create a hyperlink to interfaces/classes that can be autowired
This commit is contained in:
parent
5b38e17863
commit
a3dfcee406
@ -12,11 +12,13 @@
|
|||||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\Descriptor;
|
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\Descriptor;
|
||||||
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A console command for autowiring information.
|
* A console command for autowiring information.
|
||||||
@ -28,6 +30,15 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
|||||||
class DebugAutowiringCommand extends ContainerDebugCommand
|
class DebugAutowiringCommand extends ContainerDebugCommand
|
||||||
{
|
{
|
||||||
protected static $defaultName = 'debug:autowiring';
|
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}
|
* {@inheritdoc}
|
||||||
@ -101,7 +112,12 @@ EOF
|
|||||||
}
|
}
|
||||||
$previousId = $serviceId.' $';
|
$previousId = $serviceId.' $';
|
||||||
}
|
}
|
||||||
|
|
||||||
$serviceLine = sprintf('<fg=yellow>%s</>', $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)) {
|
if ($builder->hasAlias($serviceId)) {
|
||||||
$hasAlias[$serviceId] = true;
|
$hasAlias[$serviceId] = true;
|
||||||
$serviceAlias = $builder->getAlias($serviceId);
|
$serviceAlias = $builder->getAlias($serviceId);
|
||||||
@ -118,4 +134,14 @@ EOF
|
|||||||
}
|
}
|
||||||
$io->newLine();
|
$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>
|
||||||
|
|
||||||
<service id="console.command.debug_autowiring" class="Symfony\Bundle\FrameworkBundle\Command\DebugAutowiringCommand">
|
<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" />
|
<tag name="console.command" command="debug:autowiring" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user