Merge branch '4.4'
* 4.4: [Bridge/Twig] fix slow dep resolution on deps=low [ErrorRenderer] Add DebugCommand for easy debugging and testing [DoctrineBridge] Deprecated RegistryInterface
This commit is contained in:
commit
3d52d5a8f1
@ -64,6 +64,14 @@ DependencyInjection
|
||||
new Definition('%my_class%');
|
||||
```
|
||||
|
||||
DoctrineBridge
|
||||
--------------
|
||||
* Deprecated injecting `ClassMetadataFactory` in `DoctrineExtractor`, an instance of `EntityManagerInterface` should be
|
||||
injected instead.
|
||||
* Deprecated passing an `IdReader` to the `DoctrineChoiceLoader` when the query cannot be optimized with single id field.
|
||||
* Deprecated not passing an `IdReader` to the `DoctrineChoiceLoader` when the query can be optimized with single id field.
|
||||
* Deprecated `RegistryInterface`, use `Doctrine\Common\Persistence\ManagerRegistry`.
|
||||
|
||||
Filesystem
|
||||
----------
|
||||
|
||||
|
@ -115,10 +115,11 @@ DependencyInjection
|
||||
DoctrineBridge
|
||||
--------------
|
||||
|
||||
* Deprecated injecting `ClassMetadataFactory` in `DoctrineExtractor`, an instance of `EntityManagerInterface` should be
|
||||
* Removed the possibility to inject `ClassMetadataFactory` in `DoctrineExtractor`, an instance of `EntityManagerInterface` should be
|
||||
injected instead
|
||||
* Passing an `IdReader` to the `DoctrineChoiceLoader` when the query cannot be optimized with single id field will throw an exception, pass `null` instead
|
||||
* Not passing an `IdReader` to the `DoctrineChoiceLoader` when the query can be optimized with single id field will not apply any optimization
|
||||
* The `RegistryInterface` has been removed.
|
||||
|
||||
DomCrawler
|
||||
----------
|
||||
|
@ -12,6 +12,7 @@ CHANGELOG
|
||||
-----
|
||||
|
||||
* added `DoctrineClearEntityManagerMiddleware`
|
||||
* deprecated `RegistryInterface`, use `Doctrine\Common\Persistence\ManagerRegistry`
|
||||
|
||||
|
||||
4.3.0
|
||||
|
@ -17,6 +17,8 @@ use Doctrine\ORM\EntityManager;
|
||||
/**
|
||||
* References Doctrine connections and entity managers.
|
||||
*
|
||||
* @deprecated since Symfony 4.4, use Doctrine\Common\Persistence\ManagerRegistry instead
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface RegistryInterface extends ManagerRegistryInterface
|
||||
|
@ -34,6 +34,7 @@
|
||||
"symfony/translation": "^5.0",
|
||||
"symfony/yaml": "^4.4|^5.0",
|
||||
"symfony/security-acl": "^2.8|^3.0",
|
||||
"symfony/security-core": "^4.4|^5.0",
|
||||
"symfony/security-csrf": "^4.4|^5.0",
|
||||
"symfony/security-http": "^4.4|^5.0",
|
||||
"symfony/stopwatch": "^4.4|^5.0",
|
||||
|
@ -193,5 +193,11 @@
|
||||
<argument type="service" id="debug.file_link_formatter" on-invalid="null" />
|
||||
<tag name="console.command" command="debug:form" />
|
||||
</service>
|
||||
|
||||
<service id="console.command.error_renderer_debug" class="Symfony\Component\ErrorRenderer\Command\DebugCommand">
|
||||
<argument type="collection" /> <!-- All error renderers are injected here by ErrorRendererPass -->
|
||||
<argument type="service" id="debug.file_link_formatter" on-invalid="null" />
|
||||
<tag name="console.command" command="debug:error-renderer" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
123
src/Symfony/Component/ErrorRenderer/Command/DebugCommand.php
Normal file
123
src/Symfony/Component/ErrorRenderer/Command/DebugCommand.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\ErrorRenderer\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\ErrorRenderer\ErrorRenderer\ErrorRendererInterface;
|
||||
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
|
||||
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
|
||||
|
||||
/**
|
||||
* A console command for retrieving information about error renderers.
|
||||
*
|
||||
* @author Yonel Ceruto <yonelceruto@gmail.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DebugCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'debug:error-renderer';
|
||||
|
||||
private $renderers;
|
||||
private $fileLinkFormatter;
|
||||
|
||||
/**
|
||||
* @param ErrorRendererInterface[] $renderers
|
||||
*/
|
||||
public function __construct(array $renderers, FileLinkFormatter $fileLinkFormatter = null)
|
||||
{
|
||||
$this->renderers = $renderers;
|
||||
$this->fileLinkFormatter = $fileLinkFormatter;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addArgument('format', InputArgument::OPTIONAL, sprintf('Outputs a sample in a specific format (one of %s)', implode(', ', array_keys($this->renderers))))
|
||||
->setDescription('Displays all available error renderers and their formats.')
|
||||
->setHelp(<<<'EOF'
|
||||
The <info>%command.name%</info> command displays all available error renderers and
|
||||
their formats:
|
||||
|
||||
<info>php %command.full_name%</info>
|
||||
|
||||
Or output a sample in a specific format:
|
||||
|
||||
<info>php %command.full_name% json</info>
|
||||
|
||||
EOF
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$renderers = $this->renderers;
|
||||
|
||||
if ($format = $input->getArgument('format')) {
|
||||
if (!isset($renderers[$format])) {
|
||||
throw new InvalidArgumentException(sprintf('No error renderer found for format "%s". Known format are %s.', $format, implode(', ', array_keys($this->renderers))));
|
||||
}
|
||||
|
||||
$exception = FlattenException::createFromThrowable(new \Exception('This is a sample exception.'), 500, ['X-Debug' => false]);
|
||||
$io->writeln($renderers[$format]->render($exception));
|
||||
} else {
|
||||
$tableRows = [];
|
||||
foreach ($renderers as $format => $renderer) {
|
||||
$tableRows[] = [sprintf('<fg=cyan>%s</fg=cyan>', $format), $this->formatClassLink(\get_class($renderer))];
|
||||
}
|
||||
|
||||
$io->title('Error Renderers');
|
||||
$io->text('The following error renderers are available:');
|
||||
$io->newLine();
|
||||
$io->table(['Format', 'Class'], $tableRows);
|
||||
}
|
||||
}
|
||||
|
||||
private function formatClassLink(string $class): string
|
||||
{
|
||||
if ('' === $fileLink = $this->getFileLink($class)) {
|
||||
return $class;
|
||||
}
|
||||
|
||||
return sprintf('<href=%s>%s</>', $fileLink, $class);
|
||||
}
|
||||
|
||||
private function getFileLink(string $class): string
|
||||
{
|
||||
if (null === $this->fileLinkFormatter) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
$r = new \ReflectionClass($class);
|
||||
} catch (\ReflectionException $e) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->fileLinkFormatter->format($r->getFileName(), $r->getStartLine());
|
||||
}
|
||||
}
|
@ -24,11 +24,13 @@ class ErrorRendererPass implements CompilerPassInterface
|
||||
{
|
||||
private $rendererService;
|
||||
private $rendererTag;
|
||||
private $debugCommandService;
|
||||
|
||||
public function __construct(string $rendererService = 'error_renderer', string $rendererTag = 'error_renderer.renderer')
|
||||
public function __construct(string $rendererService = 'error_renderer', string $rendererTag = 'error_renderer.renderer', string $debugCommandService = 'console.command.error_renderer_debug')
|
||||
{
|
||||
$this->rendererService = $rendererService;
|
||||
$this->rendererTag = $rendererTag;
|
||||
$this->debugCommandService = $debugCommandService;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,5 +63,9 @@ class ErrorRendererPass implements CompilerPassInterface
|
||||
|
||||
$definition = $container->getDefinition($this->rendererService);
|
||||
$definition->replaceArgument(0, ServiceLocatorTagPass::register($container, $renderers));
|
||||
|
||||
if ($container->hasDefinition($this->debugCommandService)) {
|
||||
$container->getDefinition($this->debugCommandService)->replaceArgument(0, $renderers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\ErrorRenderer\Tests\Command;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\ErrorRenderer\Command\DebugCommand;
|
||||
use Symfony\Component\ErrorRenderer\ErrorRenderer\JsonErrorRenderer;
|
||||
use Symfony\Component\ErrorRenderer\ErrorRenderer\TxtErrorRenderer;
|
||||
use Symfony\Component\ErrorRenderer\ErrorRenderer\XmlErrorRenderer;
|
||||
|
||||
class DebugCommandTest extends TestCase
|
||||
{
|
||||
public function testAvailableRenderers()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$ret = $tester->execute([], ['decorated' => false]);
|
||||
|
||||
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
|
||||
$this->assertSame(<<<TXT
|
||||
|
||||
Error Renderers
|
||||
===============
|
||||
|
||||
The following error renderers are available:
|
||||
|
||||
-------- -----------------------------------------------------------------
|
||||
Format Class
|
||||
-------- -----------------------------------------------------------------
|
||||
json Symfony\Component\ErrorRenderer\ErrorRenderer\JsonErrorRenderer
|
||||
xml Symfony\Component\ErrorRenderer\ErrorRenderer\XmlErrorRenderer
|
||||
txt Symfony\Component\ErrorRenderer\ErrorRenderer\TxtErrorRenderer
|
||||
-------- -----------------------------------------------------------------
|
||||
|
||||
|
||||
TXT
|
||||
, $tester->getDisplay(true));
|
||||
}
|
||||
|
||||
public function testFormatArgument()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$ret = $tester->execute(['format' => 'json'], ['decorated' => false]);
|
||||
|
||||
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
|
||||
$this->assertSame(<<<TXT
|
||||
{
|
||||
"title": "Internal Server Error",
|
||||
"status": 500,
|
||||
"detail": "This is a sample exception."
|
||||
}
|
||||
|
||||
TXT
|
||||
, $tester->getDisplay(true));
|
||||
}
|
||||
|
||||
private function createCommandTester()
|
||||
{
|
||||
$command = new DebugCommand([
|
||||
'json' => new JsonErrorRenderer(false),
|
||||
'xml' => new XmlErrorRenderer(false),
|
||||
'txt' => new TxtErrorRenderer(false),
|
||||
]);
|
||||
|
||||
$application = new Application();
|
||||
$application->add($command);
|
||||
|
||||
return new CommandTester($application->find('debug:error-renderer'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage No error renderer found for format "foo". Known format are json, xml, txt.
|
||||
*/
|
||||
public function testInvalidFormat()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$tester->execute(['format' => 'foo'], ['decorated' => false]);
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/console": "^4.4",
|
||||
"symfony/dependency-injection": "^4.4",
|
||||
"symfony/http-kernel": "^4.4"
|
||||
},
|
||||
|
Reference in New Issue
Block a user