/** * Class constructor * * Initialize view and database classes. * * @return void */ public function __construct() { $this->view = new View(); $this->response = Response::getSoul(); $this->request = Request::getSoul(); $this->route = Route::getSoul(); $this->db = $this->db(); $this->model = ModelProvider::getSoul(); $this->config = Config::getSoul(); $this->cache = Cache::getSoul(); Hook::listen(__CLASS__); }
/** * render Halt Body * * @param string $type Error type * @param int $message Error string * @param string $file Error filepath * @param int $errline Error line * @return string */ protected static function renderHaltBody($type, $message, $line, $file) { $text = '<p><strong>Error Type: </strong>' . $type . '</p>' . '<p><strong>Info: </strong>' . $message . '</p>' . '<p><strong>Line: </strong>' . $line . '</p>' . '<p><strong>File: </strong>' . $file . '</p>'; $source = self::getSourceCode($file, $line); $sourceLen = strlen(strval(count($source['source']) + $source['first'])); $padding = 40 + ($sourceLen - 1) * 8; if (!empty($source)) { $text .= '<link href="' . Route::getSoul()->url('kotori-php-system-route/highlight-github.css') . '" rel="stylesheet" />'; $text .= '<style> .source-code { padding: 6px; border: 1px solid #ddd; background: #f9f9f9; overflow-x: auto; } .source-code pre { margin: 0; } .source-code pre ol { margin: 0; color: #4288ce; display: inline-block; min-width: 100%; box-sizing: border-box; font-size: 14px; font-family: Menlo,Monaco,Consolas,"Courier New",monospace; padding-left: ' . $padding . 'px; } .source-code pre li { border-left: 1px solid #ddd; height: 18px; line-height: 18px; } .source-code pre code { color: #333; height: 100%; display: inline-block; border-left: 1px solid #fff; font-size: 14px; font-family: Menlo,Monaco,Consolas,"Courier New",monospace; } .source-code pre li.line-error { background: #f8cbcb; } </style>'; $text .= '<p><strong>Source Code: </strong></p><div class="source-code"> <pre id="code-block" class="lang-php"> <ol start="' . $source['first'] . '">'; foreach ($source['source'] as $key => $value) { $currentLine = $key + $source['first']; $extendClass = $currentLine == $line ? ' line-error' : ''; $text .= '<li class="line-' . $currentLine . $extendClass . '"><code>' . htmlentities($value) . '</code></li>'; } $text .= '</ol></pre></div>'; $text .= '<script type="text/javascript" src="' . Route::getSoul()->url('kotori-php-system-route/highlight.js') . '"></script>'; $text .= '<script type="text/javascript"> window.onload = function() { hljs.highlightBlock(document.getElementById("code-block")); }; </script>'; } return $text; }
/** * Start the App. * * @return void */ public function run() { //Define a custom error handler so we can log PHP errors set_error_handler(array('\\Kotori\\Core\\Handle', 'error')); set_exception_handler(array('\\Kotori\\Core\\Handle', 'exception')); register_shutdown_function(array('\\Kotori\\Core\\Handle', 'end')); Config::getSoul()->initialize($this->_config); ini_set('date.timezone', Config::getSoul()->TIME_ZONE); if (Config::getSoul()->USE_SESSION) { !session_id() && session_start(); } //Build new Build(Config::getSoul()->APP_FULL_PATH); //Load application's common functions Helper::import(Config::getSoul()->APP_FULL_PATH . '/common.php'); if (function_exists('spl_autoload_register')) { spl_autoload_register(array('\\Kotori\\Core\\Helper', 'autoload')); } else { function __autoload($className) { Helper::autoload($className); } } //Load route class Route::getSoul()->dispatch(); //Global security filter array_walk_recursive($_GET, array('\\Kotori\\Http\\Request', 'filter')); array_walk_recursive($_POST, array('\\Kotori\\Http\\Request', 'filter')); array_walk_recursive($_REQUEST, array('\\Kotori\\Http\\Request', 'filter')); }
/** * 组装分页链接 * @return string */ public function show() { if (0 == $this->totalRows) { return ''; } /* 生成URL */ $this->parameter[$this->p] = '[PAGE]'; $this->url = Route::getSoul()->url(URI . '?' . http_build_query($this->parameter)); /* 计算分页信息 */ $this->totalPages = ceil($this->totalRows / $this->listRows); //总页数 if (!empty($this->totalPages) && $this->nowPage > $this->totalPages) { $this->nowPage = $this->totalPages; } /* 计算分页临时变量 */ $now_cool_page = $this->rollPage / 2; $now_cool_page_ceil = ceil($now_cool_page); $this->lastSuffix && ($this->config['last'] = $this->totalPages); //上一页 $up_row = $this->nowPage - 1; $up_page = $up_row > 0 ? '<a class="prev" href="' . $this->url($up_row) . '">' . $this->config['prev'] . '</a>' : ''; //下一页 $down_row = $this->nowPage + 1; $down_page = $down_row <= $this->totalPages ? '<a class="next" href="' . $this->url($down_row) . '">' . $this->config['next'] . '</a>' : ''; //第一页 $the_first = ''; if ($this->totalPages > $this->rollPage && $this->nowPage - $now_cool_page >= 1) { $the_first = '<a class="first" href="' . $this->url(1) . '">' . $this->config['first'] . '</a>'; } //最后一页 $the_end = ''; if ($this->totalPages > $this->rollPage && $this->nowPage + $now_cool_page < $this->totalPages) { $the_end = '<a class="end" href="' . $this->url($this->totalPages) . '">' . $this->config['last'] . '</a>'; } //数字连接 $link_page = ""; for ($i = 1; $i <= $this->rollPage; $i++) { if ($this->nowPage - $now_cool_page <= 0) { $page = $i; } elseif ($this->nowPage + $now_cool_page - 1 >= $this->totalPages) { $page = $this->totalPages - $this->rollPage + $i; } else { $page = $this->nowPage - $now_cool_page_ceil + $i; } if ($page > 0 && $page != $this->nowPage) { if ($page <= $this->totalPages) { $link_page .= '<a class="num" href="' . $this->url($page) . '">' . $page . '</a>'; } else { break; } } else { if ($page > 0 && $this->totalPages != 1) { $link_page .= '<span class="current">' . $page . '</span>'; } } } //替换分页内容 $page_str = str_replace(array('%HEADER%', '%NOW_PAGE%', '%UP_PAGE%', '%DOWN_PAGE%', '%FIRST%', '%LINK_PAGE%', '%END%', '%TOTAL_ROW%', '%TOTAL_PAGE%'), array($this->config['header'], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages), $this->config['theme']); return "<div>{$page_str}</div>"; }