Skip to content

Commit

Permalink
BB-18735: Symfony 5 compatibility for Twig Inspector extension (#26694)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
anyt and natewiebe13 committed Jan 28, 2020
1 parent 9bee88d commit 5a66e47
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions Controller/OpenTemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion DataCollector/TwigInspectorCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Twig/HtmlCommentsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5a66e47

Please sign in to comment.