diff --git a/.travis.yml b/.travis.yml index 41e173f..216afb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: php php: - - '7.0' - - '7.1' - '7.2' - '7.3' - '7.4' diff --git a/CHANGELOG.md b/CHANGELOG.md index 46eee7f..3938d59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +3.0.0 +------ + +- Update to Twig 3.x + 2.0.0 ------ diff --git a/ETwigViewRenderer.php b/ETwigViewRenderer.php index 2240845..585e692 100644 --- a/ETwigViewRenderer.php +++ b/ETwigViewRenderer.php @@ -8,7 +8,7 @@ * @link https://github.com/vintagesucks/twig-renderer * @link https://twig.symfony.com/ * - * @version 2.0.0 + * @version 3.0.0 */ class ETwigViewRenderer extends CApplicationComponent implements IViewRenderer { @@ -22,7 +22,7 @@ class ETwigViewRenderer extends CApplicationComponent implements IViewRenderer public $fileExtension = '.twig'; /** * @var array Twig environment options - * @see https://twig.symfony.com/doc/2.x/api.html#environment-options + * @see https://twig.symfony.com/doc/3.x/api.html#environment-options */ public $options = array(); /** @@ -53,7 +53,7 @@ class ETwigViewRenderer extends CApplicationComponent implements IViewRenderer public $extensions = array(); /** * @var array Twig lexer options - * @see https://twig.symfony.com/doc/2.x/recipes.html#customizing-the-syntax + * @see https://twig.symfony.com/doc/3.x/recipes.html#customizing-the-syntax * Example: Smarty-like syntax * array( * 'tag_comment' => array('{*', '*}'), @@ -81,7 +81,7 @@ function init() $this->_paths[] = $app->getBasePath(); - $loader = new Twig_Loader_Filesystem($this->_paths); + $loader = new \Twig\Loader\FilesystemLoader($this->_paths); $defaultOptions = array( 'autoescape' => false, // false because other way Twig escapes all HTML in templates @@ -89,7 +89,7 @@ function init() 'cache' => $app->getRuntimePath() . '/twig_cache/', 'charset' => $app->charset, ); - $this->_twig = new Twig_Environment($loader, array_merge($defaultOptions, $this->options)); + $this->_twig = new \Twig\Environment($loader, array_merge($defaultOptions, $this->options)); // Adding Yii::app() object to globals $this->_twig->addGlobal('App', $app); @@ -99,7 +99,7 @@ function init() // Adding global 'void' function (usage: {{void(App.clientScript.registerScriptFile(...))}}) // (@see ETwigViewRendererVoidFunction below for details) - $this->_twig->addFunction(new Twig_SimpleFunction('void', 'ETwigViewRendererVoidFunction')); + $this->_twig->addFunction(new \Twig\TwigFunction('void', 'ETwigViewRendererVoidFunction')); // Adding custom globals (objects or static classes) if (!empty($this->globals)) { @@ -147,7 +147,7 @@ public function renderFile($context, $sourceFile, $data, $return) break; } } - $template = $this->_twig->loadTemplate($sourceFile)->render($data); + $template = $this->_twig->render($sourceFile, $data); if ($return) { return $template; diff --git a/README.md b/README.md index 215bbb6..5905464 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ [![Build](https://api.travis-ci.com/vintagesucks/twig-renderer.svg?branch=master)](https://travis-ci.com/vintagesucks/twig-renderer) [![Packagist](https://img.shields.io/packagist/v/vintagesucks/twig-renderer.svg)](https://packagist.org/packages/vintagesucks/twig-renderer) [![Packagist](https://img.shields.io/packagist/dt/vintagesucks/twig-renderer.svg)](https://packagist.org/packages/vintagesucks/twig-renderer) -This extension allows you to use [Twig 2.x](https://twig.symfony.com/) templates in Yii 1 +This extension allows you to use [Twig 3.x](https://twig.symfony.com/) templates in Yii 1 ## Requirements * Yii 1.1 or above -* PHP 7.0 or above +* PHP 7.2 or above ## Installing diff --git a/composer.json b/composer.json index 77d27a9..9953099 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "twig/twig": "^2.10.0" + "twig/twig": "^3.0.3" }, "require-dev": { "yiisoft/yii": "^1.1" diff --git a/test/protected/config/twig.php b/test/protected/config/twig.php index 9f6c2de..9453fd8 100644 --- a/test/protected/config/twig.php +++ b/test/protected/config/twig.php @@ -1,6 +1,7 @@ 'WORLD', 'components' => [ 'viewRenderer' => [ 'class' => 'root.vendor.vintagesucks.twig-renderer.ETwigViewRenderer', diff --git a/test/protected/controllers/SiteController.php b/test/protected/controllers/SiteController.php index 28179a9..3d906dd 100644 --- a/test/protected/controllers/SiteController.php +++ b/test/protected/controllers/SiteController.php @@ -4,6 +4,6 @@ class SiteController extends CController { public function actionIndex() { - $this->render('hello-world'); + $this->render('hello-world', ['test' => 'LO']); } } \ No newline at end of file diff --git a/test/protected/views/site/hello-world.twig b/test/protected/views/site/hello-world.twig index 6522817..39a5d49 100644 --- a/test/protected/views/site/hello-world.twig +++ b/test/protected/views/site/hello-world.twig @@ -1 +1 @@ -{{ 'hello world'|upper }} \ No newline at end of file +{{ 'hel'|upper }}{{ test }} {{ App.name }} \ No newline at end of file