Completed
Push — master ( d47583...518897 )
by Andrey
02:51
created
Site.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -5,31 +5,31 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Js.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,33 +7,33 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
Braces   +16 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,19 +12,27 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
Content.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -16,16 +16,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,46 +76,46 @@  discard block
 block discarded – undo
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
         $minify = new MinifyHTML($content);
85 85
         $content = $minify->compress();
86 86
         echo $content;
87 87
     }
88 88
 
89
-    public function js($query){
89
+    public function js($query) {
90 90
         echo self::$js->compile($query);
91 91
     }
92 92
 
93 93
     # $type - page,view
94
-    public function file($name=false){
95
-        if($name === false){
94
+    public function file($name = false) {
95
+        if ($name === false) {
96 96
             $path = self::$config['core']['page'];
97 97
         } else {
98 98
             $path = self::$config['core']['view'].'/'.$name;
99 99
         }
100 100
         # Route
101 101
         $uri = self::$path;
102
-        array_push($uri,'');
103
-        foreach($uri as $key=>$value){ if(empty(trim($value))) { unset($uri[$key]); continue; } }
102
+        array_push($uri, '');
103
+        foreach ($uri as $key=>$value) { if (empty(trim($value))) { unset($uri[$key]); continue; } }
104 104
         $uri = array_values($uri);
105 105
         $isFile = null;
106 106
         $currentUri = null;
107 107
         $filePhtml = null;
108
-        for($i=count($uri)-1; $i>=0; $i--){
109
-          $nextUri = implode('/',array_slice($uri,0,$i+1));
110
-          $getFile = function($type) use($path,$nextUri){
108
+        for ($i = count($uri)-1; $i>=0; $i--) {
109
+          $nextUri = implode('/', array_slice($uri, 0, $i+1));
110
+          $getFile = function($type) use($path, $nextUri){
111 111
             $file = $path.'/'.$nextUri.'/index.'.$type;
112
-            if(is_file($file)) return $file;
112
+            if (is_file($file)) return $file;
113 113
             return null;
114 114
           };
115 115
           $filePhtml = $getFile('phtml');
116
-          if($filePhtml) { $currentUri = $nextUri; break; }
116
+          if ($filePhtml) { $currentUri = $nextUri; break; }
117 117
         }
118
-        if($filePhtml === null) {
118
+        if ($filePhtml === null) {
119 119
           $filePhtml = $path.'/index.phtml';
120 120
         }
121 121
         return $filePhtml;
Please login to merge, or discard this patch.