コード例 #1
0
ファイル: Syntax.php プロジェクト: kentfredric/Twig
 public function __construct($message, $lineno, $filename = null)
 {
     $this->lineno = $lineno;
     $this->filename = $filename;
     $this->rawMessage = $message;
     $this->updateRepr();
     parent::__construct($this->message, $lineno);
 }
コード例 #2
0
ファイル: LintCommand.php プロジェクト: ninvfeng/symfony
 private function renderException(OutputInterface $output, $template, \Twig_Error $exception, $file = null)
 {
     $line = $exception->getTemplateLine();
     if ($file) {
         $output->writeln(sprintf('<error>KO</error> in %s (line %s)', $file, $line));
     } else {
         $output->writeln(sprintf('<error>KO</error> (line %s)', $line));
     }
     foreach ($this->getContext($template, $line) as $no => $code) {
         $output->writeln(sprintf('%s %-6s %s', $no == $line ? '<error>>></error>' : '  ', $no, $code));
         if ($no == $line) {
             $output->writeln(sprintf('<error>>> %s</error> ', $exception->getRawMessage()));
         }
     }
 }
コード例 #3
0
 public function testErrorWithArrayFilename()
 {
     $error = new Twig_Error('foo');
     $error->setTemplateFile(array('foo' => 'bar'));
     $this->assertEquals('foo in {"foo":"bar"}', $error->getMessage());
 }
コード例 #4
0
ファイル: Loader.php プロジェクト: BozzaCoon/SPHERE-Framework
 public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null)
 {
     parent::__construct($message, false, false, $previous);
 }
コード例 #5
0
ファイル: LintCommand.php プロジェクト: JPunto/Symfony
 protected function renderException(OutputInterface $output, $file, \Twig_Error $exception)
 {
     $line = $exception->getTemplateLine();
     $lines = $this->getContext($file, $line);
     $output->writeln(sprintf("<error>KO</error> in %s (line %s)", $file, $line));
     foreach ($lines as $no => $code) {
         $output->writeln(sprintf("%s %-6s %s", $no == $line ? '<error>>></error>' : '  ', $no, $code));
         if ($no == $line) {
             $output->writeln(sprintf('<error>>> %s</error> ', $exception->getRawMessage()));
         }
     }
 }
コード例 #6
0
ファイル: Twig.php プロジェクト: carew/carew
 private function enhanceTwigException(\Twig_Error $e, Document $document, $template = null)
 {
     if (-1 === $e->getTemplateLine()) {
         return new \RuntimeException($e->getRawMessage());
     }
     $lines = explode(PHP_EOL, $document->getBody());
     if (!$template || $template->getTemplateName() == $e->getTemplateFile()) {
         return new \RuntimeException(OutputFormatter::escape(sprintf('%s near "%s" near line %d.', $e->getRawMessage(), $lines[$e->getTemplateLine() - 1], $e->getTemplateLine())));
     }
     return new \RuntimeException(OutputFormatter::escape(sprintf('%s in a string template line %d.', $e->getRawMessage(), $e->getTemplateLine())));
 }
コード例 #7
0
ファイル: ErrorHandler.php プロジェクト: nitwitt10/Trove
 /**
  * Handles Twig syntax errors.
  *
  * @param \Twig_Error $exception
  *
  * @return null
  */
 protected function handleTwigError(\Twig_Error $exception)
 {
     $templateFile = $exception->getTemplateFile();
     $file = craft()->templates->findTemplate($templateFile);
     if (!$file) {
         $file = $templateFile;
     }
     $this->_error = $data = array('code' => 500, 'type' => Craft::t('Template Error'), 'errorCode' => $exception->getCode(), 'message' => $exception->getRawMessage(), 'file' => $file, 'line' => $exception->getTemplateLine(), 'trace' => '', 'traces' => null);
     if (!headers_sent()) {
         HeaderHelper::setHeader("HTTP/1.0 {$data['code']} " . $this->getHttpHeader($data['code'], get_class($exception)));
     }
     if ($exception instanceof \CHttpException || !YII_DEBUG) {
         $this->render('error', $data);
     } else {
         if ($this->isAjaxRequest()) {
             craft()->displayException($exception);
         } else {
             $this->render('exception', $data);
         }
     }
 }