Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twig deprecation notice #196

Merged
merged 4 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

sudo: false

Expand All @@ -13,13 +13,11 @@ cache:
- $HOME/.composer/cache/files

env:
- SYMFONY_VERSION=2.7.*
- SYMFONY_VERSION=3.0.*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.0.* does not make sense, as that's unmaintained. The default should be to not force a Symfony version. And then having some jobs forcing LTS versions


matrix:
fast_finish: true
include:
- php: 7.2
env: SYMFONY_VERSION=2.8.*
- php: 7.2
env: SYMFONY_VERSION=3.3.*
- php: 7.2
Expand All @@ -30,19 +28,25 @@ 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.*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 2.7.* ? That will be unmaintained as soon as Twig 2.8 is released.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the intention is to test the lower bound, but I guess then it should be 2.4

- php: 7.1
env: DEPENDENCIES=beta
allow_failures:
- php: 7.2
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;
Expand Down
8 changes: 5 additions & 3 deletions Assetic/TwigFormulaLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +34,7 @@ class TwigFormulaLoader extends BaseTwigFormulaLoader
private $logger;

public function __construct(
\Twig_Environment $twig,
TwigEnvironment $twig,
LoggerInterface $logger = null,
ActiveTheme $activeTheme = null
) {
Expand All @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/Assetic/TwigFormulaLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Twig/Loader/FilesystemLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testGetSourceContextWithFallback()
}

/**
* @expectedException \Twig_Error_Loader
* @expectedException \Twig\Error\LoaderError
*/
public function testTwigErrorIfLocatorThrowsInvalid()
{
Expand Down
12 changes: 7 additions & 5 deletions Twig/Loader/FilesystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "^1.34|^2.4",
"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\\": "" }
Expand Down