Browse code

removed obsolete code

Fabien Potencier authored on 17/10/2016 20:59:54
Showing 8 changed files
... ...
@@ -46,10 +46,6 @@ You can manually convert a source code into a token stream by calling the
46 46
 
47 47
     $stream = $twig->tokenize(new Twig_Source($source, $identifier));
48 48
 
49
-.. versionadded:: 1.27
50
-    ``Twig_Source`` was introduced in version 1.27, pass the source and the
51
-    identifier directly on previous versions.
52
-
53 49
 As the stream has a ``__toString()`` method, you can have a textual
54 50
 representation of it by echoing the object::
55 51
 
... ...
@@ -323,10 +323,6 @@ If you iterate over a set of files, you can pass the filename to the
323 323
         }
324 324
     }
325 325
 
326
-.. versionadded:: 1.27
327
-    ``Twig_Source`` was introduced in version 1.27, pass the source and the
328
-    identifier directly on previous versions.
329
-
330 326
 .. note::
331 327
 
332 328
     This method won't catch any sandbox policy violations because the policy
... ...
@@ -443,20 +443,12 @@ class Twig_Environment
443 443
     /**
444 444
      * Tokenizes a source code.
445 445
      *
446
-     * @param string|Twig_Source $source The template source code
447
-     * @param string             $name   The template name (deprecated)
448
-     *
449 446
      * @return Twig_TokenStream A Twig_TokenStream instance
450 447
      *
451 448
      * @throws Twig_Error_Syntax When the code is syntactically wrong
452 449
      */
453
-    public function tokenize($source, $name = null)
450
+    public function tokenize(Twig_Source $source)
454 451
     {
455
-        if (!$source instanceof Twig_Source) {
456
-            @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
457
-            $source = new Twig_Source($source, $name);
458
-        }
459
-
460 452
         if (null === $this->lexer) {
461 453
             $this->lexer = new Twig_Lexer($this);
462 454
         }
... ...
@@ -521,20 +513,12 @@ class Twig_Environment
521 513
     /**
522 514
      * Compiles a template source code.
523 515
      *
524
-     * @param string|Twig_Source $source The template source code
525
-     * @param string             $name   The template name (deprecated)
526
-     *
527 516
      * @return string The compiled PHP source code
528 517
      *
529 518
      * @throws Twig_Error_Syntax When there was an error during tokenizing, parsing or compiling
530 519
      */
531
-    public function compileSource($source, $name = null)
520
+    public function compileSource(Twig_Source $source)
532 521
     {
533
-        if (!$source instanceof Twig_Source) {
534
-            @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
535
-            $source = new Twig_Source($source, $name);
536
-        }
537
-
538 522
         try {
539 523
             return $this->compile($this->parse($this->tokenize($source)));
540 524
         } catch (Twig_Error $e) {
... ...
@@ -26,8 +26,7 @@ class Twig_Lexer
26 26
     private $states;
27 27
     private $brackets;
28 28
     private $env;
29
-    // to be renamed to $name in 2.0 (where it is private)
30
-    private $filename;
29
+    private $name;
31 30
     private $options;
32 31
     private $regexes;
33 32
     private $position;
... ...
@@ -88,7 +87,7 @@ class Twig_Lexer
88 87
         }
89 88
 
90 89
         $this->code = str_replace(array("\r\n", "\r"), "\n", $source->getCode());
91
-        $this->filename = $source->getName();
90
+        $this->name = $source->getName();
92 91
         $this->cursor = 0;
93 92
         $this->lineno = 1;
94 93
         $this->end = strlen($this->code);
... ...
@@ -132,7 +131,7 @@ class Twig_Lexer
132 131
 
133 132
         if (!empty($this->brackets)) {
134 133
             list($expect, $lineno) = array_pop($this->brackets);
135
-            throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->filename);
134
+            throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->name);
136 135
         }
137 136
 
138 137
         if ($mbEncoding) {
... ...
@@ -227,7 +226,7 @@ class Twig_Lexer
227 226
             $this->moveCursor($match[0]);
228 227
 
229 228
             if ($this->cursor >= $this->end) {
230
-                throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $this->state === self::STATE_BLOCK ? 'block' : 'variable'), $this->currentVarBlockLine, $this->filename);
229
+                throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $this->state === self::STATE_BLOCK ? 'block' : 'variable'), $this->currentVarBlockLine, $this->name);
231 230
             }
232 231
         }
233 232
 
... ...
@@ -259,12 +258,12 @@ class Twig_Lexer
259 258
             // closing bracket
260 259
             elseif (false !== strpos(')]}', $this->code[$this->cursor])) {
261 260
                 if (empty($this->brackets)) {
262
-                    throw new Twig_Error_Syntax(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->filename);
261
+                    throw new Twig_Error_Syntax(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->name);
263 262
                 }
264 263
 
265 264
                 list($expect, $lineno) = array_pop($this->brackets);
266 265
                 if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) {
267
-                    throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->filename);
266
+                    throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->name);
268 267
                 }
269 268
             }
270 269
 
... ...
@@ -284,14 +283,14 @@ class Twig_Lexer
284 283
         }
285 284
         // unlexable
286 285
         else {
287
-            throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->filename);
286
+            throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->name);
288 287
         }
289 288
     }
290 289
 
291 290
     private function lexRawData()
