Exemple #1
0
 /**
  * Получаем инстанс
  * @static
  * @return Boot_Routes
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof Boot_Routes) {
         self::$_instance = new Boot_Routes();
     }
     return self::$_instance;
 }
Exemple #2
0
 /**
  * Инициализация
  * @throws Exception
  * @return void
  */
 public function run()
 {
     $this->root = realpath(dirname(__FILE__));
     header("Content-type: text/html; charset=UTF-8");
     //Загружаем классы
     require_once 'boot/exception/exception.php';
     require_once 'boot/exception/db.php';
     require_once 'boot/cookie.php';
     require_once 'boot/skey.php';
     require_once 'boot/routes.php';
     require_once 'boot/flash.php';
     require_once 'boot/mail.php';
     require_once 'boot/assets.php';
     require_once 'boot/params.php';
     //Инклудим треды
     require_once SYSTEM_PATH . '/boot/trait/controller.php';
     foreach (glob(SYSTEM_PATH . '/boot/trait/' . '*.php') as $path) {
         require_once $path;
     }
     //Инклудим абстрактные классы
     foreach (glob(SYSTEM_PATH . '/boot/abstract/' . '*.php') as $path) {
         require_once $path;
     }
     //Инклудим интерфейсы
     foreach (glob(SYSTEM_PATH . '/boot/interface/' . '*.php') as $path) {
         require_once $path;
     }
     require_once 'library/log.php';
     //Устанавливаем отлавливатели ошибок
     set_error_handler('Boot_Exception::err_handler');
     set_exception_handler("Boot_Exception::ex");
     ob_start("Boot_Exception::shutdown");
     //Загружаем конфиг
     $this->config();
     //Создаём маршруты
     Boot_Routes::getInstance();
     //Инициализируем защищённый ключ
     Boot_Skey::getInstance();
     //Получаем имя шаблона
     $this->_nameLayout = $this->config->default->layout ? $this->config->default->layout : "index";
     //Загружаем драйвер БД
     $this->load_model();
     //Загружаем модель предствлений
     $this->load_view();
     //Загружаем модель контроллера
     $this->load_controller();
     //Устанавливаем путь подключения моделей
     set_include_path(APPLICATION_PATH);
     spl_autoload_register(array("Boot", "autoload"));
     //Загружаем библиотеки
     $this->load_library();
     //Debug
     if (preg_match("/\\.(css|js)\$/", $_SERVER['REQUEST_URI']) == false) {
         $this->debug(PHP_EOL . PHP_EOL . $_SERVER['REQUEST_METHOD'] . " \"" . $_SERVER['REQUEST_URI'] . "\" for " . self::getRealIp() . " at " . date("Y-m-d H:i:s O"));
     }
     try {
         //Инициализируем контроллер
         $this->init_controller();
         //Если не отключали вьюху, запускаем
         if ($this->_view) {
             $view = $this->init_view();
         } else {
             $view = null;
         }
         //Загружаем шаблон
         $this->load_layout($view);
         //Выводим содержимое буфера
         ob_end_flush();
     } catch (Exception $e) {
         ob_end_clean();
         throw $e;
     }
     //Завершение работы скрипта
     $this->end();
 }
Exemple #3
0
 /**
  * Обработка запроса, разбитие на: module/controller/action
  * @throws Boot_Exception
  */
 private function getQuery()
 {
     $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $_SERVER['REQUEST_URI'];
     if (preg_match("/^(\\/[^\\/\\.]+)\\.+\$/", $path_info, $match) && count($match) > 1) {
         $this->_redirect($match[1]);
     }
     //Если страница пытается загрузкить из асетов файл
     if (APPLICATION_ENV == 'development' && preg_match("/^\\/assets\\/(css|js)\\/.*?\\.(css|js)\$/", $path_info, $matches)) {
         switch ($matches[1]) {
             case "css":
                 header("Content-Type: text/css");
                 break;
             case "js":
                 header("Content-Type: application/javascript");
                 break;
             default:
                 throw new Boot_Exception('Unknown file extension');
         }
         //Если расширение css и файл найден
         if (file_exists(APPLICATION_PATH . $path_info) || $matches[1] == 'js') {
             echo file_get_contents(APPLICATION_PATH . $path_info);
         } else {
             //Если файл не найден, пробуем найти scss
             $filename = pathinfo(APPLICATION_PATH . $path_info, PATHINFO_FILENAME);
             $scss = pathinfo(APPLICATION_PATH . $path_info, PATHINFO_DIRNAME) . '/' . $filename . '.scss';
             //Если файл существует
             if (file_exists($scss)) {
                 //Компилируем SASS файл
                 $sass = new Sass();
                 $sass->setStyle(Sass::STYLE_EXPANDED);
                 $sass->setIncludePath(APPLICATION_ROOT);
                 $sass->setComments(true);
                 file_put_contents('/tmp/' . $filename . '.css', $sass->compileFile($scss));
                 //Добавляем префиксы
                 $result = system('postcss --use autoprefixer -o /tmp/' . $filename . '.out.css /tmp/' . $filename . '.css', $r);
                 if ($result) {
                     throw new Boot_Exception($result);
                 } else {
                     echo file_get_contents('/tmp/' . $filename . '.out.css');
                     unlink('/tmp/' . $filename . '.out.css');
                     unlink('/tmp/' . $filename . '.css');
                 }
                 //					$autoprefixer = new Autoprefixer(['ff > 2', '> 2%', 'ie 8']);
                 //					echo $autoprefixer->compile($css);
                 //Ruby Sass
                 //					//Компилируем sass
                 //					$return = system('sass -l -t expanded --sourcemap=none ' . escapeshellarg($scss) . ' ' . escapeshellarg('/tmp/' . $filename . '.css') . ' 2>&1');
                 //					if( $return ) {
                 //						throw new Boot_Exception('sass error: ' . $return);
                 //					}
                 //
                 //					//Добавляем префиксы
                 //					$return = system('postcss --use autoprefixer /tmp/' . $filename . '.css -o /tmp/' . $filename . '_out.css 2>&1');
                 //					if( $return ) {
                 //						throw new Boot_Exception('autoprefixer error: ' . $return);
                 //					}
                 //
                 //					//Выводим данные
                 //					readfile('/tmp/' . $filename . '_out.css');
             } else {
                 throw new Boot_Exception('File ' . $path_info . ' not found', 404);
             }
         }
         exit;
     }
     //Получаем строку запроса
     if ($_SERVER['QUERY_STRING']) {
         parse_str($_SERVER['QUERY_STRING'], $this->_request);
     }
     $query = $path_info;
     if (preg_match("/^(.*?)\\?/", $path_info, $match)) {
         $query = $match[1];
     }
     //Сохраняем параметры запроса
     $this->_param = Boot_Routes::getInstance()->getParam(substr($query, 1, strlen($query)));
 }