Exemple #1
0
 public function __construct()
 {
     $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem(ROOT . '/templates'), array('cache' => ROOT . '/tmp/twig', 'debug' => Configure::read('mode') === 'development'));
     if (Configure::read('mode') !== 'production') {
         $this->twig->addExtension(new \Twig_Extension_Debug());
     }
     $this->twig->getExtension('core')->setNumberFormat(2, ',', '.');
     $this->twig->addGlobal('now', time());
 }
Exemple #2
0
 /**
  * Default error message
  *
  * @see \Fiets\Fiets::error()
  * @see \Fiets\Fiets::callErrorHandler()
  * @param string $argument
  * @return void
  * @author Bjorn Post
  */
 protected function defaultError($argument = null)
 {
     $title = get_class($argument);
     $code = $argument->getCode();
     $message = $argument->getMessage();
     $file = $argument->getFile();
     $line = $argument->getLine();
     $trace = $argument->getTraceAsString();
     if (PHP_SAPI === 'cli') {
         $out = "";
         $out .= sprintf(" 🐞  %s\n", $title);
         $out .= sprintf("    %s (%s)\n", $message, $code);
         $out .= sprintf("    File: %s:%s\n\n", $file, $line);
         $out .= str_replace(ROOT, '', $trace);
         echo $out;
         exit(1);
     } else {
         if (Configure::read('mode') === 'development') {
             if (!headers_sent()) {
                 header('HTTP/1.1 500 Internal Server Error');
             }
             $style = "html * { padding:0; margin:0; }\n\t\t\t\t\tbody * { padding:10px 20px; max-width: 800px; }\n\t\t\t\t\tbody * * { padding:0; }\n\t\t\t\t\tbody { font:small sans-serif; }\n\t\t\t\t\tbody>div { border-bottom:1px solid #ddd; }\n\t\t\t\t\th1 { font-weight:normal; }\n\t\t\t\t\th2 { margin-bottom:.8em; }\n\t\t\t\t\th2 span { font-size:80%; color:#666; font-weight:normal; }\n\t\t\t\t\th3 { margin:1em 0 .5em 0; }\n\t\t\t\t\th4 { margin:0 0 .5em 0; font-weight: normal; }\n\t\t\t\t\tcode, pre { font-size: 100%; white-space: pre-wrap; }\n\t\t\t\t\ttable { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; margin-top:1.5em; }\n\t\t\t\t\ttbody td, tbody th { vertical-align:top; padding:2px 3px; }\n\t\t\t\t\ttable th { width: 10em; text-align: left; }\n\n\t\t\t\t\t#summary { background: #ffc; }\n\t\t\t\t\t#summary h2 { font-weight: normal; color: #666; }\n\t\t\t\t\t#traceback { background:#eee; line-height:1.5em; }\n\t\t\t\t\t#summary table { border:none; background:transparent; }\n\t\t\t\t\tpre.exception_value { font-family: sans-serif; color: #666; font-size: 1.5em; margin: 10px 0 10px 0; }";
             $html = '<div id="summary">';
             $html .= sprintf('<h1>%s @ %s</h1>', $title, $_SERVER['REQUEST_URI']);
             $html .= sprintf('<pre class="exception_value">%s (%s)</pre>', $message, $code);
             $html .= '<table class="meta">';
             $html .= sprintf('<tr><th>Request Method:</th><td>%s</td></tr>', $_SERVER['REQUEST_METHOD']);
             $html .= sprintf('<tr><th>Request URI:</th><td>%s</td></tr>', $_SERVER['REQUEST_URI']);
             $html .= sprintf('<tr><th>File:</th><td>%s</td></tr>', $file);
             $html .= sprintf('<tr><th>Line:</th><td>%s</td></tr>', $line);
             $html .= '</table>';
             $html .= '</div>';
             if ($title == 'Pheasant\\Database\\Mysqli\\Exception') {
                 $html .= '<div id="traceback">';
                 $html .= '<h2>Query details</h2>';
                 $html .= @sprintf('<pre>%s</pre>', $argument->getTrace()[0]['args'][0]);
                 $html .= '</div>';
             }
             if ($trace) {
                 $html .= '<div id="traceback">';
                 $html .= '<h2>Traceback</h2>';
                 $html .= sprintf('<pre>%s</pre>', str_replace(ROOT, '', $trace));
                 $html .= '</div>';
             }
             echo sprintf("<html><head><title>%s</title><style>%s</style></head><body>%s</body></html>", $title, $style, $html);
         } else {
             ob_clean();
             ob_start();
             echo $this->render('500.html', compact('html', 'title', 'code', 'message', 'file', 'line', 'trace'));
             echo ob_flush();
             ob_end_clean();
         }
     }
     if ($title !== 'Pheasant\\Database\\Mysqli\\Exception') {
         // write errors to log
         if (PHP_SAPI === 'cli') {
             \Analog::log(sprintf('%s - %s: %s (%s) @ %s:%s', $file, $title, $message, $code, $file, $line), \Analog::ERROR);
         } else {
             \Analog::log(sprintf('%s %s - %s: %s (%s) @ %s:%s', $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $title, $message, $code, $file, $line), \Analog::ERROR);
         }
     } else {
         // write errors to log
         if (PHP_SAPI === 'cli') {
             \Analog::log(sprintf('%s - %s: %s (%s) @ %s:%s (%s)', $file, $title, $message, $code, $file, $line, $argument->getTrace()[0]['args'][0]), \Analog::ERROR);
         } else {
             \Analog::log(sprintf('%s %s - %s: %s (%s) @ %s:%s (%s)', $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $title, $message, $code, $file, $line, $argument->getTrace()[0]['args'][0]), \Analog::ERROR);
         }
     }
 }