예제 #1
0
파일: controller.php 프로젝트: pnixx/boot
 /**
  * Обработка запроса, разбитие на: 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)));
 }
예제 #2
0
파일: assets.php 프로젝트: pnixx/boot
 /**
  * Чтение данных файла
  * @param $path
  * @throws Exception
  * @return string
  */
 public function readfile($path)
 {
     //Получаем расширение файла
     $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
     //Если расширение входим в массив
     if (in_array($ext, [$this->ext, 'scss'])) {
         if ($this->compile) {
             //SASS
             if ($ext == 'scss') {
                 //Компилируем SASS файл
                 $sass = new Sass();
                 $sass->setStyle(Sass::STYLE_COMPRESSED);
                 $sass->setIncludePath(APPLICATION_ROOT);
                 $sass->setComments(false);
                 $filename = pathinfo(APPLICATION_PATH . $path, PATHINFO_FILENAME);
                 file_put_contents('/tmp/' . $filename . '.css', $sass->compileFile($path));
                 //Добавляем префиксы
                 $result = system('postcss --use autoprefixer -o /tmp/' . $filename . '.out.css /tmp/' . $filename . '.css 2>&1', $r);
                 if ($result) {
                     throw new Boot_Exception($result);
                 } else {
                     $css = file_get_contents('/tmp/' . $filename . '.out.css');
                     unlink('/tmp/' . $filename . '.out.css');
                     unlink('/tmp/' . $filename . '.css');
                     return $css;
                 }
                 //Ruby SASS
                 //					//Компилируем sass
                 //					$filename = pathinfo(APPLICATION_PATH . $path, PATHINFO_FILENAME);
                 //					$return = system('sass -t compressed --sourcemap=none ' . escapeshellarg($path) . ' ' . 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);
                 //					}
                 //
                 //					//Выводим данные
                 //					return file_get_contents('/tmp/' . $filename . '_out.css');
             }
             //Выполняем для обычных css файлов
             return $this->compress(file_get_contents($path));
         } else {
             switch ($this->ext) {
                 case "css":
                     return "<link href='" . str_replace(APPLICATION_PATH, "", preg_replace('/\\.scss$/i', '.css', $path)) . "' rel='stylesheet' type='text/css'>" . PHP_EOL;
                     break;
                 case "js":
                     return "<script src='" . str_replace(APPLICATION_PATH, "", $path) . "' type=\"text/javascript\"></script>" . PHP_EOL;
                     break;
                 default:
                     throw new Exception("Wrong file extension");
             }
         }
     }
     return null;
 }