Skip to content

Commit

Permalink
Update twig/twig requirement from ^2.10.0 to ^3.0.3 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot-preview[bot] authored Feb 23, 2020
1 parent 28f93bf commit 920f88e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: php

php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
3.0.0
------

- Update to Twig 3.x

2.0.0
------

Expand Down
14 changes: 7 additions & 7 deletions ETwigViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
/**
Expand Down Expand Up @@ -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('{*', '*}'),
Expand Down Expand Up @@ -81,15 +81,15 @@ 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
'auto_reload' => true,
'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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"twig/twig": "^2.10.0"
"twig/twig": "^3.0.3"
},
"require-dev": {
"yiisoft/yii": "^1.1"
Expand Down
1 change: 1 addition & 0 deletions test/protected/config/twig.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [
'name' => 'WORLD',
'components' => [
'viewRenderer' => [
'class' => 'root.vendor.vintagesucks.twig-renderer.ETwigViewRenderer',
Expand Down
2 changes: 1 addition & 1 deletion test/protected/controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class SiteController extends CController
{
public function actionIndex()
{
$this->render('hello-world');
$this->render('hello-world', ['test' => 'LO']);
}
}
2 changes: 1 addition & 1 deletion test/protected/views/site/hello-world.twig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ 'hello world'|upper }}
{{ 'hel'|upper }}{{ test }} {{ App.name }}

0 comments on commit 920f88e

Please sign in to comment.