diff --git a/.travis.yml b/.travis.yml index 7213a7f8d..1c1148ffe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,37 +3,31 @@ language: php sudo: false cache: - directories: - - vendor - - $HOME/.composer/cache/files + directories: + - vendor + - $HOME/.composer/cache/files matrix: - include: - - php: hhvm-stable - sudo: required - dist: trusty - group: edge - env: TWIG_EXT=no - - php: 7.0 - env: TWIG_EXT=no - - php: 7.1 - env: TWIG_EXT=no - allow_failures: - - php: hhvm-stable - sudo: required - dist: trusty - group: edge - env: TWIG_EXT=no - fast_finish: true + include: + - php: hhvm-stable + sudo: required + dist: trusty + env: TWIG_EXT=no + - php: 7.0 + env: TWIG_EXT=no + - php: 7.1 + env: TWIG_EXT=no + allow_failures: + - php: hhvm-stable + fast_finish: true before_install: - - if [[ ! $TRAVIS_PHP_VERSION = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi - - if [[ $TRAVIS_PHP_VERSION = hhvm* ]]; then echo hhvm.php7.all=1 >> /etc/hhvm/php.ini; fi + - if [[ ! $TRAVIS_PHP_VERSION = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi + - if [[ $TRAVIS_PHP_VERSION = hhvm* ]]; then echo hhvm.php7.all=1 >> /etc/hhvm/php.ini; fi install: - - travis_retry composer install + - travis_retry composer install before_script: - - if [ "$TWIG_EXT" == "yes" ]; then sh -c "cd ext/twig && phpize && ./configure --enable-twig && make && make install"; fi - - if [ "$TWIG_EXT" == "yes" ]; then echo "extension=twig.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`; fi - + - if [ "$TWIG_EXT" == "yes" ]; then sh -c "cd ext/twig && phpize && ./configure --enable-twig && make && make install"; fi + - if [ "$TWIG_EXT" == "yes" ]; then echo "extension=twig.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`; fi diff --git a/CHANGELOG b/CHANGELOG index 56ec90e32..de94a0afe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,7 +12,7 @@ * removed Twig_Autoloader (use Composer instead) * removed `true` as an equivalent to `html` for the auto-escaping strategy * removed pre-1.8 autoescape tag syntax - * dropped support for PHP 5.2, 5.3, 5.4, and 5.5 + * dropped support for PHP 5.x * removed the ability to register a global variable after the runtime or the extensions have been initialized * improved the performance of the filesystem loader * removed features that were deprecated in 1.x diff --git a/composer.json b/composer.json index 87010a06b..f1f40c28f 100644 --- a/composer.json +++ b/composer.json @@ -50,4 +50,4 @@ } }, "minimum-stability": "dev" -} \ No newline at end of file +} diff --git a/doc/intro.rst b/doc/intro.rst index fa3f87d9f..6afde65bb 100644 --- a/doc/intro.rst +++ b/doc/intro.rst @@ -28,7 +28,7 @@ Slim, Yii, Laravel, Codeigniter and Kohana — just to name a few. Prerequisites ------------- -Twig needs at least **PHP 5.6.0** to run. +Twig needs at least **PHP 7.0.0** to run. Installation ------------ diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index f8dc41787..694f9748e 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -61,9 +61,6 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression ; } } else { - // When Twig will require PHP 7.0, the Template::notFound() method - // will be removed and the code inlined like this: - // (function () { throw new Exception(...); })(); $compiler ->raw('(isset($context[') ->string($name) @@ -71,11 +68,12 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression ->string($name) ->raw(', $context) ? $context[') ->string($name) - ->raw('] : $this->notFound(') + ->raw('] : (function () { throw new Twig_Error_Runtime(\'Variable ') ->string($name) - ->raw(', ') + ->raw(' does not exist.\', ') ->repr($this->lineno) - ->raw('))') + ->raw(', $this->getSourceContext()); })()') + ->raw(')') ; } } diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index fb55f03c7..17fdbfb57 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -43,14 +43,7 @@ class Twig_Parser public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false) { - // push all variables into the stack to keep the current state of the parser - // using get_object_vars() instead of foreach would lead to https://bugs.php.net/71336 - // This hack can be removed when min version if PHP 7.0 - $vars = array(); - foreach ($this as $k => $v) { - $vars[$k] = $v; - } - + $vars = get_object_vars($this); unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']); $this->stack[] = $vars; diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 26220159e..b4e98a8b3 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -417,25 +417,6 @@ abstract class Twig_Template */ abstract protected function doDisplay(array $context, array $blocks = array()); - /** - * Throws an exception for an unknown variable. - * - * This method is for internal use only and should never be called - * directly. - * - * This is an implementation detail due to a PHP limitation before version 7.0. - * - * @return mixed The content of the context variable - * - * @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode - * - * @internal - */ - final protected function notFound($name, $line) - { - throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist.', $name), $line, $this->getSourceContext()); - } - /** * Returns the attribute value for a given array/object. * diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php index 9ad16d551..46b3574d1 100644 --- a/test/Twig/Tests/Node/Expression/NameTest.php +++ b/test/Twig/Tests/Node/Expression/NameTest.php @@ -27,7 +27,7 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => true)); $env1 = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => false)); - $output = '(isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : $this->notFound("foo", 1))'; + $output = '(isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : (function () { throw new Twig_Error_Runtime(\'Variable "foo" does not exist.\', 1, $this->getSourceContext()); })())'; return array( array($node, "// line 1\n".$output, $env),