@@ -7,33 +7,33 @@ |
||
| 7 | 7 | private static $host; |
| 8 | 8 | private static $config; |
| 9 | 9 | |
| 10 | - public function __construct(){ |
|
| 10 | + public function __construct() { |
|
| 11 | 11 | # Config |
| 12 | 12 | self::$config = (new Config)->get(); |
| 13 | 13 | # Host |
| 14 | 14 | self::$host = parse_url('http://'.$_SERVER['HTTP_HOST']); |
| 15 | - if(isset(self::$host['host'])) self::$host = self::$host['host']; |
|
| 15 | + if (isset(self::$host['host'])) self::$host = self::$host['host']; |
|
| 16 | 16 | else self::$host = '/'; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - public function add($js){ |
|
| 20 | - if(!is_array($js)) $js = [$js]; |
|
| 21 | - self::$list = array_merge(self::$list,$js); |
|
| 19 | + public function add($js) { |
|
| 20 | + if (!is_array($js)) $js = [$js]; |
|
| 21 | + self::$list = array_merge(self::$list, $js); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public function get(){ |
|
| 24 | + public function get() { |
|
| 25 | 25 | $js = array_unique(self::$list); |
| 26 | - if(!empty($js)) $jsQuery = '?'.implode(':',$js); |
|
| 26 | + if (!empty($js)) $jsQuery = '?'.implode(':', $js); |
|
| 27 | 27 | else $jsQuery = ''; |
| 28 | 28 | return '<script async src="http://'.self::$host.'/javascript.js'.$jsQuery.'"></script>'; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function compile($query){ |
|
| 31 | + public function compile($query) { |
|
| 32 | 32 | $js = $query; |
| 33 | 33 | $code = ''; |
| 34 | - foreach($js as $name){ |
|
| 34 | + foreach ($js as $name) { |
|
| 35 | 35 | $file = self::$config['core']['js'].'/'.$name.'.js'; |
| 36 | - if(is_file($file)) $code .= file_get_contents($file); |
|
| 36 | + if (is_file($file)) $code .= file_get_contents($file); |
|
| 37 | 37 | } |
| 38 | 38 | $minifier = new \MatthiasMullie\Minify\JS(); |
| 39 | 39 | $minifier->add($code); |
@@ -5,28 +5,28 @@ |
||
| 5 | 5 | |
| 6 | 6 | private $requestUri = ''; |
| 7 | 7 | |
| 8 | - public function __construct(){ |
|
| 8 | + public function __construct() { |
|
| 9 | 9 | $this->requestUri = $_SERVER['REQUEST_URI']; |
| 10 | - $tmp = explode('/',$this->requiestUri); |
|
| 11 | - foreach($tmp as $key=>$value){ |
|
| 10 | + $tmp = explode('/', $this->requiestUri); |
|
| 11 | + foreach ($tmp as $key=>$value) { |
|
| 12 | 12 | $value = trim($value); |
| 13 | - if(empty($value)) unset($tmp[$key]); |
|
| 13 | + if (empty($value)) unset($tmp[$key]); |
|
| 14 | 14 | else $tmp[$key] = $value; |
| 15 | 15 | } |
| 16 | 16 | $tmp = array_values($tmp); |
| 17 | 17 | $this->requestUri = $tmp; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function full(){ |
|
| 21 | - return '/'.implode('/',$this->requestUri); |
|
| 20 | + public function full() { |
|
| 21 | + return '/'.implode('/', $this->requestUri); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public function part($number){ |
|
| 25 | - if(isset($this->requestUri[$number])) return (string) urldecode($this->requestUri[$number]); |
|
| 24 | + public function part($number) { |
|
| 25 | + if (isset($this->requestUri[$number])) return (string) urldecode($this->requestUri[$number]); |
|
| 26 | 26 | else return ''; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - public function host(){ |
|
| 29 | + public function host() { |
|
| 30 | 30 | return parse_url('http://'.$_SERVER['HTTP_HOST'])['host'] |
| 31 | 31 | } |
| 32 | 32 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | private static $keywords; |
| 17 | 17 | private static $uri; |
| 18 | 18 | |
| 19 | - public function __construct(){ |
|
| 19 | + public function __construct() { |
|
| 20 | 20 | # Config |
| 21 | 21 | self::$config = (new Config)->get(); |
| 22 | 22 | # Application |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | self::$uri = new Uri; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function view($name){ |
|
| 42 | + public function view($name) { |
|
| 43 | 43 | $file = $this->file($name); |
| 44 | - if(is_file($file)) require $file; |
|
| 44 | + if (is_file($file)) require $file; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public function page(){ |
|
| 47 | + public function page() { |
|
| 48 | 48 | # get file |
| 49 | 49 | $file = $this->file(); |
| 50 | 50 | # get content |
@@ -62,46 +62,46 @@ discard block |
||
| 62 | 62 | # get keywords |
| 63 | 63 | $keywords = self::$keywords->get(); |
| 64 | 64 | # include for page |
| 65 | - $content = preg_replace('/<head>/',"<head>$keywords",$content); |
|
| 66 | - $content = preg_replace('/<head>/',"<head>$description",$content); |
|
| 67 | - $content = preg_replace('/<head>/',"<head>$title",$content); |
|
| 68 | - $content = preg_replace('/<\/head>/',"$css</head>",$content); |
|
| 69 | - $content = preg_replace('/<\/body>/',"$js</body>",$content); |
|
| 65 | + $content = preg_replace('/<head>/', "<head>$keywords", $content); |
|
| 66 | + $content = preg_replace('/<head>/', "<head>$description", $content); |
|
| 67 | + $content = preg_replace('/<head>/', "<head>$title", $content); |
|
| 68 | + $content = preg_replace('/<\/head>/', "$css</head>", $content); |
|
| 69 | + $content = preg_replace('/<\/body>/', "$js</body>", $content); |
|
| 70 | 70 | $minify = new MinifyHTML($content); |
| 71 | 71 | $content = $minify->compress(); |
| 72 | 72 | echo $content; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - public function js($query){ |
|
| 75 | + public function js($query) { |
|
| 76 | 76 | echo self::$js->compile($query); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | # $type - page,view |
| 80 | - public function file($name=false){ |
|
| 81 | - if($name === false){ |
|
| 80 | + public function file($name = false) { |
|
| 81 | + if ($name === false) { |
|
| 82 | 82 | $path = self::$config['core']['page']; |
| 83 | 83 | } else { |
| 84 | 84 | $path = self::$config['core']['view'].'/'.$name; |
| 85 | 85 | } |
| 86 | 86 | # Route |
| 87 | 87 | $uri = self::$path; |
| 88 | - array_push($uri,''); |
|
| 89 | - foreach($uri as $key=>$value){ if(empty(trim($value))) { unset($uri[$key]); continue; } } |
|
| 88 | + array_push($uri, ''); |
|
| 89 | + foreach ($uri as $key=>$value) { if (empty(trim($value))) { unset($uri[$key]); continue; } } |
|
| 90 | 90 | $uri = array_values($uri); |
| 91 | 91 | $isFile = null; |
| 92 | 92 | $currentUri = null; |
| 93 | 93 | $filePhtml = null; |
| 94 | - for($i=count($uri)-1; $i>=0; $i--){ |
|
| 95 | - $nextUri = implode('/',array_slice($uri,0,$i+1)); |
|
| 96 | - $getFile = function($type) use($path,$nextUri){ |
|
| 94 | + for ($i = count($uri)-1; $i>=0; $i--) { |
|
| 95 | + $nextUri = implode('/', array_slice($uri, 0, $i+1)); |
|
| 96 | + $getFile = function($type) use($path, $nextUri){ |
|
| 97 | 97 | $file = $path.'/'.$nextUri.'/index.'.$type; |
| 98 | - if(is_file($file)) return $file; |
|
| 98 | + if (is_file($file)) return $file; |
|
| 99 | 99 | return null; |
| 100 | 100 | }; |
| 101 | 101 | $filePhtml = $getFile('phtml'); |
| 102 | - if($filePhtml) { $currentUri = $nextUri; break; } |
|
| 102 | + if ($filePhtml) { $currentUri = $nextUri; break; } |
|
| 103 | 103 | } |
| 104 | - if($filePhtml === null) { |
|
| 104 | + if ($filePhtml === null) { |
|
| 105 | 105 | $filePhtml = $path.'/index.phtml'; |
| 106 | 106 | } |
| 107 | 107 | return $filePhtml; |