Пример #1
0
 /**
  * Send response.
  *
  * @param string $code
  * @param string $message
  * @param string $file
  * @param string $line
  * @param null $context
  * @param array|null $backtrace
  */
 public static function render($code, $message, $file, $line, $context = null, array $backtrace = [])
 {
     ob_clean();
     $data = ['message' => $message, 'code' => $code, 'file' => $file, 'line' => $line, 'trace' => $backtrace, 'context' => $context];
     if (!empty($data['trace'])) {
         foreach ($data['trace'] as $k => $item) {
             if (isset($item['type'])) {
                 switch ($item['type']) {
                     case '->':
                         $data['trace'][$k]['type'] = 'method';
                         break;
                     case '::':
                         $data['trace'][$k]['type'] = 'static method';
                         break;
                     default:
                         $data['trace'][$k]['type'] = 'function';
                 }
             }
         }
     }
     $template = new Native(dirname(__FILE__) . '/', null, true);
     $response = new Response();
     $response->headerStatus(418);
     $response->setContent($template->getContent('catch.html.php', $data));
     $response->send();
     exit;
 }
Пример #2
0
 public function testClearCache()
 {
     $root = dirname(__FILE__);
     $path = $root . '/view/test.html.php';
     mkdir($root . '/view');
     mkdir($root . '/view/_cache');
     if (file_exists($root . '/view')) {
         $fh = fopen($path, 'wb');
         fwrite($fh, '<h1>Hello world</h1>');
         fclose($fh);
         $this->assertEquals(2, count(scandir($root . '/view/_cache')));
         $template = new Native($root);
         $template->getContent('test.html.php');
         $this->assertEquals(3, count(scandir($root . '/view/_cache')));
         $template->clearCache();
         $this->assertEquals(2, count(scandir($root . '/view/_cache')));
         if (file_exists($root . '/view/_cache/test.html.php')) {
             unlink($root . '/view/_cache/test.html.php');
         }
         unlink($root . '/view/test.html.php');
         rmdir($root . '/view/_cache');
         rmdir($root . '/view');
     }
 }