Пример #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());
 }
Пример #2
0
 protected function ifConditionIsTrue($condition)
 {
     $matches = array();
     if (preg_match('/([a-zA-Z0-9_\\-\\(\\):\\s.\\"]+)\\s+?([\\!\\=\\<\\>]+)?\\s+?([a-zA-Z0-9\\(\\)_\\-:\\s.\\"]+)?/', $condition, $matches)) {
         $left = is_numeric($matches[1]) ? intval($matches[1]) : $this->template->getVariable($matches[1]);
         $right = is_numeric($matches[3]) ? intval($matches[3]) : $this->template->getVariable($matches[3]);
         $operator = $matches[2];
         switch ($operator) {
             case '==':
             case '=':
                 return $left == $right;
             case '!=':
                 return $left != $right;
             case '>=':
                 return $left >= $right;
             case '<=':
                 return $left <= $right;
             case '>':
                 return $left > $right;
             case '<':
                 return $left < $right;
         }
     } elseif (preg_match('/([a-zA-Z0-9_\\-\\(\\):\\s.]+)/', $condition, $matches)) {
         return $this->template->getVariable($condition) ? true : false;
     }
 }
Пример #3
0
 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();
 }
Пример #4
0
 public function render()
 {
     $code = parent::render();
     Event::trigger('OnTemplateRender', $code);
     return $code;
 }