Exemplo n.º 1
0
 /**
  * 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__);
 }
Exemplo n.º 2
0
    /**
     * General Error Page
     *
     * Takes an error message as input
     * and displays it using the specified template.
     *
     * @param string $message Error Message
     * @param int $code HTTP Header code
     *
     * @return void
     */
    public static function halt($message, $code = 404)
    {
        Response::getSoul()->setStatus($code);
        if (Config::getSoul()->APP_DEBUG == false) {
            $message = '404 Not Found.';
        }
        $tplPath = Config::getSoul()->ERROR_TPL;
        if ($tplPath == null || !Helper::isFile(Config::getSoul()->APP_FULL_PATH . '/views/' . $tplPath . '.html')) {
            $tpl = '<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>Kotori.php 500 Internal Error</title>
  <meta name="robots" content="NONE,NOARCHIVE">
  <style type="text/css">
    html * { padding:0; margin:0; }
    body * { padding:10px 20px; }
    body * * { padding:0; }
    body { font:small sans-serif; background:#eee; }
    body>div { border-bottom:1px solid #ddd; }
    h1 { font-weight:normal; margin-bottom:.4em; }
    h1 span { font-size:60%; color:#666; font-weight:normal; }
    table { border:none; border-collapse: collapse; width:100%; }
    td, th { vertical-align:top; padding:2px 3px; }
    th { width:12em; text-align:right; color:#666; padding-right:.5em; }
    #info { background:#f6f6f6; }
    #info p {font-size: 16px}
    #summary { background: #ffc; }
    #explanation { background:#eee; border-bottom: 0px none; }
  </style>
</head>
<body>
  <div id="summary">
    <h1>Kotori.php Internal Error <span>(500)</span></h1>
    <table class="meta">
      <tr>
        <th>Request Method:</th>
        <td>' . strtoupper($_SERVER['REQUEST_METHOD']) . '</td>
      </tr>
      <tr>
        <th>Request URL:</th>
        <td>' . Request::getSoul()->getBaseUrl() . ltrim($_SERVER['REQUEST_URI'], '/') . '</td>
      </tr>

    </table>
  </div>
  <div id="info">
      ' . $message . '
  </div>

  <div id="explanation">
    <p>
      You\'re seeing this error because you have <code>APP_DEBUG = True</code> in
      your index.php file. Change that to <code>False</code>, and Kotori.php
      will display a standard 404 page.
    </p>
  </div>
</body>
</html>';
        } else {
            $tpl = file_get_contents(Config::getSoul()->APP_FULL_PATH . '/views/' . $tplPath . '.html');
        }
        $tpl = str_replace('{$message}', $message, $tpl);
        $htmlParser = htmlParserFactory::construct();
        $tpl = $htmlParser->compress($tpl);
        exit($tpl);
    }
Exemplo n.º 3
0
 /**
  * Build Full URL
  *
  * @param string $uri URI
  * @param string $module module name
  * @return string
  */
 public function url($uri = '', $module = null)
 {
     if ($module != null) {
         $appPaths = Config::getSoul()->APP_PATH;
         if (is_array($appPaths)) {
             foreach ($appPaths as &$appPath) {
                 $appPath = str_replace('./', '', $appPath);
             }
             $appPaths = array_flip($appPaths);
             $baseUrl = $appPaths[$module];
             $baseUrl = '//' . $baseUrl . '/';
         }
     } else {
         $baseUrl = Request::getSoul()->getBaseUrl();
     }
     $uri = is_array($uri) ? implode('/', $uri) : trim($uri, '/');
     $prefix = $baseUrl . 'index.php?_i=';
     switch (Config::getSoul()->URL_MODE) {
         case 'PATH_INFO':
             return $uri == '' ? rtrim($baseUrl, '/') : $baseUrl . $uri;
             break;
         case 'QUERY_STRING':
             return $uri == '' ? rtrim($baseUrl, '/') : $prefix . $uri;
             break;
         default:
             throw new \Exception('URL_MODE Config ERROR');
     }
 }
Exemplo n.º 4
0
 /**
  * Initialize Config
  *
  * @param $config Config Array
  * @return boolean
  */
 public function initialize($config = array())
 {
     $this->_config = $config;
     if (is_array($this->_config)) {
         if (array_keys($this->_config) !== range(0, count($this->_config) - 1)) {
             if (isset($this->_config['DB']) && is_array($this->_config['DB'])) {
                 foreach ($this->_config['DB'] as $key => &$value) {
                     if (!isset($value['PORT'])) {
                         $value['PORT'] = 3306;
                     }
                     if (!isset($value['CHARSET'])) {
                         $value['CHARSET'] = 'utf8';
                     }
                 }
             }
             $this->_config = array_merge($this->_defaults, $this->_config);
             if (is_array($this->APP_PATH)) {
                 $hostName = Request::getSoul()->getHostName();
                 if (array_key_exists($hostName, $this->APP_PATH)) {
                     $appPath = $this->APP_PATH[$hostName];
                 } else {
                     throw new \Exception('Cannot found any app paths.');
                 }
             } else {
                 $appPath = $this->APP_PATH;
             }
             $this->_config = array_merge(array('APP_FULL_PATH' => realpath(realpath('.') . '/' . rtrim($appPath, '/'))), $this->_config);
             $this->NAMESPACE_PREFIX = basename($this->APP_FULL_PATH) . '\\';
         }
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * Base URL
  *
  * Returns base url
  *
  * @return string
  */
 public function getBaseUrl()
 {
     if (isset($_SERVER['HTTP_HOST']) && preg_match('/^((\\[[0-9a-f:]+\\])|(\\d{1,3}(\\.\\d{1,3}){3})|[a-z0-9\\-\\.]+)(:\\d+)?$/i', $_SERVER['HTTP_HOST'])) {
         $base_url = (Request::getSoul()->isSecure() ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
     } else {
         $base_url = 'http://localhost/';
     }
     return rtrim($base_url, '/') . '/';
 }