cdn77 / Tracy-Blue-Screen-Bundle
Showing 6 of 34 files from the diff.

@@ -1,121 +1,128 @@
Loading
1 1
<?php
2 2
3 -
declare(strict_types = 1);
3 +
declare(strict_types=1);
4 4
5 -
namespace VasekPurchart\TracyBlueScreenBundle\DependencyInjection;
5 +
namespace Cdn77\TracyBlueScreenBundle\DependencyInjection;
6 6
7 +
use Cdn77\TracyBlueScreenBundle\TracyBlueScreenBundle;
7 8
use ReflectionClass;
8 9
use Symfony\Component\Config\FileLocator;
9 10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11 +
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
10 12
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
11 -
use VasekPurchart\TracyBlueScreenBundle\TracyBlueScreenBundle;
13 +
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
12 14
13 -
class TracyBlueScreenExtension
14 -
	extends \Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension
15 -
	implements \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface
16 -
{
17 -
18 -
	public const CONTAINER_PARAMETER_BLUE_SCREEN_COLLAPSE_PATHS = 'vasek_purchart.tracy_blue_screen.blue_screen.collapse_paths';
19 -
	public const CONTAINER_PARAMETER_CONSOLE_BROWSER = 'vasek_purchart.tracy_blue_screen.console.browser';
20 -
	public const CONTAINER_PARAMETER_CONSOLE_LISTENER_PRIORITY = 'vasek_purchart.tracy_blue_screen.console.listener_priority';
21 -
	public const CONTAINER_PARAMETER_CONSOLE_LOG_DIRECTORY = 'vasek_purchart.tracy_blue_screen.console.log_directory';
22 -
	public const CONTAINER_PARAMETER_CONTROLLER_LISTENER_PRIORITY = 'vasek_purchart.tracy_blue_screen.controller.listener_priority';
23 -
24 -
	private const TWIG_BUNDLE_ALIAS = 'twig';
25 -
	private const TWIG_TEMPLATES_NAMESPACE = 'Twig';
26 -
27 -
	public function prepend(ContainerBuilder $container): void
28 -
	{
29 -
		if (!$container->hasExtension(self::TWIG_BUNDLE_ALIAS)) {
30 -
			throw new \VasekPurchart\TracyBlueScreenBundle\DependencyInjection\TwigBundleRequiredException();
31 -
		}
32 -
33 -
		$container->loadFromExtension(self::TWIG_BUNDLE_ALIAS, [
34 -
			'paths' => [
35 -
				$this->getTemplatesDirectory() => self::TWIG_TEMPLATES_NAMESPACE,
36 -
			],
37 -
		]);
38 -
	}
39 -
40 -
	private function getTemplatesDirectory(): string
41 -
	{
42 -
		$bundleClassReflection = new ReflectionClass(TracyBlueScreenBundle::class);
43 -
		$srcDirectoryPath = dirname($bundleClassReflection->getFileName());
44 -
45 -
		return $srcDirectoryPath . '/Resources/views';
46 -
	}
47 -
48 -
	/**
49 -
	 * @param mixed[] $mergedConfig
50 -
	 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
51 -
	 */
52 -
	public function loadInternal(array $mergedConfig, ContainerBuilder $container): void
53 -
	{
54 -
		$container->setParameter(
55 -
			self::CONTAINER_PARAMETER_BLUE_SCREEN_COLLAPSE_PATHS,
56 -
			$mergedConfig[Configuration::SECTION_BLUE_SCREEN][Configuration::PARAMETER_COLLAPSE_PATHS]
57 -
		);
58 -
		$container->setParameter(
59 -
			self::CONTAINER_PARAMETER_CONSOLE_BROWSER,
60 -
			$mergedConfig[Configuration::SECTION_CONSOLE][Configuration::PARAMETER_CONSOLE_BROWSER]
61 -
		);
62 -
		$container->setParameter(
63 -
			self::CONTAINER_PARAMETER_CONSOLE_LISTENER_PRIORITY,
64 -
			$mergedConfig[Configuration::SECTION_CONSOLE][Configuration::PARAMETER_CONSOLE_LISTENER_PRIORITY]
65 -
		);
66 -
		$container->setParameter(
67 -
			self::CONTAINER_PARAMETER_CONSOLE_LOG_DIRECTORY,
68 -
			$mergedConfig[Configuration::SECTION_CONSOLE][Configuration::PARAMETER_CONSOLE_LOG_DIRECTORY]
69 -
		);
70 -
		$container->setParameter(
71 -
			self::CONTAINER_PARAMETER_CONTROLLER_LISTENER_PRIORITY,
72 -
			$mergedConfig[Configuration::SECTION_CONTROLLER][Configuration::PARAMETER_CONTROLLER_LISTENER_PRIORITY]
73 -
		);
74 -
75 -
		$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
76 -
		$loader->load('services.yml');
77 -
78 -
		$environment = $container->getParameter('kernel.environment');
79 -
		$debug = $container->getParameter('kernel.debug');
80 -
81 -
		if ($this->isEnabled(
82 -
			$mergedConfig[Configuration::SECTION_CONSOLE][Configuration::PARAMETER_CONSOLE_ENABLED],
83 -
			$environment,
84 -
			$debug
85 -
		)) {
86 -
			$loader->load('console_listener.yml');
87 -
		}
88 -
		if ($this->isEnabled(
89 -
			$mergedConfig[Configuration::SECTION_CONTROLLER][Configuration::PARAMETER_CONTROLLER_ENABLED],
90 -
			$environment,
91 -
			$debug
92 -
		)) {
93 -
			$loader->load('controller_listener.yml');
94 -
		}
95 -
	}
96 -
97 -
	/**
98 -
	 * @param mixed[] $config
99 -
	 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
100 -
	 * @return \VasekPurchart\TracyBlueScreenBundle\DependencyInjection\Configuration
101 -
	 */
102 -
	public function getConfiguration(array $config, ContainerBuilder $container): Configuration
103 -
	{
104 -
		return new Configuration(
105 -
			$this->getAlias(),
106 -
			$container->getParameter('kernel.root_dir'),
107 -
			$container->getParameter('kernel.logs_dir'),
108 -
			$container->getParameter('kernel.cache_dir')
109 -
		);
110 -
	}
111 -
112 -
	private function isEnabled(?bool $configOption, string $environment, bool $debug): bool
113 -
	{
114 -
		if ($configOption === null) {
115 -
			return $environment === 'dev' && $debug === true;
116 -
		}
117 -
118 -
		return $configOption;
119 -
	}
15 +
use function assert;
16 +
use function dirname;
120 17
18 +
//phpcs:disable SlevomatCodingStandard.Files.LineLength.LineTooLong
19 +
class TracyBlueScreenExtension extends ConfigurableExtension implements PrependExtensionInterface
20 +
{
21 +
    public const CONTAINER_PARAMETER_BLUE_SCREEN_COLLAPSE_PATHS = 'cdn77.tracy_blue_screen.blue_screen.collapse_paths';
22 +
    public const CONTAINER_PARAMETER_CONSOLE_BROWSER = 'cdn77.tracy_blue_screen.console.browser';
23 +
    public const CONTAINER_PARAMETER_CONSOLE_LISTENER_PRIORITY = 'cdn77.tracy_blue_screen.console.listener_priority';
24 +
    public const CONTAINER_PARAMETER_CONSOLE_LOG_DIRECTORY = 'cdn77.tracy_blue_screen.console.log_directory';
25 +
    public const CONTAINER_PARAMETER_CONTROLLER_LISTENER_PRIORITY = 'cdn77.tracy_blue_screen.controller.listener_priority';
26 +
    private const TWIG_BUNDLE_ALIAS = 'twig';
27 +
    private const TWIG_TEMPLATES_NAMESPACE = 'Twig';
28 +
29 +
    public function prepend(ContainerBuilder $container) : void
30 +
    {
31 +
        if (! $container->hasExtension(self::TWIG_BUNDLE_ALIAS)) {
32 +
            throw new TwigBundleRequired();
33 +
        }
34 +
35 +
        $container->loadFromExtension(
36 +
            self::TWIG_BUNDLE_ALIAS,
37 +
            [
38 +
                'paths' => [
39 +
                    $this->getTemplatesDirectory() => self::TWIG_TEMPLATES_NAMESPACE,
40 +
                ],
41 +
            ]
42 +
        );
43 +
    }
44 +
45 +
    /** @param mixed[] $mergedConfig */
46 +
    public function loadInternal(array $mergedConfig, ContainerBuilder $container) : void
47 +
    {
48 +
        $container->setParameter(
49 +
            self::CONTAINER_PARAMETER_BLUE_SCREEN_COLLAPSE_PATHS,
50 +
            $mergedConfig[Configuration::SECTION_BLUE_SCREEN][Configuration::PARAMETER_COLLAPSE_PATHS]
51 +
        );
52 +
        $container->setParameter(
53 +
            self::CONTAINER_PARAMETER_CONSOLE_BROWSER,
54 +
            $mergedConfig[Configuration::SECTION_CONSOLE][Configuration::PARAMETER_CONSOLE_BROWSER]
55 +
        );
56 +
        $container->setParameter(
57 +
            self::CONTAINER_PARAMETER_CONSOLE_LISTENER_PRIORITY,
58 +
            $mergedConfig[Configuration::SECTION_CONSOLE][Configuration::PARAMETER_CONSOLE_LISTENER_PRIORITY]
59 +
        );
60 +
        $container->setParameter(
61 +
            self::CONTAINER_PARAMETER_CONSOLE_LOG_DIRECTORY,
62 +
            $mergedConfig[Configuration::SECTION_CONSOLE][Configuration::PARAMETER_CONSOLE_LOG_DIRECTORY]
63 +
        );
64 +
        $container->setParameter(
65 +
            self::CONTAINER_PARAMETER_CONTROLLER_LISTENER_PRIORITY,
66 +
            $mergedConfig[Configuration::SECTION_CONTROLLER][Configuration::PARAMETER_CONTROLLER_LISTENER_PRIORITY]
67 +
        );
68 +
69 +
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
70 +
        $loader->load('services.yml');
71 +
72 +
        $environment = $container->getParameter('kernel.environment');
73 +
        $debug = $container->getParameter('kernel.debug');
74 +
75 +
        if (
76 +
            $this->isEnabled(
77 +
                $mergedConfig[Configuration::SECTION_CONSOLE][Configuration::PARAMETER_CONSOLE_ENABLED],
78 +
                $environment,
79 +
                $debug
80 +
            )
81 +
        ) {
82 +
            $loader->load('console_listener.yml');
83 +
        }
84 +
85 +
        if (
86 +
            ! $this->isEnabled(
87 +
                $mergedConfig[Configuration::SECTION_CONTROLLER][Configuration::PARAMETER_CONTROLLER_ENABLED],
88 +
                $environment,
89 +
                $debug
90 +
            )
91 +
        ) {
92 +
            return;
93 +
        }
94 +
95 +
        $loader->load('controller_listener.yml');
96 +
    }
97 +
98 +
    /** @param mixed[] $config */
99 +
    public function getConfiguration(array $config, ContainerBuilder $container) : Configuration
100 +
    {
101 +
        return new Configuration(
102 +
            $this->getAlias(),
103 +
            $container->getParameter('kernel.root_dir'),
104 +
            $container->getParameter('kernel.logs_dir'),
105 +
            $container->getParameter('kernel.cache_dir')
106 +
        );
107 +
    }
108 +
109 +
    private function getTemplatesDirectory() : string
110 +
    {
111 +
        $bundleClassReflection = new ReflectionClass(TracyBlueScreenBundle::class);
112 +
        $fileName = $bundleClassReflection->getFileName();
113 +
        assert($fileName !== false);
114 +
115 +
        $srcDirectoryPath = dirname($fileName);
116 +
117 +
        return $srcDirectoryPath . '/Resources/views';
118 +
    }
119 +
120 +
    private function isEnabled(?bool $configOption, string $environment, bool $debug) : bool
121 +
    {
122 +
        if ($configOption === null) {
123 +
            return $environment === 'dev' && $debug === true;
124 +
        }
125 +
126 +
        return $configOption;
127 +
    }
121 128
}

@@ -1,25 +1,22 @@
Loading
1 1
<?php
2 2
3 -
declare(strict_types = 1);
3 +
declare(strict_types=1);
4 4
5 -
namespace VasekPurchart\TracyBlueScreenBundle\BlueScreen;
5 +
namespace Cdn77\TracyBlueScreenBundle\BlueScreen;
6 6
7 7
use Tracy\BlueScreen;
8 8
use Tracy\Debugger;
9 9
10 +
use function array_merge;
11 +
10 12
class BlueScreenFactory
11 13
{
14 +
    /** @param string[] $collapsePaths */
15 +
    public static function create(array $collapsePaths) : BlueScreen
16 +
    {
17 +
        $blueScreen = Debugger::getBlueScreen();
18 +
        $blueScreen->collapsePaths = array_merge($blueScreen->collapsePaths, $collapsePaths);
12 19
13 -
	/**
14 -
	 * @param string[] $collapsePaths
15 -
	 * @return \Tracy\BlueScreen
16 -
	 */
17 -
	public static function create(array $collapsePaths): BlueScreen
18 -
	{
19 -
		$blueScreen = Debugger::getBlueScreen();
20 -
		$blueScreen->collapsePaths = array_merge($blueScreen->collapsePaths, $collapsePaths);
21 -
22 -
		return $blueScreen;
23 -
	}
24 -
20 +
        return $blueScreen;
21 +
    }
25 22
}

@@ -1,101 +1,98 @@
Loading
1 1
<?php
2 2
3 -
declare(strict_types = 1);
3 +
declare(strict_types=1);
4 4
5 -
namespace VasekPurchart\TracyBlueScreenBundle\BlueScreen;
5 +
namespace Cdn77\TracyBlueScreenBundle\BlueScreen;
6 6
7 +
use InvalidArgumentException;
7 8
use Symfony\Component\Console\Event\ConsoleErrorEvent;
8 9
use Symfony\Component\Console\Output\ConsoleOutputInterface;
9 10
use Symfony\Component\Console\Output\OutputInterface;
10 11
use Tracy\BlueScreen;
11 12
use Tracy\Logger as TracyLogger;
12 13
14 +
use function escapeshellarg;
15 +
use function exec;
16 +
use function gettype;
17 +
use function is_dir;
18 +
use function is_writable;
19 +
use function sprintf;
20 +
13 21
class ConsoleBlueScreenErrorListener
14 22
{
15 -
16 -
	/** @var \Tracy\Logger */
17 -
	private $tracyLogger;
18 -
19 -
	/** @var \Tracy\BlueScreen */
20 -
	private $blueScreen;
21 -
22 -
	/** @var string|null */
23 -
	private $logDirectory;
24 -
25 -
	/** @var string|null */
26 -
	private $browser;
27 -
28 -
	public function __construct(
29 -
		TracyLogger $tracyLogger,
30 -
		BlueScreen $blueScreen,
31 -
		?string $logDirectory,
32 -
		?string $browser
33 -
	)
34 -
	{
35 -
		$this->tracyLogger = $tracyLogger;
36 -
		$this->blueScreen = $blueScreen;
37 -
		$this->logDirectory = $logDirectory;
38 -
		$this->browser = $browser;
39 -
	}
40 -
41 -
	public function onConsoleError(ConsoleErrorEvent $event): void
42 -
	{
43 -
		if ($this->tracyLogger->directory === null) {
44 -
			$this->tracyLogger->directory = $this->logDirectory;
45 -
		}
46 -
47 -
		if (
48 -
			$this->tracyLogger->directory === null
49 -
			|| !is_dir($this->tracyLogger->directory)
50 -
			|| !is_writable($this->tracyLogger->directory)
51 -
		) {
52 -
			throw new \InvalidArgumentException(sprintf(
53 -
				'Log directory must be a writable directory, %s [%s] given',
54 -
				$this->tracyLogger->directory,
55 -
				gettype($this->tracyLogger->directory)
56 -
			), 0, $event->getError());
57 -
		}
58 -
59 -
		$exception = $event->getError();
60 -
		$exceptionFile = $this->tracyLogger->getExceptionFile($exception);
61 -
		$this->blueScreen->renderToFile($exception, $exceptionFile);
62 -
63 -
		$output = $event->getOutput();
64 -
		$this->printErrorMessage($output, sprintf('BlueScreen saved in file: %s', $exceptionFile));
65 -
		if ($this->browser === null) {
66 -
			return;
67 -
		}
68 -
		// @codeCoverageIgnoreStart
69 -
		// uses global state
70 -
		$this->openBrowser($this->browser, $exceptionFile);
71 -
	}
72 -
	// @codeCoverageIgnoreEnd
73 -
74 -
	private function printErrorMessage(OutputInterface $output, string $message): void
75 -
	{
76 -
		$message = sprintf('<error>%s</error>', $message);
77 -
		if ($output instanceof ConsoleOutputInterface) {
78 -
			$output->getErrorOutput()->writeln($message);
79 -
		} else {
80 -
			$output->writeln($message);
81 -
		}
82 -
	}
83 -
84 -
	/**
85 -
	 * @codeCoverageIgnore uses global state
86 -
	 *
87 -
	 * @param string $browser
88 -
	 * @param string $file
89 -
	 */
90 -
	private function openBrowser(string $browser, string $file): void
91 -
	{
92 -
		static $showed = false;
93 -
		if ($showed) {
94 -
			return;
95 -
		}
96 -
97 -
		exec(sprintf('%s %s', $browser, escapeshellarg($file)));
98 -
		$showed = true;
99 -
	}
100 -
23 +
    /** @var TracyLogger */
24 +
    private $tracyLogger;
25 +
26 +
    /** @var BlueScreen */
27 +
    private $blueScreen;
28 +
29 +
    /** @var string|null */
30 +
    private $logDirectory;
31 +
32 +
    /** @var string|null */
33 +
    private $browser;
34 +
35 +
    public function __construct(
36 +
        TracyLogger $tracyLogger,
37 +
        BlueScreen $blueScreen,
38 +
        ?string $logDirectory,
39 +
        ?string $browser
40 +
    ) {
41 +
        $this->tracyLogger = $tracyLogger;
42 +
        $this->blueScreen = $blueScreen;
43 +
        $this->logDirectory = $logDirectory;
44 +
        $this->browser = $browser;
45 +
    }
46 +
47 +
    public function onConsoleError(ConsoleErrorEvent $event) : void
48 +
    {
49 +
        if ($this->tracyLogger->directory === null) {
50 +
            $this->tracyLogger->directory = $this->logDirectory;
51 +
        }
52 +
53 +
        if (
54 +
            $this->tracyLogger->directory === null
55 +
            || ! is_dir($this->tracyLogger->directory)
56 +
            || ! is_writable($this->tracyLogger->directory)
57 +
        ) {
58 +
            throw new InvalidArgumentException(sprintf(
59 +
                'Log directory must be a writable directory, %s [%s] given',
60 +
                $this->tracyLogger->directory,
61 +
                gettype($this->tracyLogger->directory)
62 +
            ), 0, $event->getError());
63 +
        }
64 +
65 +
        $exception = $event->getError();
66 +
        $exceptionFile = $this->tracyLogger->getExceptionFile($exception);
67 +
        $this->blueScreen->renderToFile($exception, $exceptionFile);
68 +
69 +
        $output = $event->getOutput();
70 +
        $this->printErrorMessage($output, sprintf('BlueScreen saved in file: %s', $exceptionFile));
71 +
        if ($this->browser === null) {
72 +
            return;
73 +
        }
74 +
75 +
        $this->openBrowser($this->browser, $exceptionFile);
76 +
    }
77 +
78 +
    private function printErrorMessage(OutputInterface $output, string $message) : void
79 +
    {
80 +
        $message = sprintf('<error>%s</error>', $message);
81 +
        if ($output instanceof ConsoleOutputInterface) {
82 +
            $output->getErrorOutput()->writeln($message);
83 +
        } else {
84 +
            $output->writeln($message);
85 +
        }
86 +
    }
87 +
88 +
    private function openBrowser(string $browser, string $file) : void
89 +
    {
90 +
        static $showed = false;
91 +
        if ($showed) {
92 +
            return;
93 +
        }
94 +
95 +
        exec(sprintf('%s %s', $browser, escapeshellarg($file)));
96 +
        $showed = true;
97 +
    }
101 98
}

@@ -1,51 +1,51 @@
Loading
1 1
<?php
2 2
3 -
declare(strict_types = 1);
3 +
declare(strict_types=1);
4 4
5 -
namespace VasekPurchart\TracyBlueScreenBundle\BlueScreen;
5 +
namespace Cdn77\TracyBlueScreenBundle\BlueScreen;
6 6
7 7
use Symfony\Component\HttpFoundation\Request;
8 8
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
9 +
use Throwable;
9 10
use Tracy\BlueScreen;
10 11
12 +
use function header;
13 +
use function headers_sent;
14 +
use function strpos;
15 +
11 16
class ControllerBlueScreenExceptionListener
12 17
{
13 -
14 -
	/** @var \Tracy\BlueScreen */
15 -
	private $blueScreen;
16 -
17 -
	public function __construct(
18 -
		BlueScreen $blueScreen
19 -
	)
20 -
	{
21 -
		$this->blueScreen = $blueScreen;
22 -
	}
23 -
24 -
	public function onKernelException(GetResponseForExceptionEvent $event): void
25 -
	{
26 -
		$this->forceExceptionControllerHtml($event->getRequest());
27 -
		$this->renderBlueScreen($event->getException());
28 -
	}
29 -
30 -
	private function forceExceptionControllerHtml(Request $request): void
31 -
	{
32 -
		$request->setRequestFormat('html');
33 -
		$request->attributes->set('_format', 'html');
34 -
	}
35 -
36 -
	private function renderBlueScreen(\Throwable $exception): void
37 -
	{
38 -
		if (!headers_sent()) {
39 -
			// @codeCoverageIgnoreStart
40 -
			// sends output and uses global state
41 -
			$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
42 -
			$code = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== false ? 503 : 500;
43 -
			header($protocol . ' ' . $code, true, $code);
44 -
			header('Content-Type: text/html; charset=UTF-8');
45 -
		}
46 -
		// @codeCoverageIgnoreEnd
47 -
48 -
		$this->blueScreen->render($exception);
49 -
	}
50 -
18 +
    /** @var BlueScreen */
19 +
    private $blueScreen;
20 +
21 +
    public function __construct(BlueScreen $blueScreen)
22 +
    {
23 +
        $this->blueScreen = $blueScreen;
24 +
    }
25 +
26 +
    public function onKernelException(GetResponseForExceptionEvent $event) : void
27 +
    {
28 +
        $this->forceExceptionControllerHtml($event->getRequest());
29 +
        $this->renderBlueScreen($event->getException());
30 +
    }
31 +
32 +
    private function forceExceptionControllerHtml(Request $request) : void
33 +
    {
34 +
        $request->setRequestFormat('html');
35 +
        $request->attributes->set('_format', 'html');
36 +
    }
37 +
38 +
    private function renderBlueScreen(Throwable $exception) : void
39 +
    {
40 +
        if (! headers_sent()) {
41 +
            $protocol = $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1';
42 +
            $code = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== false
43 +
                ? 503
44 +
                : 500;
45 +
            header($protocol . ' ' . $code, true, $code);
46 +
            header('Content-Type: text/html; charset=UTF-8');
47 +
        }
48 +
49 +
        $this->blueScreen->render($exception);
50 +
    }
51 51
}

@@ -0,0 +1,16 @@
Loading
1 +
<?php
2 +
3 +
declare(strict_types=1);
4 +
5 +
namespace Cdn77\TracyBlueScreenBundle\DependencyInjection;
6 +
7 +
use Exception;
8 +
use Throwable;
9 +
10 +
class TwigBundleRequired extends Exception
11 +
{
12 +
    public function __construct(?Throwable $previous = null)
13 +
    {
14 +
        parent::__construct('TwigBundle must be registered for this bundle to work properly', 0, $previous);
15 +
    }
16 +
}

@@ -1,119 +1,122 @@
Loading
1 1
<?php
2 2
3 -
declare(strict_types = 1);
3 +
declare(strict_types=1);
4 4
5 -
namespace VasekPurchart\TracyBlueScreenBundle\DependencyInjection;
5 +
namespace Cdn77\TracyBlueScreenBundle\DependencyInjection;
6 6
7 +
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7 8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9 +
use Symfony\Component\Config\Definition\ConfigurationInterface;
8 10
use Tracy\Logger as TracyLogger;
9 11
10 -
class Configuration implements \Symfony\Component\Config\Definition\ConfigurationInterface
11 -
{
12 -
13 -
	public const PARAMETER_COLLAPSE_PATHS = 'collapse_paths';
14 -
	public const PARAMETER_CONSOLE_BROWSER = 'browser';
15 -
	public const PARAMETER_CONSOLE_ENABLED = 'enabled';
16 -
	public const PARAMETER_CONSOLE_LISTENER_PRIORITY = 'listener_priority';
17 -
	public const PARAMETER_CONSOLE_LOG_DIRECTORY = 'log_directory';
18 -
	public const PARAMETER_CONTROLLER_ENABLED = 'enabled';
19 -
	public const PARAMETER_CONTROLLER_LISTENER_PRIORITY = 'listener_priority';
12 +
use function assert;
13 +
use function sprintf;
20 14
21 -
	public const SECTION_BLUE_SCREEN = 'blue_screen';
22 -
	public const SECTION_CONSOLE = 'console';
23 -
	public const SECTION_CONTROLLER = 'controller';
15 +
class Configuration implements ConfigurationInterface
16 +
{
17 +
    public const PARAMETER_COLLAPSE_PATHS = 'collapse_paths';
18 +
    public const PARAMETER_CONSOLE_BROWSER = 'browser';
19 +
    public const PARAMETER_CONSOLE_ENABLED = 'enabled';
20 +
    public const PARAMETER_CONSOLE_LISTENER_PRIORITY = 'listener_priority';
21 +
    public const PARAMETER_CONSOLE_LOG_DIRECTORY = 'log_directory';
22 +
    public const PARAMETER_CONTROLLER_ENABLED = 'enabled';
23 +
    public const PARAMETER_CONTROLLER_LISTENER_PRIORITY = 'listener_priority';
24 24
25 -
	/** @var string */
26 -
	private $rootNode;
25 +
    public const SECTION_BLUE_SCREEN = 'blue_screen';
26 +
    public const SECTION_CONSOLE = 'console';
27 +
    public const SECTION_CONTROLLER = 'controller';
27 28
28 -
	/** @var string */
29 -
	private $kernelRootDir;
29 +
    /** @var string */
30 +
    private $alias;
30 31
31 -
	/** @var string */
32 -
	private $kernelLogsDir;
32 +
    /** @var string */
33 +
    private $kernelRootDir;
33 34
34 -
	/** @var string */
35 -
	private $kernelCacheDir;
35 +
    /** @var string */
36 +
    private $kernelLogsDir;
36 37
37 -
	public function __construct(
38 -
		string $rootNode,
39 -
		string $kernelRootDir,
40 -
		string $kernelLogsDir,
41 -
		string $kernelCacheDir
42 -
	)
43 -
	{
44 -
		$this->rootNode = $rootNode;
45 -
		$this->kernelRootDir = $kernelRootDir;
46 -
		$this->kernelLogsDir = $kernelLogsDir;
47 -
		$this->kernelCacheDir = $kernelCacheDir;
48 -
	}
38 +
    /** @var string */
39 +
    private $kernelCacheDir;
49 40
50 -
	public function getConfigTreeBuilder(): TreeBuilder
51 -
	{
52 -
		$treeBuilder = new TreeBuilder();
53 -
		$rootNode = $treeBuilder->root($this->rootNode);
41 +
    public function __construct(string $alias, string $kernelRootDir, string $kernelLogsDir, string $kernelCacheDir)
42 +
    {
43 +
        $this->alias = $alias;
44 +
        $this->kernelRootDir = $kernelRootDir;
45 +
        $this->kernelLogsDir = $kernelLogsDir;
46 +
        $this->kernelCacheDir = $kernelCacheDir;
47 +
    }
54 48
55 -
		$rootNode
56 -
			->children()
57 -
				->arrayNode(self::SECTION_CONTROLLER)
58 -
					->addDefaultsIfNotSet()
59 -
					->children()
60 -
						->scalarNode(self::PARAMETER_CONTROLLER_ENABLED)
61 -
							->info('Enable debug screen for controllers.')
62 -
							->defaultNull()
63 -
							->end()
64 -
						->integerNode(self::PARAMETER_CONTROLLER_LISTENER_PRIORITY)
65 -
							->info('Priority with which the listener will be registered.')
66 -
							->defaultValue(0)
67 -
							->end()
68 -
						->end()
69 -
					->end()
70 -
				->arrayNode(self::SECTION_CONSOLE)
71 -
					->addDefaultsIfNotSet()
72 -
					->children()
73 -
						->scalarNode(self::PARAMETER_CONSOLE_ENABLED)
74 -
							->info('Enable debug screen for console.')
75 -
							->defaultNull()
76 -
							->end()
77 -
						->scalarNode(self::PARAMETER_CONSOLE_LOG_DIRECTORY)
78 -
							->info(
79 -
								'Directory, where BlueScreens for console will be stored.'
80 -
								. ' If you are already using Tracy for logging, set this to the same.'
81 -
								. sprintf(' This will be only used, if given %s instance does not have a directory set.', TracyLogger::class)
82 -
							)
83 -
							->defaultValue($this->kernelLogsDir)
84 -
							->end()
85 -
						->scalarNode(self::PARAMETER_CONSOLE_BROWSER)
86 -
							->info(
87 -
								'Configure this to open generated BlueScreen in your browser.'
88 -
								. ' Configuration option may be for example \'google-chrome\' or \'firefox\''
89 -
								. ' and it will be invoked as a shell command.'
90 -
							)
91 -
							->defaultNull()
92 -
							->end()
93 -
						->integerNode(self::PARAMETER_CONSOLE_LISTENER_PRIORITY)
94 -
							->info('Priority with which the listener will be registered.')
95 -
							->defaultValue(0)
96 -
							->end()
97 -
						->end()
98 -
					->end()
99 -
				->arrayNode(self::SECTION_BLUE_SCREEN)
100 -
					->addDefaultsIfNotSet()
101 -
					->children()
102 -
						->arrayNode(self::PARAMETER_COLLAPSE_PATHS)
103 -
							->info('Add paths which should be collapsed (for external/compiled code) so that actual error is expanded.')
104 -
							->prototype('scalar')
105 -
								->end()
106 -
							->defaultValue([
107 -
								$this->kernelRootDir . '/bootstrap.php.cache',
108 -
								$this->kernelCacheDir,
109 -
							])
110 -
							->end()
111 -
						->end()
112 -
					->end()
113 -
				->end()
114 -
			->end();
49 +
    public function getConfigTreeBuilder() : TreeBuilder
50 +
    {
51 +
        $treeBuilder = new TreeBuilder($this->alias);
52 +
        $rootNode = $treeBuilder->getRootNode();
53 +
        assert($rootNode instanceof ArrayNodeDefinition);
115 54
116 -
		return $treeBuilder;
117 -
	}
55 +
        $rootNode
56 +
            ->children()
57 +
                ->arrayNode(self::SECTION_CONTROLLER)
58 +
                    ->addDefaultsIfNotSet()
59 +
                    ->children()
60 +
                        ->scalarNode(self::PARAMETER_CONTROLLER_ENABLED)
61 +
                            ->info('Enable debug screen for controllers.')
62 +
                            ->defaultNull()
63 +
                            ->end()
64 +
                        ->integerNode(self::PARAMETER_CONTROLLER_LISTENER_PRIORITY)
65 +
                            ->info('Priority with which the listener will be registered.')
66 +
                            ->defaultValue(0)
67 +
                            ->end()
68 +
                        ->end()
69 +
                    ->end()
70 +
                ->arrayNode(self::SECTION_CONSOLE)
71 +
                    ->addDefaultsIfNotSet()
72 +
                    ->children()
73 +
                        ->scalarNode(self::PARAMETER_CONSOLE_ENABLED)
74 +
                            ->info('Enable debug screen for console.')
75 +
                            ->defaultNull()
76 +
                            ->end()
77 +
                        ->scalarNode(self::PARAMETER_CONSOLE_LOG_DIRECTORY)
78 +
                            ->info(
79 +
                                'Directory, where BlueScreens for console will be stored.'
80 +
                                . ' If you are already using Tracy for logging, set this to the same.'
81 +
                                . sprintf(
82 +
                                    ' This will be only used, if given %s instance does not have a directory set.',
83 +
                                    TracyLogger::class
84 +
                                )
85 +
                            )
86 +
                            ->defaultValue($this->kernelLogsDir)
87 +
                            ->end()
88 +
                        ->scalarNode(self::PARAMETER_CONSOLE_BROWSER)
89 +
                            ->info(
90 +
                                'Configure this to open generated BlueScreen in your browser.'
91 +
                                . ' Configuration option may be for example \'google-chrome\' or \'firefox\''
92 +
                                . ' and it will be invoked as a shell command.'
93 +
                            )
94 +
                            ->defaultNull()
95 +
                            ->end()
96 +
                        ->integerNode(self::PARAMETER_CONSOLE_LISTENER_PRIORITY)
97 +
                            ->info('Priority with which the listener will be registered.')
98 +
                            ->defaultValue(0)
99 +
                            ->end()
100 +
                        ->end()
101 +
                    ->end()
102 +
                ->arrayNode(self::SECTION_BLUE_SCREEN)
103 +
                    ->addDefaultsIfNotSet()
104 +
                    ->children()
105 +
                        ->arrayNode(self::PARAMETER_COLLAPSE_PATHS)
106 +
                            //phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
107 +
                            ->info('Add paths which should be collapsed (for external/compiled code) so that actual error is expanded.')
108 +
                            ->prototype('scalar')
109 +
                                ->end()
110 +
                            ->defaultValue([
111 +
                                $this->kernelRootDir . '/bootstrap.php.cache',
112 +
                                $this->kernelCacheDir,
113 +
                            ])
114 +
                            ->end()
115 +
                        ->end()
116 +
                    ->end()
117 +
                ->end()
118 +
            ->end();
118 119
120 +
        return $treeBuilder;
121 +
    }
119 122
}
Files Coverage
src 92.31%
Project Totals (6 files) 92.31%
Notifications are pending CI completion. Waiting for GitHub's status webhook to queue notifications. Push notifications now.

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading