Skip to content

Commit

Permalink
Drop Twig, actually
Browse files Browse the repository at this point in the history
There is no known reason why it should be needed. This extension is hooked directly to kernel events leveraging tracy/tracy to render exceptions
  • Loading branch information
simPod committed Mar 3, 2021
1 parent 5b233a7 commit d9410d2
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 139 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
16 changes: 0 additions & 16 deletions src/DependencyInjection/Exception/TwigBundleRequired.php

This file was deleted.

36 changes: 1 addition & 35 deletions src/DependencyInjection/TracyBlueScreenExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,23 @@

namespace Cdn77\TracyBlueScreenBundle\DependencyInjection;

use Cdn77\TracyBlueScreenBundle\DependencyInjection\Exception\TwigBundleRequired;
use Cdn77\TracyBlueScreenBundle\TracyBlueScreenBundle;
use ReflectionClass;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;

use function assert;
use function dirname;
use function is_bool;
use function is_string;

//phpcs:disable SlevomatCodingStandard.Files.LineLength.LineTooLong
final class TracyBlueScreenExtension extends ConfigurableExtension implements PrependExtensionInterface
final class TracyBlueScreenExtension extends ConfigurableExtension
{
public const CONTAINER_PARAMETER_BLUE_SCREEN_COLLAPSE_PATHS = 'cdn77.tracy_blue_screen.blue_screen.collapse_paths';
public const CONTAINER_PARAMETER_CONSOLE_BROWSER = 'cdn77.tracy_blue_screen.console.browser';
public const CONTAINER_PARAMETER_CONSOLE_LISTENER_PRIORITY = 'cdn77.tracy_blue_screen.console.listener_priority';
public const CONTAINER_PARAMETER_CONSOLE_LOG_DIRECTORY = 'cdn77.tracy_blue_screen.console.log_directory';
public const CONTAINER_PARAMETER_CONTROLLER_LISTENER_PRIORITY = 'cdn77.tracy_blue_screen.controller.listener_priority';
public const TWIG_BUNDLE_ALIAS = 'twig';
private const TWIG_TEMPLATES_NAMESPACE = 'Twig';

public function prepend(ContainerBuilder $container) : void
{
if (! $container->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
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions src/Resources/views/Exception/exception_full.html.twig

This file was deleted.

8 changes: 0 additions & 8 deletions src/TracyBlueScreenBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
21 changes: 0 additions & 21 deletions tests/Cdn77/TracyBlueScreenBundle/TracyBlueScreenBundleTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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[]) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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[]) */
Expand Down
25 changes: 1 addition & 24 deletions tests/DependencyInjection/TracyBlueScreenExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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[]) */
Expand Down

0 comments on commit d9410d2

Please sign in to comment.