Example #1
0
 public function handleException(Exception $ex)
 {
     if (ini_get('display_errors')) {
         $template = Template::createFromFile('UncaughtExceptionTemplate', B8_PATH . 'Exception/');
     } elseif (isset($this->friendlyTemplate)) {
         $template =& $this->friendlyTemplate;
     } else {
         $template = Template::createFromFile('FriendlyUncaughtExceptionTemplate', B8_PATH . 'Exception/');
     }
     $template->file = $ex->getFile();
     $template->line = $ex->getLine();
     $template->message = $ex->getMessage();
     $template->trace = $this->extendTrace($ex->getTrace());
     $template->code = $this->getErrorLines($ex->getFile(), $ex->getLine() - 1);
     list($file, $line) = $this->findApplicationExceptionSource($template->trace);
     if ($file != $ex->getFile() || $line != $ex->getLine()) {
         $template->app_code = $this->getErrorLines($file, $line - 1);
     }
     $template->addFunction('var_dump', function ($args, &$view) {
         $item = $view->getVariable($args['item']);
         ob_start();
         var_dump($item);
         $rtn = ob_get_contents();
         ob_end_clean();
         return $rtn;
     });
     if ($ex instanceof HttpException) {
         header($ex->getHttpHeader(), true, $ex->getErrorCode());
     } else {
         header('HTTP/1.1 500 Internal Server Error', true, 500);
     }
     die($template->render());
 }
 protected function processTemplate($tableName, $table, $template)
 {
     $config = Config::getInstance();
     $appNamespace = $config->get('b8.app.namespace');
     if (!class_exists($appNamespace . '\\Model')) {
         $appNamespace = 'b8';
     }
     $tpl = Template::createFromFile($template, B8_PATH . 'Database/CodeGenerator/');
     $tpl->appNamespace = $appNamespace;
     $tpl->itemNamespace = $this->getNamespace($table['php_name']);
     $tpl->name = $tableName;
     $tpl->table = $table;
     $tpl->counts = $this->counts;
     $callback = function ($args, $view) {
         return $this->getNamespace($args['model']);
     };
     $tpl->addFunction('get_namespace', $callback);
     return $tpl->render();
 }