From 5a66e476172b89c1f697fee2bf032acec63065a0 Mon Sep 17 00:00:00 2001 From: Andrey Yatsenco Date: Tue, 28 Jan 2020 11:20:35 +0100 Subject: [PATCH] BB-18735: Symfony 5 compatibility for Twig Inspector extension (#26694) * Allow symfony 5 and twig 3 * Update twig usage to not use internal function * Update collect function based on interface changes * Add backwards compatible fix for symfony 3 * Fix deprecation * BB-18735: Symfony 5 compatibility for Twig Inspector extension - updated minimum required symfony version * Updated dev.locks Co-authored-by: Nate Wiebe --- Bundle/DependencyInjection/Configuration.php | 4 +++- Controller/OpenTemplateController.php | 6 +++--- DataCollector/TwigInspectorCollector.php | 2 +- Twig/HtmlCommentsExtension.php | 2 +- composer.json | 12 ++++++------ 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Bundle/DependencyInjection/Configuration.php b/Bundle/DependencyInjection/Configuration.php index 459acf1..f17e610 100644 --- a/Bundle/DependencyInjection/Configuration.php +++ b/Bundle/DependencyInjection/Configuration.php @@ -16,7 +16,9 @@ class Configuration implements ConfigurationInterface public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('oro_twig_inspector'); - $rootNode = $treeBuilder->getRootNode(); + // BC layer for symfony/config < 4.2 + $rootNode = method_exists($treeBuilder, 'getRootNode') ? + $treeBuilder->getRootNode() : $treeBuilder->root('oro_twig_inspector'); $rootNode ->children() diff --git a/Controller/OpenTemplateController.php b/Controller/OpenTemplateController.php index bd631cd..c2d85b3 100644 --- a/Controller/OpenTemplateController.php +++ b/Controller/OpenTemplateController.php @@ -6,7 +6,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Debug\FileLinkFormatter; use Twig\Environment; -use Twig\Template; +use Twig\TemplateWrapper; /** * Open Twig template in an IDE by template name at the the line @@ -41,8 +41,8 @@ public function __invoke(Request $request, string $template) { $line = $request->query->get('line', 1); - /** @var Template $template */ - $template = $this->twig->loadTemplate($template); + /** @var TemplateWrapper $template */ + $template = $this->twig->load($template); $file = $template->getSourceContext()->getPath(); $url = $this->fileLinkFormatter->format($file, $line); diff --git a/DataCollector/TwigInspectorCollector.php b/DataCollector/TwigInspectorCollector.php index 7b2b625..e03bc3f 100644 --- a/DataCollector/TwigInspectorCollector.php +++ b/DataCollector/TwigInspectorCollector.php @@ -14,7 +14,7 @@ class TwigInspectorCollector implements DataCollectorInterface /** * {@inheritDoc} */ - public function collect(Request $request, Response $response, \Exception $exception = null) + public function collect(Request $request, Response $response, \Throwable $exception = null) { } diff --git a/Twig/HtmlCommentsExtension.php b/Twig/HtmlCommentsExtension.php index d136a2f..207025c 100644 --- a/Twig/HtmlCommentsExtension.php +++ b/Twig/HtmlCommentsExtension.php @@ -67,7 +67,7 @@ public function end(NodeReference $ref): void $content = ob_get_clean(); if ($this->isSupported($content)) { - if (strpos($content, $this->previousContent) !== false) { + if ((string)$this->previousContent !== '' && strpos($content, $this->previousContent) !== false) { if (trim($content) !== trim($this->previousContent)) { $this->boxDrawings->blockChanged($this->nestingLevel); } diff --git a/composer.json b/composer.json index a2d67a5..3e7ddbc 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,12 @@ "psr-4": {"Oro\\TwigInspector\\": ""} }, "require": { - "symfony/config": "^3.4 | ^4.0", - "symfony/dependency-injection": "^3.4 | ^4.0", - "symfony/http-kernel": "^3.4 | ^4.0", - "symfony/http-foundation": "^3.4 | ^4.0", - "symfony/routing": "^3.4 | ^4.0", - "twig/twig": "~1.34|~2.4" + "symfony/config": "^4.1.12 | ^5.0", + "symfony/dependency-injection": "^4.1.12 | ^5.0", + "symfony/http-kernel": "^4.1.12 | ^5.0", + "symfony/http-foundation": "^4.1.12 | ^5.0", + "symfony/routing": "^4.1.12 | ^5.0", + "twig/twig": "^1.34 | ^2.4 | ^3.0" }, "minimum-stability": "dev", "prefer-stable": true,