60 if (version_compare(PHP_VERSION,
'5.3.0',
'<')) {
62 parent::__construct(
'');
70 if (-1 === $this->lineno || null === $this->filename) {
74 $this->rawMessage = $message;
149 public function __call($method, $arguments)
151 if (
'getprevious' == strtolower($method)) {
155 throw new BadMethodCallException(sprintf(
'Method "Twig_Error::%s()" does not exist.', $method));
163 if (
'.' === substr($this->message, -1)) {
164 $this->message = substr($this->message, 0, -1);
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);
172 $filename = json_encode($this->filename);
174 $this->message .= sprintf(
' in %s',
$filename);
177 if ($this->lineno && $this->lineno >= 0) {
178 $this->message .= sprintf(
' at line %d', $this->lineno);
182 $this->message .=
'.';
189 $templateClass = null;
191 if (version_compare(phpversion(),
'5.3.6',
'>=')) {
192 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
194 $backtrace = debug_backtrace();
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']);
209 if (null !== $template && null === $this->filename) {
210 $this->filename = $template->getTemplateName();
213 if (null === $template || $this->lineno > -1) {
217 $r =
new ReflectionObject($template);
218 $file = $r->getFileName();
220 $exceptions = array($e = $this);
221 while (($e instanceof
self || method_exists($e,
'getPrevious')) && $e = $e->getPrevious()) {
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']) {
232 foreach ($template->getDebugInfo() as $codeLine => $templateLine) {
233 if ($codeLine <= $trace[
'line']) {
235 $this->lineno = $templateLine;
getTemplateLine()
Gets the template line where the error occurred.
setTemplateLine($lineno)
Sets the template line where the error occurred.
getTemplateFile()
Gets the filename where the error occurred.
getRawMessage()
Gets the raw message.
__construct($message, $lineno=-1, $filename=null, Exception $previous=null)
Constructor.
__call($method, $arguments)
For PHP < 5.3.0, provides access to the getPrevious() method.
Default base class for compiled templates.
setTemplateFile($filename)
Sets the filename where the error occurred.