You are here

protected function Twig_Error::guessTemplateInfo in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Error.php \Twig_Error::guessTemplateInfo()

@internal

2 calls to Twig_Error::guessTemplateInfo()
Twig_Error::guess in vendor/twig/twig/lib/Twig/Error.php
Twig_Error::__construct in vendor/twig/twig/lib/Twig/Error.php
Constructor.

File

vendor/twig/twig/lib/Twig/Error.php, line 208

Class

Twig_Error
Twig base exception.

Code

protected function guessTemplateInfo() {
  $template = null;
  $templateClass = null;
  if (PHP_VERSION_ID >= 50306) {
    $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
  }
  else {
    $backtrace = debug_backtrace();
  }
  foreach ($backtrace as $trace) {
    if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
      $currentClass = get_class($trace['object']);
      $isEmbedContainer = 0 === strpos($templateClass, $currentClass);
      if (null === $this->filename || $this->filename == $trace['object']
        ->getTemplateName() && !$isEmbedContainer) {
        $template = $trace['object'];
        $templateClass = get_class($trace['object']);
      }
    }
  }

  // update template filename
  if (null !== $template && null === $this->filename) {
    $this->filename = $template
      ->getTemplateName();
  }
  if (null === $template || $this->lineno > -1) {
    return;
  }
  $r = new ReflectionObject($template);
  $file = $r
    ->getFileName();

  // hhvm has a bug where eval'ed files comes out as the current directory
  if (is_dir($file)) {
    $file = '';
  }
  $exceptions = array(
    $e = $this,
  );
  while (($e instanceof self || method_exists($e, 'getPrevious')) && ($e = $e
    ->getPrevious())) {
    $exceptions[] = $e;
  }
  while ($e = array_pop($exceptions)) {
    $traces = $e
      ->getTrace();
    array_unshift($traces, array(
      'file' => $e
        ->getFile(),
      'line' => $e
        ->getLine(),
    ));
    while ($trace = array_shift($traces)) {
      if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) {
        continue;
      }
      foreach ($template
        ->getDebugInfo() as $codeLine => $templateLine) {
        if ($codeLine <= $trace['line']) {

          // update template line
          $this->lineno = $templateLine;
          return;
        }
      }
    }
  }
}