PEEL Shopping
Open source ecommerce : PEEL Shopping
Error.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 2009 Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
34 class Twig_Error extends Exception
35 {
36  protected $lineno;
37  protected $filename;
38  protected $rawMessage;
39  protected $previous;
40 
58  public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null)
59  {
60  if (version_compare(PHP_VERSION, '5.3.0', '<')) {
61  $this->previous = $previous;
62  parent::__construct('');
63  } else {
64  parent::__construct('', 0, $previous);
65  }
66 
67  $this->lineno = $lineno;
68  $this->filename = $filename;
69 
70  if (-1 === $this->lineno || null === $this->filename) {
71  $this->guessTemplateInfo();
72  }
73 
74  $this->rawMessage = $message;
75 
76  $this->updateRepr();
77  }
78 
84  public function getRawMessage()
85  {
86  return $this->rawMessage;
87  }
88 
94  public function getTemplateFile()
95  {
96  return $this->filename;
97  }
98 
104  public function setTemplateFile($filename)
105  {
106  $this->filename = $filename;
107 
108  $this->updateRepr();
109  }
110 
116  public function getTemplateLine()
117  {
118  return $this->lineno;
119  }
120 
126  public function setTemplateLine($lineno)
127  {
128  $this->lineno = $lineno;
129 
130  $this->updateRepr();
131  }
132 
133  public function guess()
134  {
135  $this->guessTemplateInfo();
136  $this->updateRepr();
137  }
138 
149  public function __call($method, $arguments)
150  {
151  if ('getprevious' == strtolower($method)) {
152  return $this->previous;
153  }
154 
155  throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method));
156  }
157 
158  protected function updateRepr()
159  {
160  $this->message = $this->rawMessage;
161 
162  $dot = false;
163  if ('.' === substr($this->message, -1)) {
164  $this->message = substr($this->message, 0, -1);
165  $dot = true;
166  }
167 
168  if ($this->filename) {
169  if (is_string($this->filename) || (is_object($this->filename) && method_exists($this->filename, '__toString'))) {
170  $filename = sprintf('"%s"', $this->filename);
171  } else {
172  $filename = json_encode($this->filename);
173  }
174  $this->message .= sprintf(' in %s', $filename);
175  }
176 
177  if ($this->lineno && $this->lineno >= 0) {
178  $this->message .= sprintf(' at line %d', $this->lineno);
179  }
180 
181  if ($dot) {
182  $this->message .= '.';
183  }
184  }
185 
186  protected function guessTemplateInfo()
187  {
188  $template = null;
189  $templateClass = null;
190 
191  if (version_compare(phpversion(), '5.3.6', '>=')) {
192  $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
193  } else {
194  $backtrace = debug_backtrace();
195  }
196 
197  foreach ($backtrace as $trace) {
198  if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
199  $currentClass = get_class($trace['object']);
200  $isEmbedContainer = 0 === strpos($templateClass, $currentClass);
201  if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
202  $template = $trace['object'];
203  $templateClass = get_class($trace['object']);
204  }
205  }
206  }
207 
208  // update template filename
209  if (null !== $template && null === $this->filename) {
210  $this->filename = $template->getTemplateName();
211  }
212 
213  if (null === $template || $this->lineno > -1) {
214  return;
215  }
216 
217  $r = new ReflectionObject($template);
218  $file = $r->getFileName();
219 
220  $exceptions = array($e = $this);
221  while (($e instanceof self || method_exists($e, 'getPrevious')) && $e = $e->getPrevious()) {
222  $exceptions[] = $e;
223  }
224 
225  while ($e = array_pop($exceptions)) {
226  $traces = $e->getTrace();
227  while ($trace = array_shift($traces)) {
228  if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) {
229  continue;
230  }
231 
232  foreach ($template->getDebugInfo() as $codeLine => $templateLine) {
233  if ($codeLine <= $trace['line']) {
234  // update template line
235  $this->lineno = $templateLine;
236 
237  return;
238  }
239  }
240  }
241  }
242  }
243 }
guessTemplateInfo()
Definition: Error.php:186
updateRepr()
Definition: Error.php:158
getTemplateLine()
Gets the template line where the error occurred.
Definition: Error.php:116
setTemplateLine($lineno)
Sets the template line where the error occurred.
Definition: Error.php:126
getTemplateFile()
Gets the filename where the error occurred.
Definition: Error.php:94
getRawMessage()
Gets the raw message.
Definition: Error.php:84
__construct($message, $lineno=-1, $filename=null, Exception $previous=null)
Constructor.
Definition: Error.php:58
Twig base exception.
Definition: Error.php:34
__call($method, $arguments)
For PHP < 5.3.0, provides access to the getPrevious() method.
Definition: Error.php:149
$rawMessage
Definition: Error.php:38
Default base class for compiled templates.
Definition: Template.php:18
setTemplateFile($filename)
Sets the filename where the error occurred.
Definition: Error.php:104

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:18 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.