@@ -85,6 +85,10 @@ |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | # $type - page,view |
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 88 | 92 | public function file($name=false){ |
| 89 | 93 | if($name === false){ |
| 90 | 94 | $path = self::$config['core']['page']; |
@@ -100,17 +100,17 @@ |
||
| 100 | 100 | $currentUri = null; |
| 101 | 101 | $filePhtml = null; |
| 102 | 102 | for($i=count($uri)-1; $i>=0; $i--){ |
| 103 | - $nextUri = implode('/',array_slice($uri,0,$i+1)); |
|
| 104 | - $getFile = function($type) use($path,$nextUri){ |
|
| 103 | + $nextUri = implode('/',array_slice($uri,0,$i+1)); |
|
| 104 | + $getFile = function($type) use($path,$nextUri){ |
|
| 105 | 105 | $file = $path.'/'.$nextUri.'/index.'.$type; |
| 106 | 106 | if(is_file($file)) return $file; |
| 107 | 107 | return null; |
| 108 | - }; |
|
| 109 | - $filePhtml = $getFile('phtml'); |
|
| 110 | - if($filePhtml) { $currentUri = $nextUri; break; } |
|
| 108 | + }; |
|
| 109 | + $filePhtml = $getFile('phtml'); |
|
| 110 | + if($filePhtml) { $currentUri = $nextUri; break; } |
|
| 111 | 111 | } |
| 112 | 112 | if($filePhtml === null) { |
| 113 | - $filePhtml = $path.'/index.phtml'; |
|
| 113 | + $filePhtml = $path.'/index.phtml'; |
|
| 114 | 114 | } |
| 115 | 115 | return $filePhtml; |
| 116 | 116 | } |
@@ -16,16 +16,16 @@ 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 | # Host |
| 23 | 23 | self::$host = parse_url('http://'.$_SERVER['HTTP_HOST'])['host']; |
| 24 | 24 | # Url |
| 25 | - self::$path = explode('/',parse_url(urldecode($_SERVER['REQUEST_URI']))['path']); |
|
| 26 | - foreach(self::$path as $key=>$value){ |
|
| 25 | + self::$path = explode('/', parse_url(urldecode($_SERVER['REQUEST_URI']))['path']); |
|
| 26 | + foreach (self::$path as $key=>$value) { |
|
| 27 | 27 | $value = trim($value); |
| 28 | - if(empty($value)) unset(self::$path[$key]); |
|
| 28 | + if (empty($value)) unset(self::$path[$key]); |
|
| 29 | 29 | } |
| 30 | 30 | self::$path = array_values(self::$path); |
| 31 | 31 | # Application |
@@ -45,20 +45,20 @@ discard block |
||
| 45 | 45 | # Keywords |
| 46 | 46 | self::$keywords = new Keywords; |
| 47 | 47 | # Uri |
| 48 | - self::$uri = explode('/',$_SERVER['REQUEST_URI']); |
|
| 49 | - foreach(self::$uri as $key=>$value){ |
|
| 50 | - if(empty($value)) unset(self::$uri[$key]); |
|
| 48 | + self::$uri = explode('/', $_SERVER['REQUEST_URI']); |
|
| 49 | + foreach (self::$uri as $key=>$value) { |
|
| 50 | + if (empty($value)) unset(self::$uri[$key]); |
|
| 51 | 51 | else self::$uri[$key] = urldecode($value); |
| 52 | 52 | } |
| 53 | 53 | self::$uri = array_values(self::$uri); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public function view($name){ |
|
| 56 | + public function view($name) { |
|
| 57 | 57 | $file = $this->file($name); |
| 58 | - if(is_file($file)) require $file; |
|
| 58 | + if (is_file($file)) require $file; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - public function page(){ |
|
| 61 | + public function page() { |
|
| 62 | 62 | # get file |
| 63 | 63 | $file = $this->file(); |
| 64 | 64 | # get content |
@@ -76,40 +76,40 @@ discard block |
||
| 76 | 76 | # get keywords |
| 77 | 77 | $keywords = self::$keywords->get(); |
| 78 | 78 | # include for page |
| 79 | - $content = preg_replace('/<head>/',"<head>$keywords",$content); |
|
| 80 | - $content = preg_replace('/<head>/',"<head>$description",$content); |
|
| 81 | - $content = preg_replace('/<head>/',"<head>$title",$content); |
|
| 82 | - $content = preg_replace('/<\/head>/',"$css</head>",$content); |
|
| 83 | - $content = preg_replace('/<\/body>/',"$js</body>",$content); |
|
| 79 | + $content = preg_replace('/<head>/', "<head>$keywords", $content); |
|
| 80 | + $content = preg_replace('/<head>/', "<head>$description", $content); |
|
| 81 | + $content = preg_replace('/<head>/', "<head>$title", $content); |
|
| 82 | + $content = preg_replace('/<\/head>/', "$css</head>", $content); |
|
| 83 | + $content = preg_replace('/<\/body>/', "$js</body>", $content); |
|
| 84 | 84 | echo $content; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | # $type - page,view |
| 88 | - public function file($name=false){ |
|
| 89 | - if($name === false){ |
|
| 88 | + public function file($name = false) { |
|
| 89 | + if ($name === false) { |
|
| 90 | 90 | $path = self::$config['core']['page']; |
| 91 | 91 | } else { |
| 92 | 92 | $path = self::$config['core']['view'].'/'.$name; |
| 93 | 93 | } |
| 94 | 94 | # Route |
| 95 | 95 | $uri = self::$path; |
| 96 | - array_push($uri,''); |
|
| 97 | - foreach($uri as $key=>$value){ if(empty(trim($value))) { unset($uri[$key]); continue; } } |
|
| 96 | + array_push($uri, ''); |
|
| 97 | + foreach ($uri as $key=>$value) { if (empty(trim($value))) { unset($uri[$key]); continue; } } |
|
| 98 | 98 | $uri = array_values($uri); |
| 99 | 99 | $isFile = null; |
| 100 | 100 | $currentUri = null; |
| 101 | 101 | $filePhtml = null; |
| 102 | - for($i=count($uri)-1; $i>=0; $i--){ |
|
| 103 | - $nextUri = implode('/',array_slice($uri,0,$i+1)); |
|
| 104 | - $getFile = function($type) use($path,$nextUri){ |
|
| 102 | + for ($i = count($uri)-1; $i>=0; $i--) { |
|
| 103 | + $nextUri = implode('/', array_slice($uri, 0, $i+1)); |
|
| 104 | + $getFile = function($type) use($path, $nextUri){ |
|
| 105 | 105 | $file = $path.'/'.$nextUri.'/index.'.$type; |
| 106 | - if(is_file($file)) return $file; |
|
| 106 | + if (is_file($file)) return $file; |
|
| 107 | 107 | return null; |
| 108 | 108 | }; |
| 109 | 109 | $filePhtml = $getFile('phtml'); |
| 110 | - if($filePhtml) { $currentUri = $nextUri; break; } |
|
| 110 | + if ($filePhtml) { $currentUri = $nextUri; break; } |
|
| 111 | 111 | } |
| 112 | - if($filePhtml === null) { |
|
| 112 | + if ($filePhtml === null) { |
|
| 113 | 113 | $filePhtml = $path.'/index.phtml'; |
| 114 | 114 | } |
| 115 | 115 | return $filePhtml; |
@@ -25,7 +25,9 @@ discard block |
||
| 25 | 25 | self::$path = explode('/',parse_url(urldecode($_SERVER['REQUEST_URI']))['path']); |
| 26 | 26 | foreach(self::$path as $key=>$value){ |
| 27 | 27 | $value = trim($value); |
| 28 | - if(empty($value)) unset(self::$path[$key]); |
|
| 28 | + if(empty($value)) { |
|
| 29 | + unset(self::$path[$key]); |
|
| 30 | + } |
|
| 29 | 31 | } |
| 30 | 32 | self::$path = array_values(self::$path); |
| 31 | 33 | # Application |
@@ -47,15 +49,20 @@ discard block |
||
| 47 | 49 | # Uri |
| 48 | 50 | self::$uri = explode('/',$_SERVER['REQUEST_URI']); |
| 49 | 51 | foreach(self::$uri as $key=>$value){ |
| 50 | - if(empty($value)) unset(self::$uri[$key]); |
|
| 51 | - else self::$uri[$key] = urldecode($value); |
|
| 52 | + if(empty($value)) { |
|
| 53 | + unset(self::$uri[$key]); |
|
| 54 | + } else { |
|
| 55 | + self::$uri[$key] = urldecode($value); |
|
| 56 | + } |
|
| 52 | 57 | } |
| 53 | 58 | self::$uri = array_values(self::$uri); |
| 54 | 59 | } |
| 55 | 60 | |
| 56 | 61 | public function view($name){ |
| 57 | 62 | $file = $this->file($name); |
| 58 | - if(is_file($file)) require $file; |
|
| 63 | + if(is_file($file)) { |
|
| 64 | + require $file; |
|
| 65 | + } |
|
| 59 | 66 | } |
| 60 | 67 | |
| 61 | 68 | public function page(){ |
@@ -103,7 +110,9 @@ discard block |
||
| 103 | 110 | $nextUri = implode('/',array_slice($uri,0,$i+1)); |
| 104 | 111 | $getFile = function($type) use($path,$nextUri){ |
| 105 | 112 | $file = $path.'/'.$nextUri.'/index.'.$type; |
| 106 | - if(is_file($file)) return $file; |
|
| 113 | + if(is_file($file)) { |
|
| 114 | + return $file; |
|
| 115 | + } |
|
| 107 | 116 | return null; |
| 108 | 117 | }; |
| 109 | 118 | $filePhtml = $getFile('phtml'); |
@@ -7,23 +7,23 @@ |
||
| 7 | 7 | private static $config; |
| 8 | 8 | private static $application = []; |
| 9 | 9 | |
| 10 | - public function __construct(){ |
|
| 10 | + public function __construct() { |
|
| 11 | 11 | self::$config = (new Config)->get(); |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public function __get($name){ |
|
| 15 | - array_push(self::$application,$name); |
|
| 14 | + public function __get($name) { |
|
| 15 | + array_push(self::$application, $name); |
|
| 16 | 16 | return (new self); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - public function __call($name,$value){ |
|
| 20 | - array_push(self::$application,$name); |
|
| 21 | - $file = implode('/',self::$application); |
|
| 19 | + public function __call($name, $value) { |
|
| 20 | + array_push(self::$application, $name); |
|
| 21 | + $file = implode('/', self::$application); |
|
| 22 | 22 | $file = self::$config['core']['apps'].'/'.$file.'.php'; |
| 23 | 23 | self::$application = []; |
| 24 | - if(is_file($file)) { |
|
| 24 | + if (is_file($file)) { |
|
| 25 | 25 | $result = require($file); |
| 26 | - if(is_callable($result)) $result = call_user_func_array($result,$value); |
|
| 26 | + if (is_callable($result)) $result = call_user_func_array($result, $value); |
|
| 27 | 27 | return $result; |
| 28 | 28 | } |
| 29 | 29 | } |
@@ -23,7 +23,9 @@ |
||
| 23 | 23 | self::$application = []; |
| 24 | 24 | if(is_file($file)) { |
| 25 | 25 | $result = require($file); |
| 26 | - if(is_callable($result)) $result = call_user_func_array($result,$value); |
|
| 26 | + if(is_callable($result)) { |
|
| 27 | + $result = call_user_func_array($result,$value); |
|
| 28 | + } |
|
| 27 | 29 | return $result; |
| 28 | 30 | } |
| 29 | 31 | } |
@@ -5,11 +5,11 @@ |
||
| 5 | 5 | |
| 6 | 6 | public static $config = []; |
| 7 | 7 | |
| 8 | - public function __construct($config=[]){ |
|
| 9 | - self::$config = array_merge(self::$config,$config); |
|
| 8 | + public function __construct($config = []) { |
|
| 9 | + self::$config = array_merge(self::$config, $config); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | - public function get(){ |
|
| 12 | + public function get() { |
|
| 13 | 13 | return self::$config; |
| 14 | 14 | } |
| 15 | 15 | |
@@ -7,31 +7,31 @@ |
||
| 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($css){ |
|
| 20 | - if(!is_array($css)) $css = [$css]; |
|
| 21 | - self::$list = array_merge(self::$list,$css); |
|
| 19 | + public function add($css) { |
|
| 20 | + if (!is_array($css)) $css = [$css]; |
|
| 21 | + self::$list = array_merge(self::$list, $css); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public function get(){ |
|
| 24 | + public function get() { |
|
| 25 | 25 | $css = array_unique(self::$list); |
| 26 | 26 | $code = ''; |
| 27 | - foreach($css as $name){ |
|
| 27 | + foreach ($css as $name) { |
|
| 28 | 28 | $file = self::$config['core']['css'].'/'.$name.'.css'; |
| 29 | - if(is_file($file)) $code .= file_get_contents($file); |
|
| 29 | + if (is_file($file)) $code .= file_get_contents($file); |
|
| 30 | 30 | } |
| 31 | 31 | return "<style>$code</style>"; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function compile(){ |
|
| 34 | + public function compile() { |
|
| 35 | 35 | # ... |
| 36 | 36 | } |
| 37 | 37 | |
@@ -12,12 +12,17 @@ discard block |
||
| 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']; |
|
| 16 | - else self::$host = '/'; |
|
| 15 | + if(isset(self::$host['host'])) { |
|
| 16 | + self::$host = self::$host['host']; |
|
| 17 | + } else { |
|
| 18 | + self::$host = '/'; |
|
| 19 | + } |
|
| 17 | 20 | } |
| 18 | 21 | |
| 19 | 22 | public function add($css){ |
| 20 | - if(!is_array($css)) $css = [$css]; |
|
| 23 | + if(!is_array($css)) { |
|
| 24 | + $css = [$css]; |
|
| 25 | + } |
|
| 21 | 26 | self::$list = array_merge(self::$list,$css); |
| 22 | 27 | } |
| 23 | 28 | |
@@ -26,7 +31,9 @@ discard block |
||
| 26 | 31 | $code = ''; |
| 27 | 32 | foreach($css as $name){ |
| 28 | 33 | $file = self::$config['core']['css'].'/'.$name.'.css'; |
| 29 | - if(is_file($file)) $code .= file_get_contents($file); |
|
| 34 | + if(is_file($file)) { |
|
| 35 | + $code .= file_get_contents($file); |
|
| 36 | + } |
|
| 30 | 37 | } |
| 31 | 38 | return "<style>$code</style>"; |
| 32 | 39 | } |
@@ -5,19 +5,19 @@ |
||
| 5 | 5 | |
| 6 | 6 | private static $memory = []; |
| 7 | 7 | |
| 8 | - public function add($title){ |
|
| 9 | - if(!is_array($title)) $title = [$title]; |
|
| 10 | - self::$memory = array_merge(self::$memory,$title); |
|
| 8 | + public function add($title) { |
|
| 9 | + if (!is_array($title)) $title = [$title]; |
|
| 10 | + self::$memory = array_merge(self::$memory, $title); |
|
| 11 | 11 | return $this; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public function get(){ |
|
| 14 | + public function get() { |
|
| 15 | 15 | self::$memory = array_reverse(self::$memory); |
| 16 | - foreach(self::$memory as $key=>$value){ |
|
| 16 | + foreach (self::$memory as $key=>$value) { |
|
| 17 | 17 | $value = urldecode($value); |
| 18 | 18 | self::$memory[$key] = $value; |
| 19 | 19 | } |
| 20 | - return '<meta name="description" content="'.implode(' ',self::$memory).'">'; |
|
| 20 | + return '<meta name="description" content="'.implode(' ', self::$memory).'">'; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | } |
@@ -6,7 +6,9 @@ |
||
| 6 | 6 | private static $memory = []; |
| 7 | 7 | |
| 8 | 8 | public function add($title){ |
| 9 | - if(!is_array($title)) $title = [$title]; |
|
| 9 | + if(!is_array($title)) { |
|
| 10 | + $title = [$title]; |
|
| 11 | + } |
|
| 10 | 12 | self::$memory = array_merge(self::$memory,$title); |
| 11 | 13 | return $this; |
| 12 | 14 | } |
@@ -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 | 26 | $code = ''; |
| 27 | - foreach($js as $name){ |
|
| 27 | + foreach ($js as $name) { |
|
| 28 | 28 | $file = self::$config['core']['js'].'/'.$name.'.js'; |
| 29 | - if(is_file($file)) $code .= file_get_contents($file); |
|
| 29 | + if (is_file($file)) $code .= file_get_contents($file); |
|
| 30 | 30 | } |
| 31 | 31 | $cache = self::$config['core']['js'].'/../cache/javascript.js'; |
| 32 | - file_put_contents($cache,$code); |
|
| 32 | + file_put_contents($cache, $code); |
|
| 33 | 33 | return '<script async src="http://'.self::$host.'/cache/javascript.js"></script>'; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function compile(){ |
|
| 36 | + public function compile() { |
|
| 37 | 37 | # ... |
| 38 | 38 | } |
| 39 | 39 | |
@@ -12,12 +12,17 @@ discard block |
||
| 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']; |
|
| 16 | - else self::$host = '/'; |
|
| 15 | + if(isset(self::$host['host'])) { |
|
| 16 | + self::$host = self::$host['host']; |
|
| 17 | + } else { |
|
| 18 | + self::$host = '/'; |
|
| 19 | + } |
|
| 17 | 20 | } |
| 18 | 21 | |
| 19 | 22 | public function add($js){ |
| 20 | - if(!is_array($js)) $js = [$js]; |
|
| 23 | + if(!is_array($js)) { |
|
| 24 | + $js = [$js]; |
|
| 25 | + } |
|
| 21 | 26 | self::$list = array_merge(self::$list,$js); |
| 22 | 27 | } |
| 23 | 28 | |
@@ -26,7 +31,9 @@ discard block |
||
| 26 | 31 | $code = ''; |
| 27 | 32 | foreach($js as $name){ |
| 28 | 33 | $file = self::$config['core']['js'].'/'.$name.'.js'; |
| 29 | - if(is_file($file)) $code .= file_get_contents($file); |
|
| 34 | + if(is_file($file)) { |
|
| 35 | + $code .= file_get_contents($file); |
|
| 36 | + } |
|
| 30 | 37 | } |
| 31 | 38 | $cache = self::$config['core']['js'].'/../cache/javascript.js'; |
| 32 | 39 | file_put_contents($cache,$code); |
@@ -5,19 +5,19 @@ |
||
| 5 | 5 | |
| 6 | 6 | private static $memory = []; |
| 7 | 7 | |
| 8 | - public function add($title){ |
|
| 9 | - if(!is_array($title)) $title = [$title]; |
|
| 10 | - self::$memory = array_merge(self::$memory,$title); |
|
| 8 | + public function add($title) { |
|
| 9 | + if (!is_array($title)) $title = [$title]; |
|
| 10 | + self::$memory = array_merge(self::$memory, $title); |
|
| 11 | 11 | return $this; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public function get(){ |
|
| 14 | + public function get() { |
|
| 15 | 15 | self::$memory = array_reverse(self::$memory); |
| 16 | - foreach(self::$memory as $key=>$value){ |
|
| 16 | + foreach (self::$memory as $key=>$value) { |
|
| 17 | 17 | $value = urldecode($value); |
| 18 | 18 | self::$memory[$key] = $value; |
| 19 | 19 | } |
| 20 | - return '<meta name="keywords" content="'.implode(',',self::$memory).'">'; |
|
| 20 | + return '<meta name="keywords" content="'.implode(',', self::$memory).'">'; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | } |
@@ -6,7 +6,9 @@ |
||
| 6 | 6 | private static $memory = []; |
| 7 | 7 | |
| 8 | 8 | public function add($title){ |
| 9 | - if(!is_array($title)) $title = [$title]; |
|
| 9 | + if(!is_array($title)) { |
|
| 10 | + $title = [$title]; |
|
| 11 | + } |
|
| 10 | 12 | self::$memory = array_merge(self::$memory,$title); |
| 11 | 13 | return $this; |
| 12 | 14 | } |
@@ -3,55 +3,55 @@ |
||
| 3 | 3 | |
| 4 | 4 | class Site { |
| 5 | 5 | |
| 6 | - public function __construct(){ |
|
| 6 | + public function __construct() { |
|
| 7 | 7 | |
| 8 | 8 | $config = (new Config)->get(); |
| 9 | 9 | |
| 10 | - if(!isset($_SERVER['HTTP_ACCEPT'])) $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 11 | - $acceptSrc = explode(',',$_SERVER['HTTP_ACCEPT']); |
|
| 12 | - foreach($acceptSrc as $key=>$value){ |
|
| 13 | - $value = explode('/',$value); |
|
| 14 | - $value[1] = explode(';',$value[1]); |
|
| 10 | + if (!isset($_SERVER['HTTP_ACCEPT'])) $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 11 | + $acceptSrc = explode(',', $_SERVER['HTTP_ACCEPT']); |
|
| 12 | + foreach ($acceptSrc as $key=>$value) { |
|
| 13 | + $value = explode('/', $value); |
|
| 14 | + $value[1] = explode(';', $value[1]); |
|
| 15 | 15 | $name = array_shift($value[1]); |
| 16 | 16 | $data = []; |
| 17 | - foreach($value[1] as $k=>$v){ |
|
| 18 | - $v = explode('=',$v); |
|
| 17 | + foreach ($value[1] as $k=>$v) { |
|
| 18 | + $v = explode('=', $v); |
|
| 19 | 19 | $data[$v[0]] = $v[1]; |
| 20 | 20 | } |
| 21 | 21 | $accept[$value[0]][$name] = $data; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - unset($acceptSrc,$key,$value,$name,$data,$k,$v); |
|
| 24 | + unset($acceptSrc, $key, $value, $name, $data, $k, $v); |
|
| 25 | 25 | |
| 26 | 26 | header('Access-Control-Allow-Origin: *'); |
| 27 | 27 | header('Access-Control-Max-Age: 31556926'); |
| 28 | 28 | header('Access-Control-Allow-Credentials: true'); |
| 29 | 29 | header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT'); |
| 30 | 30 | |
| 31 | - if(isset($accept['application']['view'])){ |
|
| 31 | + if (isset($accept['application']['view'])) { |
|
| 32 | 32 | header('Content-Type: text/html'); |
| 33 | 33 | (new RestApi)->view(); |
| 34 | - } else if(isset($accept['application']['widget'])){ |
|
| 34 | + } else if (isset($accept['application']['widget'])) { |
|
| 35 | 35 | header('Content-Type: text/html'); |
| 36 | 36 | (new RestApi)->widget(); |
| 37 | - } else if(isset($accept['application']['apps'])){ |
|
| 37 | + } else if (isset($accept['application']['apps'])) { |
|
| 38 | 38 | header('Content-Type: application/json'); |
| 39 | - $query = json_decode(file_get_contents('php://input'),1); |
|
| 39 | + $query = json_decode(file_get_contents('php://input'), 1); |
|
| 40 | 40 | $result = []; |
| 41 | - foreach($query as $method=>$params){ |
|
| 41 | + foreach ($query as $method=>$params) { |
|
| 42 | 42 | $stableParams = []; |
| 43 | 43 | $file = $config['core']['apps'].'/'.$method.'.php'; |
| 44 | 44 | $func = require_once($file); |
| 45 | 45 | $reflection = new \ReflectionFunction($func); |
| 46 | - foreach($reflection->getParameters() as $key=>$value){ |
|
| 47 | - if(isset($params[$value->name])) $stableParams[$value->name] = $params[$value->name]; |
|
| 46 | + foreach ($reflection->getParameters() as $key=>$value) { |
|
| 47 | + if (isset($params[$value->name])) $stableParams[$value->name] = $params[$value->name]; |
|
| 48 | 48 | else $stableParams[$value->name] = null; |
| 49 | 49 | } |
| 50 | - $name = explode('/',$method); |
|
| 50 | + $name = explode('/', $method); |
|
| 51 | 51 | $count = count($name)-1; |
| 52 | 52 | $app = new Application; |
| 53 | - foreach($name as $key=>$var){ |
|
| 54 | - if($count == $key) $app = call_user_method_array($var,$app,$stableParams); |
|
| 53 | + foreach ($name as $key=>$var) { |
|
| 54 | + if ($count == $key) $app = call_user_method_array($var, $app, $stableParams); |
|
| 55 | 55 | else $app = $app->{$var}; |
| 56 | 56 | } |
| 57 | 57 | $result[$method] = $app; |
@@ -7,7 +7,9 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | $config = (new Config)->get(); |
| 9 | 9 | |
| 10 | - if(!isset($_SERVER['HTTP_ACCEPT'])) $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 10 | + if(!isset($_SERVER['HTTP_ACCEPT'])) { |
|
| 11 | + $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 12 | + } |
|
| 11 | 13 | $acceptSrc = explode(',',$_SERVER['HTTP_ACCEPT']); |
| 12 | 14 | foreach($acceptSrc as $key=>$value){ |
| 13 | 15 | $value = explode('/',$value); |
@@ -44,15 +46,21 @@ discard block |
||
| 44 | 46 | $func = require_once($file); |
| 45 | 47 | $reflection = new \ReflectionFunction($func); |
| 46 | 48 | foreach($reflection->getParameters() as $key=>$value){ |
| 47 | - if(isset($params[$value->name])) $stableParams[$value->name] = $params[$value->name]; |
|
| 48 | - else $stableParams[$value->name] = null; |
|
| 49 | + if(isset($params[$value->name])) { |
|
| 50 | + $stableParams[$value->name] = $params[$value->name]; |
|
| 51 | + } else { |
|
| 52 | + $stableParams[$value->name] = null; |
|
| 53 | + } |
|
| 49 | 54 | } |
| 50 | 55 | $name = explode('/',$method); |
| 51 | 56 | $count = count($name)-1; |
| 52 | 57 | $app = new Application; |
| 53 | 58 | foreach($name as $key=>$var){ |
| 54 | - if($count == $key) $app = call_user_method_array($var,$app,$stableParams); |
|
| 55 | - else $app = $app->{$var}; |
|
| 59 | + if($count == $key) { |
|
| 60 | + $app = call_user_method_array($var,$app,$stableParams); |
|
| 61 | + } else { |
|
| 62 | + $app = $app->{$var}; |
|
| 63 | + } |
|
| 56 | 64 | } |
| 57 | 65 | $result[$method] = $app; |
| 58 | 66 | } |
@@ -5,19 +5,19 @@ |
||
| 5 | 5 | |
| 6 | 6 | private static $memory = []; |
| 7 | 7 | |
| 8 | - public function add($title){ |
|
| 9 | - if(!is_array($title)) $title = [$title]; |
|
| 10 | - self::$memory = array_merge(self::$memory,$title); |
|
| 8 | + public function add($title) { |
|
| 9 | + if (!is_array($title)) $title = [$title]; |
|
| 10 | + self::$memory = array_merge(self::$memory, $title); |
|
| 11 | 11 | return $this; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public function get(){ |
|
| 14 | + public function get() { |
|
| 15 | 15 | self::$memory = array_reverse(self::$memory); |
| 16 | - foreach(self::$memory as $key=>$value){ |
|
| 16 | + foreach (self::$memory as $key=>$value) { |
|
| 17 | 17 | $value = urldecode($value); |
| 18 | 18 | self::$memory[$key] = $value; |
| 19 | 19 | } |
| 20 | - return '<title>'.implode(' - ',self::$memory).'</title>'; |
|
| 20 | + return '<title>'.implode(' - ', self::$memory).'</title>'; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | } |
@@ -6,7 +6,9 @@ |
||
| 6 | 6 | private static $memory = []; |
| 7 | 7 | |
| 8 | 8 | public function add($title){ |
| 9 | - if(!is_array($title)) $title = [$title]; |
|
| 9 | + if(!is_array($title)) { |
|
| 10 | + $title = [$title]; |
|
| 11 | + } |
|
| 10 | 12 | self::$memory = array_merge(self::$memory,$title); |
| 11 | 13 | return $this; |
| 12 | 14 | } |