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:

Error.php
12 12
/**
13 13
 * Twig base exception.
14 14
 *
15
 * This exception class and its children must only be used when
16
 * an error occurs during the loading of a template, when a syntax error
17
 * is detected in a template, or when rendering a template. Other
18
 * errors must use regular PHP exception classes (like when the template
19
 * cache directory is not writable for instance).
20
 *
21
 * To help debugging template issues, this class tracks the original template
22
 * name and line where the error occurred.
23
 *
24
 * Whenever possible, you must set these information (original template name
25
 * and line number) yourself by passing them to the constructor. If some or all
26
 * these information are not available from where you throw the exception, then
27
 * this class will guess them automatically (when the line number is set to -1
28
 * and/or the filename is set to null). As this is a costly operation, this
29
 * can be disabled by passing false for both the filename and the line number
30
 * when creating a new instance of this class.
31
 *
15 32
 * @package    twig
16 33
 * @author     Fabien Potencier <fabien@symfony.com>
17 34
 */
......
25 42
    /**
26 43
     * Constructor.
27 44
     *
45
     * Set both the line number and the filename to false to
46
     * disable automatic guessing of the original template name
47
     * and line number.
48
     *
49
     * Set the line number to -1 to enable its automatic guessing.
50
     * Set the filename to null to enable its automatic guessing.
51
     *
52
     * By default, automatic guessing is enabled.
53
     *
28 54
     * @param string    $message  The error message
29 55
     * @param integer   $lineno   The template line where the error occurred
30 56
     * @param string    $filename The template file name where the error occurred
......
105 131
        $this->updateRepr();
106 132
    }
107 133

  
134
    public function guess()
135
    {
136
        $this->guessTemplateInfo();
137
        $this->updateRepr();
138
    }
139

  
108 140
    /**
109 141
     * For PHP < 5.3.0, provides access to the getPrevious() method.
110 142
     *
111
     * @param  string $method    The method name
112
     * @param  array  $arguments The parameters to be passed to the method
143
     * @param string $method    The method name
144
     * @param array  $arguments The parameters to be passed to the method
113 145
     *
114 146
     * @return Exception The previous exception or null
147
     *
148
     * @throws BadMethodCallException
115 149
     */
116 150
    public function __call($method, $arguments)
117 151
    {
......
132 166
            $dot = true;
133 167
        }
134 168

  
135
        if (null !== $this->filename) {
169
        if ($this->filename) {
136 170
            if (is_string($this->filename) || (is_object($this->filename) && method_exists($this->filename, '__toString'))) {
137 171
                $filename = sprintf('"%s"', $this->filename);
138 172
            } else {
......
141 175
            $this->message .= sprintf(' in %s', $filename);
142 176
        }
143 177

  
144
        if ($this->lineno >= 0) {
178
        if ($this->lineno && $this->lineno >= 0) {
145 179
            $this->message .= sprintf(' at line %d', $this->lineno);
146 180
        }
147 181

  
......
155 189
        $template = null;
156 190
        foreach (debug_backtrace() as $trace) {
157 191
            if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
158
                $template = $trace['object'];
159

  
160
                // update template filename
161
                if (null === $this->filename) {
162
                    $this->filename = $template->getTemplateName();
192
                if (null === $this->filename || $this->filename == $trace['object']->getTemplateName()) {
193
                    $template = $trace['object'];
163 194
                }
164 195
            }
165 196
        }
166 197

  
198
        // update template filename
199
        if (null !== $template && null === $this->filename) {
200
            $this->filename = $template->getTemplateName();
201
        }
202

  
167 203
        if (null === $template || $this->lineno > -1) {
168 204
            return;
169 205
        }
......
172 208
        $file = $r->getFileName();
173 209

  
174 210
        $exceptions = array($e = $this);
175
        while (method_exists($e, 'getPrevious') && $e = $e->getPrevious()) {
211
        while (($e instanceof self || method_exists($e, 'getPrevious')) && $e = $e->getPrevious()) {
176 212
            $exceptions[] = $e;
177 213
        }
178 214

  

Also available in: Unified diff