Browse code

dropped PHP 5.x support

Fabien Potencier authored on 16/12/2016 13:17:23
Showing 8 changed files
... ...
@@ -3,37 +3,31 @@ language: php
3 3
 sudo: false
4 4
 
5 5
 cache:
6
-  directories:
7
-    - vendor
8
-    - $HOME/.composer/cache/files
6
+    directories:
7
+        - vendor
8
+        - $HOME/.composer/cache/files
9 9
 
10 10
 matrix:
11
-  include:
12
-    - php: hhvm-stable
13
-      sudo: required
14
-      dist: trusty
15
-      group: edge
16
-      env: TWIG_EXT=no
17
-    - php: 7.0
18
-      env: TWIG_EXT=no
19
-    - php: 7.1
20
-      env: TWIG_EXT=no
21
-  allow_failures:
22
-    - php: hhvm-stable
23
-      sudo: required
24
-      dist: trusty
25
-      group: edge
26
-      env: TWIG_EXT=no
27
-  fast_finish: true
11
+    include:
12
+        - php: hhvm-stable
13
+          sudo: required
14
+          dist: trusty
15
+          env: TWIG_EXT=no
16
+        - php: 7.0
17
+          env: TWIG_EXT=no
18
+        - php: 7.1
19
+          env: TWIG_EXT=no
20
+    allow_failures:
21
+        - php: hhvm-stable
22
+    fast_finish: true
28 23
 
29 24
 before_install:
30
-  - if [[ ! $TRAVIS_PHP_VERSION = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi
31
-  - if [[ $TRAVIS_PHP_VERSION = hhvm* ]]; then echo hhvm.php7.all=1 >> /etc/hhvm/php.ini; fi
25
+    - if [[ ! $TRAVIS_PHP_VERSION = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi
26
+    - if [[ $TRAVIS_PHP_VERSION = hhvm* ]]; then echo hhvm.php7.all=1 >> /etc/hhvm/php.ini; fi
32 27
 
33 28
 install:
34
-  - travis_retry composer install
29
+    - travis_retry composer install
35 30
 
36 31
 before_script:
37
-  - if [ "$TWIG_EXT" == "yes" ]; then sh -c "cd ext/twig && phpize && ./configure --enable-twig && make && make install"; fi
38
-  - if [ "$TWIG_EXT" == "yes" ]; then echo "extension=twig.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`; fi
39
-
32
+    - if [ "$TWIG_EXT" == "yes" ]; then sh -c "cd ext/twig && phpize && ./configure --enable-twig && make && make install"; fi
33
+    - if [ "$TWIG_EXT" == "yes" ]; then echo "extension=twig.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`; fi
... ...
@@ -12,7 +12,7 @@
12 12
  * removed Twig_Autoloader (use Composer instead)
13 13
  * removed `true` as an equivalent to `html` for the auto-escaping strategy
14 14
  * removed pre-1.8 autoescape tag syntax
15
- * dropped support for PHP 5.2, 5.3, 5.4, and 5.5
15
+ * dropped support for PHP 5.x
16 16
  * removed the ability to register a global variable after the runtime or the extensions have been initialized
17 17
  * improved the performance of the filesystem loader
18 18
  * removed features that were deprecated in 1.x
... ...
@@ -50,4 +50,4 @@
50 50
         }
51 51
     },
52 52
     "minimum-stability": "dev"
53
-}
54 53
\ No newline at end of file
54
+}
... ...
@@ -28,7 +28,7 @@ Slim, Yii, Laravel, Codeigniter and Kohana — just to name a few.
28 28
 Prerequisites
29 29
 -------------
30 30
 
31
-Twig needs at least **PHP 5.6.0** to run.
31
+Twig needs at least **PHP 7.0.0** to run.
32 32
 
33 33
 Installation
34 34
 ------------
... ...
@@ -61,9 +61,6 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
61 61
                     ;
62 62
                 }
63 63
             } else {
64
-                // When Twig will require PHP 7.0, the Template::notFound() method
65
-                // will be removed and the code inlined like this:
66
-                // (function () { throw new Exception(...); })();
67 64
                 $compiler
68 65
                     ->raw('(isset($context[')
69 66
                     ->string($name)
... ...
@@ -71,11 +68,12 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
71 68
                     ->string($name)
72 69
                     ->raw(', $context) ? $context[')
73 70
                     ->string($name)
74
-                    ->raw('] : $this->notFound(')
71
+                    ->raw('] : (function () { throw new Twig_Error_Runtime(\'Variable ')
75 72
                     ->string($name)
76
-                    ->raw(', ')
73
+                    ->raw(' does not exist.\', ')
77 74
                     ->repr($this->lineno)
78
-                    ->raw('))')
75
+                    ->raw(', $this->getSourceContext()); })()')
76
+                    ->raw(')')
79 77
                 ;
80 78
             }
81 79
         }
... ...
@@ -43,14 +43,7 @@ class Twig_Parser
43 43
 
44 44
     public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false)
45 45
     {
46
-        // push all variables into the stack to keep the current state of the parser
47
-        // using get_object_vars() instead of foreach would lead to https://bugs.php.net/71336
48
-        // This hack can be removed when min version if PHP 7.0
49
-        $vars = array();
50
-        foreach ($this as $k => $v) {
51
-            $vars[$k] = $v;
52
-        }
53
-
46
+        $vars = get_object_vars($this);
54 47
         unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']);
55 48
         $this->stack[] = $vars;
56 49
 
... ...
@@ -418,25 +418,6 @@ abstract class Twig_Template
418 418
     abstract protected function doDisplay(array $context, array $blocks = array());
419 419
 
420 420
     /**
421
-     * Throws an exception for an unknown variable.
422
-     *
423
-     * This method is for internal use only and should never be called
424
-     * directly.
425
-     *
426
-     * This is an implementation detail due to a PHP limitation before version 7.0.
427
-     *
428
-     * @return mixed The content of the context variable
429
-     *
430
-     * @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode
431
-     *
432
-     * @internal
433
-     */
434
-    final protected function notFound($name, $line)
435
-    {
436
-        throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist.', $name), $line, $this->getSourceContext());
437
-    }
438
-
439
-    /**
440 421
      * Returns the attribute value for a given array/object.
441 422
      *
442 423
      * @param mixed  $object            The object or array from where to get the item
... ...
@@ -27,7 +27,7 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase
27 27
         $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => true));
28 28
         $env1 = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => false));
29 29
 
30
-        $output = '(isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : $this->notFound("foo", 1))';
30
+        $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()); })())';
31 31
 
32 32
         return array(
33 33
             array($node, "// line 1\n".$output, $env),