From 1085343f53a96ea64061ad8e8ce524f3213db169 Mon Sep 17 00:00:00 2001 From: sjoulbak Date: Thu, 11 Jun 2020 15:21:36 +0200 Subject: [PATCH 1/3] Added Twig 3 support --- README.md | 3 ++- composer.json | 2 +- src/InlineCssExtension.php | 7 ++++--- src/InlineCssNode.php | 8 ++++---- src/InlineCssParser.php | 16 ++++++++-------- tests/IntegrationTest.php | 4 +++- tests/fixtures/basic.test | 2 +- tests/fixtures/filenotfound.test | 2 +- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ce854fe..d9378f6 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,9 @@ Add the extension to the `Twig_Environment`: ```php use NerdsAndCompany\CssToInlineStyles\Twig\InlineCssExtension; +use Twig\Environment; -$twig = new Twig_Environment(...); +$twig = new Environment(...); $twig->addExtension(new InlineCssExtension()); ``` diff --git a/composer.json b/composer.json index 6c010fd..a74f078 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "require": { "php": ">=5.3.3", - "twig/twig": ">=1.0", + "twig/twig": ">=3.0", "tijsverkoyen/css-to-inline-styles": "^2.0" }, "require-dev": { diff --git a/src/InlineCssExtension.php b/src/InlineCssExtension.php index c225f4d..2d76d41 100644 --- a/src/InlineCssExtension.php +++ b/src/InlineCssExtension.php @@ -2,7 +2,8 @@ namespace NerdsAndCompany\CssToInlineStyles\Twig; -use Twig_Extension; +use Twig\Extension\AbstractExtension; +use Twig\Extension\GlobalsInterface; use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles; /** @@ -14,7 +15,7 @@ * * @see http://www.nerds.company */ -class InlineCssExtension extends Twig_Extension implements \Twig_Extension_GlobalsInterface +class InlineCssExtension extends AbstractExtension implements GlobalsInterface { /** * {@inheritdoc} @@ -27,7 +28,7 @@ public function getTokenParsers() /** * {@inheritdoc} */ - public function getGlobals() + public function getGlobals(): array { return ['inlinecss' => new CssToInlineStyles()]; } diff --git a/src/InlineCssNode.php b/src/InlineCssNode.php index 125d36d..c404ec2 100644 --- a/src/InlineCssNode.php +++ b/src/InlineCssNode.php @@ -2,8 +2,8 @@ namespace NerdsAndCompany\CssToInlineStyles\Twig; -use Twig_Compiler; -use Twig_Node; +use Twig\Compiler; +use Twig\Node\Node; /** * Inline css node adds coversion of css to inline style for given node. @@ -14,12 +14,12 @@ * * @see http://www.nerds.company */ -class InlineCssNode extends Twig_Node +class InlineCssNode extends Node { /** * {@inheritdoc} */ - public function compile(Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->addDebugInfo($this) ->write('$cssPath = ') diff --git a/src/InlineCssParser.php b/src/InlineCssParser.php index 3ade5a6..ac501ab 100644 --- a/src/InlineCssParser.php +++ b/src/InlineCssParser.php @@ -2,8 +2,8 @@ namespace NerdsAndCompany\CssToInlineStyles\Twig; -use Twig_TokenParser; -use Twig_Token; +use Twig\TokenParser\AbstractTokenParser; +use Twig\Token; /** * Parses twig node between inlinecss and endinlinecss. @@ -14,20 +14,20 @@ * * @see http://www.nerds.company */ -class InlineCssParser extends Twig_TokenParser +class InlineCssParser extends AbstractTokenParser { /** * {@inheritdoc} */ - public function parse(Twig_Token $token) + public function parse(Token $token) { $lineNo = $token->getLine(); $stream = $this->parser->getStream(); $path = $this->parser->getExpressionParser()->parseMultitargetExpression(); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse(array($this, 'decideEnd'), true); - $stream->expect(Twig_Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); return new InlineCssNode(['body' => $body], ['css' => $path], $lineNo, $this->getTag()); } @@ -43,9 +43,9 @@ public function getTag() /** * Node ends when endinlinecss tag has been reached. * - * @param Twig_Token $token + * @param Token $token */ - public function decideEnd(Twig_Token $token) + public function decideEnd(Token $token) { return $token->test('endinlinecss'); } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 8058dab..74fb7e1 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -2,6 +2,8 @@ namespace NerdsAndCompany\CssToInlineStyles\Twig; +use Twig\Test\IntegrationTestCase; + /** * Inline Css extension integration test. * @@ -11,7 +13,7 @@ * * @see http://www.nerds.company */ -class InlineCssIntegrationTest extends \Twig_Test_IntegrationTestCase +class InlineCssIntegrationTest extends IntegrationTestCase { /** * {@inheritdoc} diff --git a/tests/fixtures/basic.test b/tests/fixtures/basic.test index fa38596..b4cbb61 100644 --- a/tests/fixtures/basic.test +++ b/tests/fixtures/basic.test @@ -5,7 +5,7 @@

Hello World

{% endinlinecss %} --DATA-- -return array('cssPath' => __DIR__.'/../../../../../../tests/fixtures/test.css') +return array('cssPath' => __DIR__.'/../../../../../tests/fixtures/test.css') --EXPECT--

Hello World

diff --git a/tests/fixtures/filenotfound.test b/tests/fixtures/filenotfound.test index da285fc..6fe2bde 100644 --- a/tests/fixtures/filenotfound.test +++ b/tests/fixtures/filenotfound.test @@ -7,4 +7,4 @@ --DATA-- return array('cssPath' => 'notfound.css') --EXPECT-- -Twig_Error: Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Given file could not be found: notfound.css") in "index.twig" at line 2 in "filenotfound.test". +Twig\Error\Error: Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template ("Given file could not be found: notfound.css") in "index.twig" at line 2. From 20e60340710ef21e088e628c241f63edbbf03e53 Mon Sep 17 00:00:00 2001 From: sjoulbak Date: Thu, 11 Jun 2020 15:28:32 +0200 Subject: [PATCH 2/3] Updated minimum PHP version to 7.2.5 --- .travis.yml | 8 +++----- composer.json | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 244ba75..7997700 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,8 @@ language: php php: - - '5.4' - - '5.5' - - '5.6' - - '7.0' - - '7.1' + - '7.2' + - '7.3' + - '7.4' - hhvm - nightly install: diff --git a/composer.json b/composer.json index a74f078..9984439 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": ">=5.3.3", + "php": ">=7.2.5", "twig/twig": ">=3.0", "tijsverkoyen/css-to-inline-styles": "^2.0" }, From c8a8b9872bd2ae1452f09603c47b6f025a3b233f Mon Sep 17 00:00:00 2001 From: sjoulbak Date: Thu, 11 Jun 2020 15:42:01 +0200 Subject: [PATCH 3/3] Removed nightly and hhvm --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7997700..edc3cf1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,6 @@ php: - '7.2' - '7.3' - '7.4' - - hhvm - - nightly install: - composer install script: ./vendor/bin/phpunit