Project

General

Profile

« Previous | Next » 

Revision 1852

Added by darkviper over 11 years ago

updated Twig template engine to stable version 1.11.1 step2

View differences:

Compiler.php
25 25
    protected $debugInfo;
26 26
    protected $sourceOffset;
27 27
    protected $sourceLine;
28
    protected $filename;
28 29

  
29 30
    /**
30 31
     * Constructor.
......
37 38
        $this->debugInfo = array();
38 39
    }
39 40

  
41
    public function getFilename()
42
    {
43
        return $this->filename;
44
    }
45

  
40 46
    /**
41 47
     * Returns the environment instance related to this compiler.
42 48
     *
......
70 76
        $this->lastLine = null;
71 77
        $this->source = '';
72 78
        $this->sourceOffset = 0;
73
        $this->sourceLine = 0;
79
        // source code starts at 1 (as we then increment it when we encounter new lines)
80
        $this->sourceLine = 1;
74 81
        $this->indentation = $indentation;
75 82

  
83
        if ($node instanceof Twig_Node_Module) {
84
            $this->filename = $node->getAttribute('filename');
85
        }
86

  
76 87
        $node->compile($this);
77 88

  
78 89
        return $this;
......
92 103
    /**
93 104
     * Adds a raw string to the compiled code.
94 105
     *
95
     * @param  string $string The string
106
     * @param string $string The string
96 107
     *
97 108
     * @return Twig_Compiler The current compiler instance
98 109
     */
......
119 130
        return $this;
120 131
    }
121 132

  
133
    /**
134
     * Appends an indentation to the current PHP code after compilation.
135
     *
136
     * @return Twig_Compiler The current compiler instance
137
     */
122 138
    public function addIndentation()
123 139
    {
124 140
        $this->source .= str_repeat(' ', $this->indentation * 4);
......
129 145
    /**
130 146
     * Adds a quoted string to the compiled code.
131 147
     *
132
     * @param  string $value The string
148
     * @param string $value The string
133 149
     *
134 150
     * @return Twig_Compiler The current compiler instance
135 151
     */
......
143 159
    /**
144 160
     * Returns a PHP representation of a given value.
145 161
     *
146
     * @param  mixed $value The value to convert
162
     * @param mixed $value The value to convert
147 163
     *
148 164
     * @return Twig_Compiler The current compiler instance
149 165
     */
......
192 208
    public function addDebugInfo(Twig_NodeInterface $node)
193 209
    {
194 210
        if ($node->getLine() != $this->lastLine) {
195
            $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
211
            $this->write("// line {$node->getLine()}\n");
212

  
213
            // when mbstring.func_overload is set to 2
214
            // mb_substr_count() replaces substr_count()
215
            // but they have different signatures!
216
            if (((int) ini_get('mbstring.func_overload')) & 2) {
217
                // this is much slower than the "right" version
218
                $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n");
219
            } else {
220
                $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
221
            }
196 222
            $this->sourceOffset = strlen($this->source);
197 223
            $this->debugInfo[$this->sourceLine] = $node->getLine();
198 224

  
199 225
            $this->lastLine = $node->getLine();
200
            $this->write("// line {$node->getLine()}\n");
201 226
        }
202 227

  
203 228
        return $this;
......
231 256
     */
232 257
    public function outdent($step = 1)
233 258
    {
259
        // can't outdent by more steps that the current indentation level
260
        if ($this->indentation < $step) {
261
            throw new LogicException('Unable to call outdent() as the indentation would become negative');
262
        }
263

  
234 264
        $this->indentation -= $step;
235 265

  
236
        if ($this->indentation < 0) {
237
            throw new Twig_Error('Unable to call outdent() as the indentation would become negative');
238
        }
239

  
240 266
        return $this;
241 267
    }
242 268
}

Also available in: Unified diff