From c77309a21b2f45573ec91ffccc0c6a0fbc346c37 Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Tue, 26 Mar 2019 10:21:03 -0400 Subject: [PATCH 1/4] Update to `Twig` namespace classes --- Assetic/TwigFormulaLoader.php | 8 +++++--- Tests/Assetic/TwigFormulaLoaderTest.php | 6 +++--- Tests/Twig/Loader/FilesystemLoaderTest.php | 2 +- Twig/Loader/FilesystemLoader.php | 12 +++++++----- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Assetic/TwigFormulaLoader.php b/Assetic/TwigFormulaLoader.php index b8a2466..774e2da 100644 --- a/Assetic/TwigFormulaLoader.php +++ b/Assetic/TwigFormulaLoader.php @@ -15,6 +15,8 @@ use Psr\Log\LoggerInterface; use Liip\ThemeBundle\ActiveTheme; use Assetic\Extension\Twig\TwigFormulaLoader as BaseTwigFormulaLoader; +use Twig\Environment as TwigEnvironment; +use Twig\Source as TwigSource; /** * Extends the base twig formula loader but iterates over all the @@ -32,7 +34,7 @@ class TwigFormulaLoader extends BaseTwigFormulaLoader private $logger; public function __construct( - \Twig_Environment $twig, + TwigEnvironment $twig, LoggerInterface $logger = null, ActiveTheme $activeTheme = null ) { @@ -58,8 +60,8 @@ public function load(ResourceInterface $resource) try { // determine if the template has any errors - if (class_exists('Twig_Source')) { - $content = new \Twig_Source($resource->getContent(), (string) $resource->getContent()); + if (class_exists(TwigSource::class)) { + $content = new TwigSource($resource->getContent(), (string) $resource->getContent()); } else { $content = $resource->getContent(); } diff --git a/Tests/Assetic/TwigFormulaLoaderTest.php b/Tests/Assetic/TwigFormulaLoaderTest.php index 5ba12bd..c55b419 100644 --- a/Tests/Assetic/TwigFormulaLoaderTest.php +++ b/Tests/Assetic/TwigFormulaLoaderTest.php @@ -52,7 +52,7 @@ public function setUp() $this->markTestSkipped('Assetic not supported'); } - $this->twig = $this->prophesize('Twig_Environment'); + $this->twig = $this->prophesize(\Twig\Environment::class); $this->activeTheme = $this->prophesize('Liip\ThemeBundle\ActiveTheme'); $this->logger = $this->prophesize('Psr\Log\LoggerInterface'); $this->resource = $this->prophesize('Assetic\Factory\Resource\ResourceInterface'); @@ -78,8 +78,8 @@ public function testLoader() $this->activeTheme->setName('theme1')->shouldBeCalledTimes(2); $this->activeTheme->setName('theme2')->shouldBeCalled(); - $this->twig->tokenize(Argument::any(), Argument::any())->shouldBeCalled()->willReturn(new \Twig_TokenStream(array())); - $this->twig->parse(Argument::any())->shouldBeCalled()->willReturn(new \Twig_Node); + $this->twig->tokenize(Argument::any(), Argument::any())->shouldBeCalled()->willReturn(new \Twig\TokenStream(array())); + $this->twig->parse(Argument::any())->shouldBeCalled()->willReturn(new \Twig\Node\Node); $this->loader->load($this->resource->reveal()); } diff --git a/Tests/Twig/Loader/FilesystemLoaderTest.php b/Tests/Twig/Loader/FilesystemLoaderTest.php index 4c7324a..72bf17c 100644 --- a/Tests/Twig/Loader/FilesystemLoaderTest.php +++ b/Tests/Twig/Loader/FilesystemLoaderTest.php @@ -47,7 +47,7 @@ public function testGetSourceContextWithFallback() } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testTwigErrorIfLocatorThrowsInvalid() { diff --git a/Twig/Loader/FilesystemLoader.php b/Twig/Loader/FilesystemLoader.php index df294c5..8c994dc 100644 --- a/Twig/Loader/FilesystemLoader.php +++ b/Twig/Loader/FilesystemLoader.php @@ -6,8 +6,10 @@ use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\Templating\TemplateReferenceInterface; use Liip\ThemeBundle\ActiveTheme; +use Twig\Error\LoaderError as TwigLoaderError; +use Twig\Loader\FilesystemLoader as TwigFilesystemLoader; -class FilesystemLoader extends \Twig_Loader_Filesystem +class FilesystemLoader extends TwigFilesystemLoader { protected $locator; protected $parser; @@ -52,11 +54,11 @@ public function setActiveTheme(ActiveTheme $activeTheme = null) * Otherwise the template is located using the locator from the twig library. * * @param string|TemplateReferenceInterface $template The template - * @param bool $throw When true, a \Twig_Error_Loader exception will be thrown if a template could not be found + * @param bool $throw When true, a \Twig\Error\LoaderError exception will be thrown if a template could not be found * * @return string The path to the template file * - * @throws \Twig_Error_Loader if the template could not be found + * @throws \Twig\Error\LoaderError if the template could not be found */ protected function findTemplate($template, $throw = true) { @@ -82,14 +84,14 @@ protected function findTemplate($template, $throw = true) // for BC try { $file = parent::findTemplate((string) $template); - } catch (\Twig_Error_Loader $e) { + } catch (TwigLoaderError $e) { $previous = $e; } } if (false === $file || null === $file) { if ($throw) { - throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous); + throw new TwigLoaderError(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous); } return false; From 6095f3d2a71b74516789819a66f8635e3cc86ac3 Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Tue, 26 Mar 2019 10:21:44 -0400 Subject: [PATCH 2/4] Remove support for SF2.7, PHP5 and Twig < 2.7 --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index c914e70..bf5cfc3 100644 --- a/composer.json +++ b/composer.json @@ -15,18 +15,18 @@ } ], "require": { - "php": "^5.3.9|^7.0", - "symfony/framework-bundle": "^2.7|^3.0|^4.0", - "symfony/finder": "^2.7|^3.0|^4.0", - "symfony/twig-bundle": "^2.7|^3.0|^4.0", - "symfony/templating": "^2.7|^3.0|^4.0", - "twig/twig": "^1.27|^2.0", + "php": "^7.0", + "symfony/framework-bundle": "^3.0|^4.0", + "symfony/finder": "^3.0|^4.0", + "symfony/twig-bundle": "^3.0|^4.0", + "symfony/templating": "^3.0|^4.0", + "twig/twig": ">=2.7", "psr/log": "~1.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35|^6.0", - "symfony/console": "^2.7|^3.0|^4.0", - "symfony/expression-language": "^2.7|^3.0|^4.0" + "phpunit/phpunit": "^6.0", + "symfony/console": "^3.0|^4.0", + "symfony/expression-language": "^3.0|^4.0" }, "autoload": { "psr-4": { "Liip\\ThemeBundle\\": "" } From ee1ec1826aa3ab7fc596b217704283a900feec5d Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Tue, 26 Mar 2019 10:46:55 -0400 Subject: [PATCH 3/4] Updating travis configuration, drop PHP5.6 support, add test for PHP7.3 --- .travis.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index bbd264d..386e31c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: php php: - - 5.6 - 7.0 - 7.1 - 7.2 + - 7.3 sudo: false @@ -13,13 +13,11 @@ cache: - $HOME/.composer/cache/files env: - - SYMFONY_VERSION=2.7.* + - SYMFONY_VERSION=3.0.* matrix: fast_finish: true include: - - php: 7.2 - env: SYMFONY_VERSION=2.8.* - php: 7.2 env: SYMFONY_VERSION=3.3.* - php: 7.2 @@ -30,10 +28,18 @@ matrix: env: SYMFONY_VERSION=4.1.*;ASSETIC=skip - php: 7.2 env: SYMFONY_VERSION=@dev;ASSETIC=skip + - php: 7.3 + env: SYMFONY_VERSION=3.3.* + - php: 7.3 + env: SYMFONY_VERSION=3.4.* + - php: 7.3 + env: SYMFONY_VERSION=4.0.*;ASSETIC=skip + - php: 7.3 + env: SYMFONY_VERSION=4.1.*;ASSETIC=skip + - php: 7.3 + env: SYMFONY_VERSION=@dev;ASSETIC=skip - php: 7.0 - env: TWIG_VERSION=2.x - - php: 5.6 - env: COMPOSER_FLAGS="--prefer-lowest" + env: TWIG_VERSION=2.7.* - php: 7.1 env: DEPENDENCIES=beta allow_failures: @@ -41,8 +47,6 @@ matrix: env: SYMFONY_VERSION=@dev;ASSETIC=skip before_install: - - if [[ $TRAVIS_PHP_VERSION = '5.6' ]]; then phpenv config-add travis.php.ini; fi - - if [[ $TRAVIS_PHP_VERSION != '7.0' && $TRAVIS_PHP_VERSION != '7.1' && $TRAVIS_PHP_VERSION != '7.2' ]]; then phpenv config-rm xdebug.ini; fi - composer self-update - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; - if [ "$ASSETIC" != "skip" ]; then composer require "kriswallsmith/assetic:^1.1" --no-update; fi; From b764a653b9381a6f3ff6b45cb9216eae197d4c87 Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Thu, 4 Apr 2019 12:49:27 -0400 Subject: [PATCH 4/4] Update supported versions fo `twig/twig`, 1.34+ | 2.4+ --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bf5cfc3..fbe6fca 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "symfony/finder": "^3.0|^4.0", "symfony/twig-bundle": "^3.0|^4.0", "symfony/templating": "^3.0|^4.0", - "twig/twig": ">=2.7", + "twig/twig": "^1.34|^2.4", "psr/log": "~1.0" }, "require-dev": {