@@ -5,31 +5,31 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | private static $js; |
| 7 | 7 | |
| 8 | - public function __construct(){ |
|
| 8 | + public function __construct() { |
|
| 9 | 9 | |
| 10 | 10 | $config = (new Config)->get(); |
| 11 | 11 | |
| 12 | - if(!isset($_SERVER['HTTP_ACCEPT'])) $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 13 | - $acceptSrc = explode(',',$_SERVER['HTTP_ACCEPT']); |
|
| 14 | - foreach($acceptSrc as $key=>$value){ |
|
| 15 | - $value = explode('/',$value); |
|
| 16 | - $value[1] = explode(';',$value[1]); |
|
| 12 | + if (!isset($_SERVER['HTTP_ACCEPT'])) $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 13 | + $acceptSrc = explode(',', $_SERVER['HTTP_ACCEPT']); |
|
| 14 | + foreach ($acceptSrc as $key=>$value) { |
|
| 15 | + $value = explode('/', $value); |
|
| 16 | + $value[1] = explode(';', $value[1]); |
|
| 17 | 17 | $name = array_shift($value[1]); |
| 18 | 18 | $data = []; |
| 19 | - foreach($value[1] as $k=>$v){ |
|
| 20 | - $v = explode('=',$v); |
|
| 19 | + foreach ($value[1] as $k=>$v) { |
|
| 20 | + $v = explode('=', $v); |
|
| 21 | 21 | $data[$v[0]] = $v[1]; |
| 22 | 22 | } |
| 23 | 23 | $accept[$value[0]][$name] = $data; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - unset($acceptSrc,$key,$value,$name,$data,$k,$v); |
|
| 26 | + unset($acceptSrc, $key, $value, $name, $data, $k, $v); |
|
| 27 | 27 | |
| 28 | 28 | $requestUri = parse_url($_SERVER['REQUEST_URI']); |
| 29 | - if($requestUri['path'] == '/javascript.js'){ |
|
| 29 | + if ($requestUri['path'] == '/javascript.js') { |
|
| 30 | 30 | header('Content-Type: application/javascript'); |
| 31 | - if(isset($requestUri['query'])){ |
|
| 32 | - $query = explode(':',$requestUri['query']); |
|
| 31 | + if (isset($requestUri['query'])) { |
|
| 32 | + $query = explode(':', $requestUri['query']); |
|
| 33 | 33 | (new Content)->js($query); |
| 34 | 34 | } |
| 35 | 35 | exit; |
@@ -40,30 +40,30 @@ discard block |
||
| 40 | 40 | header('Access-Control-Allow-Credentials: true'); |
| 41 | 41 | header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT'); |
| 42 | 42 | |
| 43 | - if(isset($accept['application']['view'])){ |
|
| 43 | + if (isset($accept['application']['view'])) { |
|
| 44 | 44 | header('Content-Type: text/html'); |
| 45 | 45 | (new RestApi)->view(); |
| 46 | - } else if(isset($accept['application']['widget'])){ |
|
| 46 | + } else if (isset($accept['application']['widget'])) { |
|
| 47 | 47 | header('Content-Type: text/html'); |
| 48 | 48 | (new RestApi)->widget(); |
| 49 | - } else if(isset($accept['application']['apps'])){ |
|
| 49 | + } else if (isset($accept['application']['apps'])) { |
|
| 50 | 50 | header('Content-Type: application/json'); |
| 51 | - $query = json_decode(file_get_contents('php://input'),1); |
|
| 51 | + $query = json_decode(file_get_contents('php://input'), 1); |
|
| 52 | 52 | $result = []; |
| 53 | - foreach($query as $method=>$params){ |
|
| 53 | + foreach ($query as $method=>$params) { |
|
| 54 | 54 | $stableParams = []; |
| 55 | 55 | $file = $config['core']['apps'].'/'.$method.'.php'; |
| 56 | 56 | $func = require_once($file); |
| 57 | 57 | $reflection = new \ReflectionFunction($func); |
| 58 | - foreach($reflection->getParameters() as $key=>$value){ |
|
| 59 | - if(isset($params[$value->name])) $stableParams[$value->name] = $params[$value->name]; |
|
| 58 | + foreach ($reflection->getParameters() as $key=>$value) { |
|
| 59 | + if (isset($params[$value->name])) $stableParams[$value->name] = $params[$value->name]; |
|
| 60 | 60 | else $stableParams[$value->name] = null; |
| 61 | 61 | } |
| 62 | - $name = explode('/',$method); |
|
| 62 | + $name = explode('/', $method); |
|
| 63 | 63 | $count = count($name)-1; |
| 64 | 64 | $app = new Application; |
| 65 | - foreach($name as $key=>$var){ |
|
| 66 | - if($count == $key) $app = call_user_method_array($var,$app,$stableParams); |
|
| 65 | + foreach ($name as $key=>$var) { |
|
| 66 | + if ($count == $key) $app = call_user_method_array($var, $app, $stableParams); |
|
| 67 | 67 | else $app = $app->{$var}; |
| 68 | 68 | } |
| 69 | 69 | $result[$method] = $app; |
@@ -9,7 +9,9 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | $config = (new Config)->get(); |
| 11 | 11 | |
| 12 | - if(!isset($_SERVER['HTTP_ACCEPT'])) $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 12 | + if(!isset($_SERVER['HTTP_ACCEPT'])) { |
|
| 13 | + $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 14 | + } |
|
| 13 | 15 | $acceptSrc = explode(',',$_SERVER['HTTP_ACCEPT']); |
| 14 | 16 | foreach($acceptSrc as $key=>$value){ |
| 15 | 17 | $value = explode('/',$value); |
@@ -38,8 +40,7 @@ discard block |
||
| 38 | 40 | { |
| 39 | 41 | header('HTTP/1.1 304 Not Modified'); |
| 40 | 42 | exit(); |
| 41 | - } |
|
| 42 | - else |
|
| 43 | + } else |
|
| 43 | 44 | { |
| 44 | 45 | header("Last-Modified: $tsstring"); |
| 45 | 46 | header("ETag: $etag"); |
@@ -73,15 +74,21 @@ discard block |
||
| 73 | 74 | $func = require_once($file); |
| 74 | 75 | $reflection = new \ReflectionFunction($func); |
| 75 | 76 | foreach($reflection->getParameters() as $key=>$value){ |
| 76 | - if(isset($params[$value->name])) $stableParams[$value->name] = $params[$value->name]; |
|
| 77 | - else $stableParams[$value->name] = null; |
|
| 77 | + if(isset($params[$value->name])) { |
|
| 78 | + $stableParams[$value->name] = $params[$value->name]; |
|
| 79 | + } else { |
|
| 80 | + $stableParams[$value->name] = null; |
|
| 81 | + } |
|
| 78 | 82 | } |
| 79 | 83 | $name = explode('/',$method); |
| 80 | 84 | $count = count($name)-1; |
| 81 | 85 | $app = new Application; |
| 82 | 86 | foreach($name as $key=>$var){ |
| 83 | - if($count == $key) $app = call_user_method_array($var,$app,$stableParams); |
|
| 84 | - else $app = $app->{$var}; |
|
| 87 | + if($count == $key) { |
|
| 88 | + $app = call_user_method_array($var,$app,$stableParams); |
|
| 89 | + } else { |
|
| 90 | + $app = $app->{$var}; |
|
| 91 | + } |
|
| 85 | 92 | } |
| 86 | 93 | $result[$method] = $app; |
| 87 | 94 | } |
@@ -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); |
@@ -12,19 +12,27 @@ 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 | |
| 24 | 29 | public function get(){ |
| 25 | 30 | $js = array_unique(self::$list); |
| 26 | - if(!empty($js)) $jsQuery = '?'.implode(':',$js); |
|
| 27 | - else $jsQuery = ''; |
|
| 31 | + if(!empty($js)) { |
|
| 32 | + $jsQuery = '?'.implode(':',$js); |
|
| 33 | + } else { |
|
| 34 | + $jsQuery = ''; |
|
| 35 | + } |
|
| 28 | 36 | return '<script async src="http://'.self::$host.'/javascript.js'.$jsQuery.'"></script>'; |
| 29 | 37 | } |
| 30 | 38 | |
@@ -33,7 +41,9 @@ discard block |
||
| 33 | 41 | $code = ''; |
| 34 | 42 | foreach($js as $name){ |
| 35 | 43 | $file = self::$config['core']['js'].'/'.$name.'.js'; |
| 36 | - if(is_file($file)) $code .= file_get_contents($file); |
|
| 44 | + if(is_file($file)) { |
|
| 45 | + $code .= file_get_contents($file); |
|
| 46 | + } |
|
| 37 | 47 | } |
| 38 | 48 | $minifier = new \MatthiasMullie\Minify\JS(); |
| 39 | 49 | $minifier->add($code); |
@@ -10,8 +10,11 @@ discard block |
||
| 10 | 10 | $tmp = explode('/',$this->requiestUri); |
| 11 | 11 | foreach($tmp as $key=>$value){ |
| 12 | 12 | $value = trim($value); |
| 13 | - if(empty($value)) unset($tmp[$key]); |
|
| 14 | - else $tmp[$key] = $value; |
|
| 13 | + if(empty($value)) { |
|
| 14 | + unset($tmp[$key]); |
|
| 15 | + } else { |
|
| 16 | + $tmp[$key] = $value; |
|
| 17 | + } |
|
| 15 | 18 | } |
| 16 | 19 | $tmp = array_values($tmp); |
| 17 | 20 | $this->requestUri = $tmp; |
@@ -22,8 +25,11 @@ discard block |
||
| 22 | 25 | } |
| 23 | 26 | |
| 24 | 27 | public function part($number){ |
| 25 | - if(isset($this->requestUri[$number])) return (string) urldecode($this->requestUri[$number]); |
|
| 26 | - else return ''; |
|
| 28 | + if(isset($this->requestUri[$number])) { |
|
| 29 | + return (string) urldecode($this->requestUri[$number]); |
|
| 30 | + } else { |
|
| 31 | + return ''; |
|
| 32 | + } |
|
| 27 | 33 | } |
| 28 | 34 | |
| 29 | 35 | public function host(){ |
@@ -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->requestUri); |
|
| 11 | - foreach($tmp as $key=>$value){ |
|
| 10 | + $tmp = explode('/', $this->requestUri); |
|
| 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 | |