292 291
     {
293 292
         if (!preg_match($this->regexes['lex_raw_data'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
294
-            throw new Twig_Error_Syntax('Unexpected end of file: Unclosed "verbatim" block.', $this->lineno, $this->filename);
293
+            throw new Twig_Error_Syntax('Unexpected end of file: Unclosed "verbatim" block.', $this->lineno, $this->name);
295 294
         }
296 295
 
297 296
         $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor);
... ...
@@ -307,7 +306,7 @@ class Twig_Lexer
307 306
     private function lexComment()
308 307
     {
309 308
         if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
310
-            throw new Twig_Error_Syntax('Unclosed comment.', $this->lineno, $this->filename);
309
+            throw new Twig_Error_Syntax('Unclosed comment.', $this->lineno, $this->name);
311 310
         }
312 311
 
313 312
         $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]);
... ...
@@ -326,7 +325,7 @@ class Twig_Lexer
326 325
         } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
327 326
             list($expect, $lineno) = array_pop($this->brackets);
328 327
             if ($this->code[$this->cursor] != '"') {
329
-                throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->filename);
328
+                throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->name);
330 329
             }
331 330
 
332 331
             $this->popState();
... ...
@@ -21,15 +21,8 @@
21 21
  */
22 22
 class Twig_Node_Module extends Twig_Node
23 23
 {
24
-    public function __construct(Twig_Node $body, Twig_Node_Expression $parent = null, Twig_Node $blocks, Twig_Node $macros, Twig_Node $traits, $embeddedTemplates, $name, $source = '')
24
+    public function __construct(Twig_Node $body, Twig_Node_Expression $parent = null, Twig_Node $blocks, Twig_Node $macros, Twig_Node $traits, $embeddedTemplates, Twig_Source $source)
25 25
     {
26
-        if (!$name instanceof Twig_Source) {
27
-            @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
28
-            $source = new Twig_Source($source, $name);
29
-        } else {
30
-            $source = $name;
31
-        }
32
-
33 26
         $nodes = array(
34 27
             'body' => $body,
35 28
             'blocks' => $blocks,
... ...
@@ -19,32 +19,18 @@ class Twig_TokenStream
19 19
 {
20 20
     private $tokens;
21 21
     private $current = 0;
22
-    private $filename;
23
-
24 22
     private $source;
25 23
 
26 24
     /**
27 25
      * Constructor.
28 26
      *
29 27
      * @param array       $tokens An array of tokens
30
-     * @param string|null $name   The name of the template which tokens are associated with
31
-     * @param string|null $source The source code associated with the tokens
28
+     * @param Twig_Source $source
32 29
      */
33
-    public function __construct(array $tokens, $name = null, $source = null)
30
+    public function __construct(array $tokens, Twig_Source $source = null)
34 31
     {
35
-        if (!$name instanceof Twig_Source) {
36
-            if (null !== $name || null !== $source) {
37
-                @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
38
-            }
39
-            $this->source = new Twig_Source($source, $name);
40
-        } else {
41
-            $this->source = $name;
42
-        }
43
-
44 32
         $this->tokens = $tokens;
45
-
46
-        // deprecated, not used anymore, to be removed in 2.0
47
-        $this->filename = $this->source->getName();
33
+        $this->source = $source ?: new Twig_Source('');
48 34
     }
49 35
 
50 36
     /**
... ...
@@ -158,36 +144,6 @@ class Twig_TokenStream
158 144
     }
159 145
 
160 146
     /**
161
-     * Gets the name associated with this stream (null if not defined).
162
-     *
163
-     * @return string|null
164
-     *
165
-     * @deprecated since 1.27 (to be removed in 2.0)
166
-     */
167
-    public function getFilename()
168
-    {
169
-        @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
170
-
171
-        return $this->source->getName();
172
-    }
173
-
174
-    /**
175
-     * Gets the source code associated with this stream.
176
-     *
177
-     * @return string
178
-     *
179
-     * @internal Don't use this as it might be empty depending on the environment configuration
180
-     *
181
-     * @deprecated since 1.27 (to be removed in 2.0)
182
-     */
183
-    public function getSource()
184
-    {
185
-        @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED);
186
-
187
-        return $this->source->getCode();
188
-    }
189
-
190
-    /**
191 147
      * Gets the source associated with this stream.
192 148
      *
193 149
      * @return Twig_Source
... ...
@@ -10,17 +10,6 @@
10 10
  */
11 11
 class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
12 12
 {
13
-    /**
14
-     * @group legacy
15
-     */
16
-    public function testLegacyConstructorSignature()
17
-    {
18
-        $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
19
-        $stream = $lexer->tokenize('{{ foo }}', 'foo');
20
-        $this->assertEquals('foo', $stream->getFilename());
21
-        $this->assertEquals('{{ foo }}', $stream->getSource());
22
-    }
23
-
24 13
     public function testNameLabelForTag()
25 14
     {
26 15
         $template = '{% ยง %}';
... ...
@@ -27,18 +27,6 @@ class Twig_Tests_TokenStreamTest extends PHPUnit_Framework_TestCase
27 27
         );
28 28
     }
29 29
 
30
-    /**
31
-     * @group legacy
32
-     */
33
-    public function testLegacyConstructorSignature()
34
-    {
35
-        $stream = new Twig_TokenStream(array(), 'foo', '{{ foo }}');
36
-        $this->assertEquals('foo', $stream->getFilename());
37
-        $this->assertEquals('{{ foo }}', $stream->getSource());
38
-        $this->assertEquals('foo', $stream->getSourceContext()->getName());
39
-        $this->assertEquals('{{ foo }}', $stream->getSourceContext()->getCode());
40
-    }
41
-
42 30
     public function testNext()
43 31
     {
44 32
         $stream = new Twig_TokenStream(self::$tokens);