From d9410d231677eb8298824feb6b699bed164efa58 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Wed, 3 Mar 2021 15:13:14 +0100 Subject: [PATCH] Drop Twig, actually There is no known reason why it should be needed. This extension is hooked directly to kernel events leveraging tracy/tracy to render exceptions --- README.md | 4 +-- composer.json | 1 - .../Exception/TwigBundleRequired.php | 16 --------- .../TracyBlueScreenExtension.php | 36 +------------------ .../views/Exception/exception_full.html.twig | 3 -- src/TracyBlueScreenBundle.php | 8 ----- .../TracyBlueScreenBundleTest.php | 21 ----------- .../TracyBlueScreenExtensionConsoleTest.php | 15 +------- ...TracyBlueScreenExtensionControllerTest.php | 15 +------- .../TracyBlueScreenExtensionTest.php | 25 +------------ 10 files changed, 5 insertions(+), 139 deletions(-) delete mode 100644 src/DependencyInjection/Exception/TwigBundleRequired.php delete mode 100644 src/Resources/views/Exception/exception_full.html.twig delete mode 100644 tests/Cdn77/TracyBlueScreenBundle/TracyBlueScreenBundleTest.php diff --git a/README.md b/README.md index 5a5a62d..32d2da4 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,10 @@ To provide the same comfort while using [Symfony Console](http://symfony.com/doc Usage ----- -If you do not have any custom `kernel.exception` listeners this works out of the box. However if you have any, you have to ensure that they do not return any response, because that prevents the profiler from showing up (the same applies for the default Symfony exception screen). +If you do not have any custom `kernel.exception` listeners this works out of the box. However, if you have any, you have to ensure that they do not return any response, because that prevents the profiler from showing up (the same applies for the default Symfony exception screen). If you need to change the default position of this listener (see order in `bin/console debug:event-dispatcher`), use the configuration option `listener_priority`. -This bundle expects that you are using the default Symfony profiler screen rendered via the [TwigBundle](http://symfony.com/doc/current/reference/configuration/twig.html), which must be registered. - Console integration also works out of the box, if you do not have an `console.error` listener that would prevent execution of this one. Again, this can be tweaked using the respective `listener_priority` option. Configure the `browser` option to open the exceptions directly in your browser, configured binary must be executable with [`exec()`](http://php.net/manual/en/function.exec.php). diff --git a/composer.json b/composer.json index 165bda6..f86cecf 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,6 @@ "symfony/console": "^5.0", "symfony/dependency-injection": "^5.0", "symfony/http-kernel": "^5.0", - "symfony/twig-bundle": "^5.0", "symfony/yaml": "^5.0", "tracy/tracy": "^2.8" }, diff --git a/src/DependencyInjection/Exception/TwigBundleRequired.php b/src/DependencyInjection/Exception/TwigBundleRequired.php deleted file mode 100644 index f4092e1..0000000 --- a/src/DependencyInjection/Exception/TwigBundleRequired.php +++ /dev/null @@ -1,16 +0,0 @@ -hasExtension(self::TWIG_BUNDLE_ALIAS)) { - throw new TwigBundleRequired(); - } - - $container->loadFromExtension( - self::TWIG_BUNDLE_ALIAS, - [ - 'paths' => [ - $this->getTemplatesDirectory() => self::TWIG_TEMPLATES_NAMESPACE, - ], - ] - ); - } /** @param mixed[] $mergedConfig */ public function loadInternal(array $mergedConfig, ContainerBuilder $container) : void @@ -118,17 +95,6 @@ public function getConfiguration(array $config, ContainerBuilder $container) : C ); } - private function getTemplatesDirectory() : string - { - $bundleClassReflection = new ReflectionClass(TracyBlueScreenBundle::class); - $fileName = $bundleClassReflection->getFileName(); - assert($fileName !== false); - - $srcDirectoryPath = dirname($fileName); - - return $srcDirectoryPath . '/Resources/views'; - } - private function isEnabled(?bool $configOption, string $environment, bool $debug) : bool { if ($configOption === null) { diff --git a/src/Resources/views/Exception/exception_full.html.twig b/src/Resources/views/Exception/exception_full.html.twig deleted file mode 100644 index 74145fc..0000000 --- a/src/Resources/views/Exception/exception_full.html.twig +++ /dev/null @@ -1,3 +0,0 @@ - -{{ currentContent }} - diff --git a/src/TracyBlueScreenBundle.php b/src/TracyBlueScreenBundle.php index a0444a6..14181bd 100644 --- a/src/TracyBlueScreenBundle.php +++ b/src/TracyBlueScreenBundle.php @@ -4,16 +4,8 @@ namespace Cdn77\TracyBlueScreenBundle; -use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; final class TracyBlueScreenBundle extends Bundle { - public function build(ContainerBuilder $container) : void - { - parent::build($container); - - $container->registerExtension(new TwigExtension()); - } } diff --git a/tests/Cdn77/TracyBlueScreenBundle/TracyBlueScreenBundleTest.php b/tests/Cdn77/TracyBlueScreenBundle/TracyBlueScreenBundleTest.php deleted file mode 100644 index eb2ae73..0000000 --- a/tests/Cdn77/TracyBlueScreenBundle/TracyBlueScreenBundleTest.php +++ /dev/null @@ -1,21 +0,0 @@ -build($containerBuilder); - - self::assertTrue($containerBuilder->hasExtension(TracyBlueScreenExtension::TWIG_BUNDLE_ALIAS)); - } -} diff --git a/tests/DependencyInjection/TracyBlueScreenExtensionConsoleTest.php b/tests/DependencyInjection/TracyBlueScreenExtensionConsoleTest.php index 79abd48..f054973 100644 --- a/tests/DependencyInjection/TracyBlueScreenExtensionConsoleTest.php +++ b/tests/DependencyInjection/TracyBlueScreenExtensionConsoleTest.php @@ -7,7 +7,6 @@ use Cdn77\TracyBlueScreenBundle\BlueScreen\ConsoleBlueScreenErrorListener; use Cdn77\TracyBlueScreenBundle\DependencyInjection\TracyBlueScreenExtension; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; -use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; final class TracyBlueScreenExtensionConsoleTest extends AbstractExtensionTestCase @@ -21,15 +20,6 @@ public function setUp() : void $this->setParameter('kernel.cache_dir', __DIR__ . '/tests-cache-dir'); $this->setParameter('kernel.environment', 'dev'); $this->setParameter('kernel.debug', true); - $this->setParameter( - 'kernel.bundles_metadata', - [ - 'TwigBundle' => [ - 'namespace' => 'Symfony\\Bundle\\TwigBundle', - 'path' => __DIR__, - ], - ] - ); } public function testEnabledByDefault() : void @@ -162,10 +152,7 @@ public function testConfigureListenerPriority() : void /** @return ExtensionInterface[] */ protected function getContainerExtensions() : array { - return [ - new TracyBlueScreenExtension(), - new TwigExtension(), - ]; + return [new TracyBlueScreenExtension()]; } /** @param mixed[] $configuration format: extensionAlias(string) => configuration(mixed[]) */ diff --git a/tests/DependencyInjection/TracyBlueScreenExtensionControllerTest.php b/tests/DependencyInjection/TracyBlueScreenExtensionControllerTest.php index 89a659c..5e10add 100644 --- a/tests/DependencyInjection/TracyBlueScreenExtensionControllerTest.php +++ b/tests/DependencyInjection/TracyBlueScreenExtensionControllerTest.php @@ -7,7 +7,6 @@ use Cdn77\TracyBlueScreenBundle\BlueScreen\ControllerBlueScreenExceptionListener; use Cdn77\TracyBlueScreenBundle\DependencyInjection\TracyBlueScreenExtension; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; -use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; final class TracyBlueScreenExtensionControllerTest extends AbstractExtensionTestCase @@ -21,15 +20,6 @@ public function setUp() : void $this->setParameter('kernel.cache_dir', __DIR__ . '/tests-cache-dir'); $this->setParameter('kernel.environment', 'dev'); $this->setParameter('kernel.debug', true); - $this->setParameter( - 'kernel.bundles_metadata', - [ - 'TwigBundle' => [ - 'namespace' => 'Symfony\\Bundle\\TwigBundle', - 'path' => __DIR__, - ], - ] - ); } public function testEnabledByDefault() : void @@ -108,10 +98,7 @@ public function testConfigureListenerPriority() : void /** @return ExtensionInterface[] */ protected function getContainerExtensions() : array { - return [ - new TracyBlueScreenExtension(), - new TwigExtension(), - ]; + return [new TracyBlueScreenExtension()]; } /** @param mixed[] $configuration format: extensionAlias(string) => configuration(mixed[]) */ diff --git a/tests/DependencyInjection/TracyBlueScreenExtensionTest.php b/tests/DependencyInjection/TracyBlueScreenExtensionTest.php index 7459798..40149e2 100644 --- a/tests/DependencyInjection/TracyBlueScreenExtensionTest.php +++ b/tests/DependencyInjection/TracyBlueScreenExtensionTest.php @@ -4,10 +4,8 @@ namespace Cdn77\TracyBlueScreenBundle\Tests\DependencyInjection; -use Cdn77\TracyBlueScreenBundle\DependencyInjection\Exception\TwigBundleRequired; use Cdn77\TracyBlueScreenBundle\DependencyInjection\TracyBlueScreenExtension; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; -use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; @@ -68,24 +66,6 @@ public function setUp() : void $this->setParameter('kernel.cache_dir', __DIR__ . '/tests-cache-dir'); $this->setParameter('kernel.environment', 'dev'); $this->setParameter('kernel.debug', true); - $this->setParameter( - 'kernel.bundles_metadata', - [ - 'TwigBundle' => [ - 'namespace' => 'Symfony\\Bundle\\TwigBundle', - 'path' => __DIR__, - ], - ] - ); - } - - public function testDependsOnTwigBundle() : void - { - $containerBuilder = new ContainerBuilder(); - $extension = new TracyBlueScreenExtension(); - - $this->expectException(TwigBundleRequired::class); - $extension->prepend($containerBuilder); } public function testOnlyAddCollapsePaths() : void @@ -160,10 +140,7 @@ public function testEmptyCollapseDirs() : void /** @return ExtensionInterface[] */ protected function getContainerExtensions() : array { - return [ - new TracyBlueScreenExtension(), - new TwigExtension(), - ]; + return [new TracyBlueScreenExtension()]; } /** @param mixed[] $configuration format: extensionAlias(string) => configuration(mixed[]) */