You are here

protected function Twig_Error::guessTemplateInfo in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Error.php \Twig_Error::guessTemplateInfo()
2 calls to Twig_Error::guessTemplateInfo()
Twig_Error::guess in vendor/Twig/Error.php
Twig_Error::__construct in vendor/Twig/Error.php
Constructor.

File

vendor/Twig/Error.php, line 186

Class

Twig_Error
Twig base exception.

Code

protected function guessTemplateInfo() {
  $template = null;
  $templateClass = null;
  if (version_compare(phpversion(), '5.3.6', '>=')) {
    $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;
        }
      }
    }
  }
}