Exemple #1
0
 /**
  * Подключение к базе данных
  *
  * @return \Knee\DataBase\Query
  */
 public static function connection($connect = null)
 {
     $connect = !is_null($connect) ? $connect : 'default';
     if (array_key_exists($connect, static::$connections)) {
         return static::$connections[$connect];
     }
     try {
         $config = Config::get('database.connections.' . $connect);
         if (!is_array($config)) {
             throw new PDOException();
         }
         extract($config);
         $dsn = "mysql:host=" . $host . ";port=" . $port . ";dbname=" . $database;
         $pdo = new PDO($dsn, $username, $password, array());
         $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $pdo->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
         $pdo->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
         $pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
         $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
         $pdo->query("SET NAMES '" . $charcter . "'");
         $DBQuery = new \Knee\DataBase\Query($pdo);
         static::$connections[$connect] = $DBQuery;
         return static::$connections[$connect];
     } catch (PDOException $e) {
         Error::e503(Lang::get('system.db.noconnect'));
     }
 }
Exemple #2
0
 /**
  * Старт маршрутизации
  */
 public static function start()
 {
     if (static::$start) {
         return false;
     } else {
         static::$start = true;
     }
     static::$record = true;
     static::$host = Request::host();
     static::$path = Request::path();
     static::$query = Request::query();
     static::$method = Request::method();
     if (preg_match('#^/index.php#i', static::$path)) {
         Error::e404();
     }
     if (preg_match('#^/public/#i', static::$path)) {
         Error::e404();
     }
     static::running();
     if (!static::$found) {
         if (mb_substr(static::$path, -1, 1) != '/') {
             $extension = pathinfo(static::$path, PATHINFO_EXTENSION);
             if ($extension == "") {
                 static::$path .= "/";
                 static::running();
                 if (static::$found) {
                     Redirect::r302(static::$path . (static::$query != '' ? '?' . static::$query : ''));
                 }
             }
         }
     }
     static::$record = false;
     if (static::$found) {
         static::render();
     } else {
         Error::e404();
     }
 }
Exemple #3
0
 /**
  * Рузультат работы
  *
  * Использует eval() т.к. так в PHP <=5.6 можно поймать Fatal Error
  * См. класс /knee/debug.php
  *
  * @return string
  */
 public function result()
 {
     ob_start();
     $__viewData = $this->data;
     extract($__viewData, EXTR_SKIP);
     $__eval = @eval('?>' . $this->template);
     if ($__eval === false and is_array(error_get_last())) {
         ob_end_clean_all();
         \Knee\Error::e503(\Knee\Lang::get('system.view.error-compile') . '<br>View: ' . $this->path);
     } else {
         return trim(ob_get_clean());
     }
 }