Example #1
0
 /**
  * Clarify exeption with it's actual location.
  *
  * @param string            $path
  * @param StemplerException $exception
  * @return StemplerException
  */
 protected function clarifyException($path, StemplerException $exception)
 {
     if (empty($exception->getToken())) {
         //Unable to locate
         return $exception;
     }
     //We will need only first tag line
     $target = explode("\n", $exception->getToken()[HtmlTokenizer::TOKEN_CONTENT])[0];
     //Let's try to locate place where exception was used
     $lines = explode("\n", $this->loader->getSource($path));
     foreach ($lines as $number => $line) {
         if (strpos($line, $target) !== false) {
             //We found where token were used (!!)
             $exception->setLocation($this->loader->localFilename($path), $number + 1);
             break;
         }
     }
     return $exception;
 }