@@ -18,6 +18,9 @@ |
||
18 | 18 | protected static $headers = []; |
19 | 19 | protected static $last_info = null; |
20 | 20 | |
21 | + /** |
|
22 | + * @param string $method |
|
23 | + */ |
|
21 | 24 | protected static function request($method, $url, $data=[], array $headers=[], $data_as_json=false, $username=null, $password = null){ |
22 | 25 | $http_method = strtoupper($method); |
23 | 26 | $ch = curl_init($url); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | protected static $headers = []; |
19 | 19 | protected static $last_info = null; |
20 | 20 | |
21 | - protected static function request($method, $url, $data=[], array $headers=[], $data_as_json=false, $username=null, $password = null){ |
|
21 | + protected static function request($method, $url, $data = [], array $headers = [], $data_as_json = false, $username = null, $password = null) { |
|
22 | 22 | $http_method = strtoupper($method); |
23 | 23 | $ch = curl_init($url); |
24 | 24 | $opt = [ |
@@ -33,26 +33,26 @@ discard block |
||
33 | 33 | CURLOPT_ENCODING => '', |
34 | 34 | ]; |
35 | 35 | |
36 | - if($username && $password) { |
|
37 | - $opt[CURLOPT_USERPWD] = "$username:$password"; |
|
36 | + if ($username && $password) { |
|
37 | + $opt[CURLOPT_USERPWD] = "$username:$password"; |
|
38 | 38 | } |
39 | 39 | |
40 | - $headers = array_merge($headers,static::$headers); |
|
40 | + $headers = array_merge($headers, static::$headers); |
|
41 | 41 | |
42 | - if($http_method == 'GET'){ |
|
43 | - if($data && is_array($data)){ |
|
42 | + if ($http_method == 'GET') { |
|
43 | + if ($data && is_array($data)) { |
|
44 | 44 | $tmp = []; |
45 | 45 | $queried_url = $url; |
46 | - foreach($data as $key=>$val) $tmp[] = $key.'='.$val; |
|
47 | - $queried_url .= (strpos($queried_url,'?')===false)?'?':'&'; |
|
48 | - $queried_url .= implode('&',$tmp); |
|
46 | + foreach ($data as $key=>$val) $tmp[] = $key.'='.$val; |
|
47 | + $queried_url .= (strpos($queried_url, '?') === false) ? '?' : '&'; |
|
48 | + $queried_url .= implode('&', $tmp); |
|
49 | 49 | $opt[CURLOPT_URL] = $queried_url; |
50 | 50 | unset($opt[CURLOPT_CUSTOMREQUEST]); |
51 | 51 | $opt[CURLOPT_HTTPGET] = true; |
52 | 52 | } |
53 | 53 | } else { |
54 | 54 | $opt[CURLOPT_CUSTOMREQUEST] = $http_method; |
55 | - if($data_as_json or is_object($data)){ |
|
55 | + if ($data_as_json or is_object($data)) { |
|
56 | 56 | $headers['Content-Type'] = 'application/json'; |
57 | 57 | $opt[CURLOPT_POSTFIELDS] = json_encode($data); |
58 | 58 | } else { |
@@ -61,56 +61,56 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | |
64 | - curl_setopt_array($ch,$opt); |
|
64 | + curl_setopt_array($ch, $opt); |
|
65 | 65 | $_harr = []; |
66 | - foreach($headers as $key=>$val) $_harr[] = $key.': '.$val; |
|
66 | + foreach ($headers as $key=>$val) $_harr[] = $key.': '.$val; |
|
67 | 67 | curl_setopt($ch, CURLOPT_HTTPHEADER, $_harr); |
68 | 68 | $result = curl_exec($ch); |
69 | 69 | $contentType = strtolower(curl_getinfo($ch, CURLINFO_CONTENT_TYPE)); |
70 | 70 | static::$last_info = curl_getinfo($ch); |
71 | - if(false !== strpos($contentType,'json')) $result = json_decode($result); |
|
71 | + if (false !== strpos($contentType, 'json')) $result = json_decode($result); |
|
72 | 72 | curl_close($ch); |
73 | 73 | return $result; |
74 | 74 | } |
75 | 75 | |
76 | - public static function useJSON($value=null){ |
|
77 | - return static::$json_data = ($value===null?static::$json_data:$value); |
|
76 | + public static function useJSON($value = null) { |
|
77 | + return static::$json_data = ($value === null ? static::$json_data : $value); |
|
78 | 78 | } |
79 | 79 | |
80 | - public static function addHeader($name,$value){ |
|
80 | + public static function addHeader($name, $value) { |
|
81 | 81 | static::$headers[$name] = $value; |
82 | 82 | } |
83 | 83 | |
84 | - public static function removeHeader($name){ |
|
84 | + public static function removeHeader($name) { |
|
85 | 85 | unset(static::$headers[$name]); |
86 | 86 | } |
87 | 87 | |
88 | - public static function headers($name=null){ |
|
89 | - return null===$name?static::$headers:(isset(static::$headers[$name])?static::$headers[$name]:''); |
|
88 | + public static function headers($name = null) { |
|
89 | + return null === $name ? static::$headers : (isset(static::$headers[$name]) ? static::$headers[$name] : ''); |
|
90 | 90 | } |
91 | 91 | |
92 | - public static function userAgent($value=null){ |
|
93 | - return static::$UA = ($value===null?static::$UA:$value); |
|
92 | + public static function userAgent($value = null) { |
|
93 | + return static::$UA = ($value === null ? static::$UA : $value); |
|
94 | 94 | } |
95 | 95 | |
96 | - public static function get($url,$data=null,array $headers=[], $username = null, $password = null){ |
|
97 | - return static::request('get',$url,$data,$headers,false,$username,$password); |
|
96 | + public static function get($url, $data = null, array $headers = [], $username = null, $password = null) { |
|
97 | + return static::request('get', $url, $data, $headers, false, $username, $password); |
|
98 | 98 | } |
99 | 99 | |
100 | - public static function post($url,$data=null,array $headers=[], $username = null, $password = null){ |
|
101 | - return static::request('post',$url,$data,$headers,static::$json_data,$username,$password); |
|
100 | + public static function post($url, $data = null, array $headers = [], $username = null, $password = null) { |
|
101 | + return static::request('post', $url, $data, $headers, static::$json_data, $username, $password); |
|
102 | 102 | } |
103 | 103 | |
104 | - public static function put($url,$data=null,array $headers=[], $username = null, $password = null){ |
|
105 | - return static::request('put',$url,$data,$headers,static::$json_data,$username,$password); |
|
104 | + public static function put($url, $data = null, array $headers = [], $username = null, $password = null) { |
|
105 | + return static::request('put', $url, $data, $headers, static::$json_data, $username, $password); |
|
106 | 106 | } |
107 | 107 | |
108 | - public static function delete($url,$data=null,array $headers=[], $username = null, $password = null){ |
|
109 | - return static::request('delete',$url,$data,$headers,static::$json_data,$username,$password); |
|
108 | + public static function delete($url, $data = null, array $headers = [], $username = null, $password = null) { |
|
109 | + return static::request('delete', $url, $data, $headers, static::$json_data, $username, $password); |
|
110 | 110 | } |
111 | 111 | |
112 | - public static function info($url=null){ |
|
113 | - if ($url){ |
|
112 | + public static function info($url = null) { |
|
113 | + if ($url) { |
|
114 | 114 | $ch = curl_init($url); |
115 | 115 | curl_setopt_array($ch, [ |
116 | 116 | CURLOPT_SSL_VERIFYHOST => false, |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | protected static $headers = []; |
19 | 19 | protected static $last_info = null; |
20 | 20 | |
21 | - protected static function request($method, $url, $data=[], array $headers=[], $data_as_json=false, $username=null, $password = null){ |
|
21 | + protected static function request($method, $url, $data=[], array $headers=[], $data_as_json=false, $username=null, $password = null) { |
|
22 | 22 | $http_method = strtoupper($method); |
23 | 23 | $ch = curl_init($url); |
24 | 24 | $opt = [ |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | |
40 | 40 | $headers = array_merge($headers,static::$headers); |
41 | 41 | |
42 | - if($http_method == 'GET'){ |
|
43 | - if($data && is_array($data)){ |
|
42 | + if($http_method == 'GET') { |
|
43 | + if($data && is_array($data)) { |
|
44 | 44 | $tmp = []; |
45 | 45 | $queried_url = $url; |
46 | 46 | foreach($data as $key=>$val) $tmp[] = $key.'='.$val; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | } else { |
54 | 54 | $opt[CURLOPT_CUSTOMREQUEST] = $http_method; |
55 | - if($data_as_json or is_object($data)){ |
|
55 | + if($data_as_json or is_object($data)) { |
|
56 | 56 | $headers['Content-Type'] = 'application/json'; |
57 | 57 | $opt[CURLOPT_POSTFIELDS] = json_encode($data); |
58 | 58 | } else { |
@@ -68,49 +68,51 @@ discard block |
||
68 | 68 | $result = curl_exec($ch); |
69 | 69 | $contentType = strtolower(curl_getinfo($ch, CURLINFO_CONTENT_TYPE)); |
70 | 70 | static::$last_info = curl_getinfo($ch); |
71 | - if(false !== strpos($contentType,'json')) $result = json_decode($result); |
|
71 | + if(false !== strpos($contentType,'json')) { |
|
72 | + $result = json_decode($result); |
|
73 | + } |
|
72 | 74 | curl_close($ch); |
73 | 75 | return $result; |
74 | 76 | } |
75 | 77 | |
76 | - public static function useJSON($value=null){ |
|
78 | + public static function useJSON($value=null) { |
|
77 | 79 | return static::$json_data = ($value===null?static::$json_data:$value); |
78 | 80 | } |
79 | 81 | |
80 | - public static function addHeader($name,$value){ |
|
82 | + public static function addHeader($name,$value) { |
|
81 | 83 | static::$headers[$name] = $value; |
82 | 84 | } |
83 | 85 | |
84 | - public static function removeHeader($name){ |
|
86 | + public static function removeHeader($name) { |
|
85 | 87 | unset(static::$headers[$name]); |
86 | 88 | } |
87 | 89 | |
88 | - public static function headers($name=null){ |
|
90 | + public static function headers($name=null) { |
|
89 | 91 | return null===$name?static::$headers:(isset(static::$headers[$name])?static::$headers[$name]:''); |
90 | 92 | } |
91 | 93 | |
92 | - public static function userAgent($value=null){ |
|
94 | + public static function userAgent($value=null) { |
|
93 | 95 | return static::$UA = ($value===null?static::$UA:$value); |
94 | 96 | } |
95 | 97 | |
96 | - public static function get($url,$data=null,array $headers=[], $username = null, $password = null){ |
|
98 | + public static function get($url,$data=null,array $headers=[], $username = null, $password = null) { |
|
97 | 99 | return static::request('get',$url,$data,$headers,false,$username,$password); |
98 | 100 | } |
99 | 101 | |
100 | - public static function post($url,$data=null,array $headers=[], $username = null, $password = null){ |
|
102 | + public static function post($url,$data=null,array $headers=[], $username = null, $password = null) { |
|
101 | 103 | return static::request('post',$url,$data,$headers,static::$json_data,$username,$password); |
102 | 104 | } |
103 | 105 | |
104 | - public static function put($url,$data=null,array $headers=[], $username = null, $password = null){ |
|
106 | + public static function put($url,$data=null,array $headers=[], $username = null, $password = null) { |
|
105 | 107 | return static::request('put',$url,$data,$headers,static::$json_data,$username,$password); |
106 | 108 | } |
107 | 109 | |
108 | - public static function delete($url,$data=null,array $headers=[], $username = null, $password = null){ |
|
110 | + public static function delete($url,$data=null,array $headers=[], $username = null, $password = null) { |
|
109 | 111 | return static::request('delete',$url,$data,$headers,static::$json_data,$username,$password); |
110 | 112 | } |
111 | 113 | |
112 | - public static function info($url=null){ |
|
113 | - if ($url){ |
|
114 | + public static function info($url=null) { |
|
115 | + if ($url) { |
|
114 | 116 | $ch = curl_init($url); |
115 | 117 | curl_setopt_array($ch, [ |
116 | 118 | CURLOPT_SSL_VERIFYHOST => false, |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use Module; |
15 | 15 | |
16 | 16 | protected static $body, |
17 | - $accepts; |
|
17 | + $accepts; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Handle Content Negotiation requests |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * @return string |
207 | 207 | */ |
208 | 208 | public static function method(){ |
209 | - return Filter::with('core.request.method',strtolower(filter_input(INPUT_SERVER,'REQUEST_METHOD')?:'get')); |
|
209 | + return Filter::with('core.request.method',strtolower(filter_input(INPUT_SERVER,'REQUEST_METHOD')?:'get')); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return string |
216 | 216 | */ |
217 | 217 | public static function IP(){ |
218 | - return Filter::with('core.request.IP',strtolower(filter_input(INPUT_SERVER,'REMOTE_ADDR')?:'')); |
|
218 | + return Filter::with('core.request.IP',strtolower(filter_input(INPUT_SERVER,'REMOTE_ADDR')?:'')); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @return string |
225 | 225 | */ |
226 | 226 | public static function UA(){ |
227 | - return Filter::with('core.request.UA',strtolower(filter_input(INPUT_SERVER,'HTTP_USER_AGENT')?:'')); |
|
227 | + return Filter::with('core.request.UA',strtolower(filter_input(INPUT_SERVER,'HTTP_USER_AGENT')?:'')); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | if ($json) { |
244 | 244 | static::$body = json_decode(file_get_contents("php://input")); |
245 | 245 | } else { |
246 | - if (empty($_POST)) { |
|
246 | + if (empty($_POST)) { |
|
247 | 247 | static::$body = file_get_contents("php://input"); |
248 | 248 | } else { |
249 | 249 | static::$body = (object)$_POST; |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return Object The preferred content if $choices is empty else return best match |
26 | 26 | */ |
27 | - public static function accept($key='type',$choices=''){ |
|
27 | + public static function accept($key = 'type', $choices = '') { |
|
28 | 28 | if (null === static::$accepts) static::$accepts = [ |
29 | - 'type' => new Negotiation(isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : ''), |
|
29 | + 'type' => new Negotiation(isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : ''), |
|
30 | 30 | 'language' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''), |
31 | 31 | 'encoding' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : ''), |
32 | - 'charset' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : ''), |
|
32 | + 'charset' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : ''), |
|
33 | 33 | ]; |
34 | 34 | return empty(static::$accepts[$key]) |
35 | 35 | ? false |
36 | - : ( empty($choices) |
|
36 | + : (empty($choices) |
|
37 | 37 | ? static::$accepts[$key]->preferred() |
38 | 38 | : static::$accepts[$key]->best($choices) |
39 | 39 | ); |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return Object The returned value or $default. |
49 | 49 | */ |
50 | - public static function input($key=null,$default=null){ |
|
51 | - return $key ? (isset($_REQUEST[$key]) ? new Object($_REQUEST[$key]) : (is_callable($default)?call_user_func($default):$default)) : new Object($_REQUEST[$key]); |
|
50 | + public static function input($key = null, $default = null) { |
|
51 | + return $key ? (isset($_REQUEST[$key]) ? new Object($_REQUEST[$key]) : (is_callable($default) ? call_user_func($default) : $default)) : new Object($_REQUEST[$key]); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return Object The returned value or $default. |
61 | 61 | */ |
62 | - public static function env($key=null,$default=null){ |
|
63 | - return $key ? (filter_input(INPUT_ENV,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_ENV; |
|
62 | + public static function env($key = null, $default = null) { |
|
63 | + return $key ? (filter_input(INPUT_ENV, $key) ?: (is_callable($default) ? call_user_func($default) : $default)) : $_ENV; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return Object The returned value or $default. |
73 | 73 | */ |
74 | - public static function server($key=null,$default=null){ |
|
75 | - return $key ? (filter_input(INPUT_SERVER,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_SERVER; |
|
74 | + public static function server($key = null, $default = null) { |
|
75 | + return $key ? (filter_input(INPUT_SERVER, $key) ?: (is_callable($default) ? call_user_func($default) : $default)) : $_SERVER; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return Object The returned value or $default. |
85 | 85 | */ |
86 | - public static function post($key=null,$default=null){ |
|
87 | - return $key ? (filter_input(INPUT_POST,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_POST; |
|
86 | + public static function post($key = null, $default = null) { |
|
87 | + return $key ? (filter_input(INPUT_POST, $key) ?: (is_callable($default) ? call_user_func($default) : $default)) : $_POST; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return Object The returned value or $default. |
97 | 97 | */ |
98 | - public static function get($key=null,$default=null){ |
|
99 | - return $key ? (filter_input(INPUT_GET,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_GET; |
|
98 | + public static function get($key = null, $default = null) { |
|
99 | + return $key ? (filter_input(INPUT_GET, $key) ?: (is_callable($default) ? call_user_func($default) : $default)) : $_GET; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return Object The returned value or $default. |
109 | 109 | */ |
110 | - public static function files($key=null,$default=null){ |
|
111 | - return $key ? (isset($_FILES[$key]) ? $_FILES[$key] : (is_callable($default)?call_user_func($default):$default)) : $_FILES; |
|
110 | + public static function files($key = null, $default = null) { |
|
111 | + return $key ? (isset($_FILES[$key]) ? $_FILES[$key] : (is_callable($default) ? call_user_func($default) : $default)) : $_FILES; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return Object The returned value or $default. |
121 | 121 | */ |
122 | - public static function cookie($key=null,$default=null){ |
|
123 | - return $key ? (filter_input(INPUT_COOKIE,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_COOKIE; |
|
122 | + public static function cookie($key = null, $default = null) { |
|
123 | + return $key ? (filter_input(INPUT_COOKIE, $key) ?: (is_callable($default) ? call_user_func($default) : $default)) : $_COOKIE; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,12 +128,11 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public static function host($protocol=true){ |
|
132 | - $host = filter_input(INPUT_SERVER,'HOSTNAME') ?: ( |
|
133 | - filter_input(INPUT_SERVER,'SERVER_NAME') ?: |
|
134 | - filter_input(INPUT_SERVER,'HTTP_HOST') |
|
131 | + public static function host($protocol = true) { |
|
132 | + $host = filter_input(INPUT_SERVER, 'HOSTNAME') ?: ( |
|
133 | + filter_input(INPUT_SERVER, 'SERVER_NAME') ?: filter_input(INPUT_SERVER, 'HTTP_HOST') |
|
135 | 134 | ); |
136 | - return ($protocol ? 'http' . (filter_input(INPUT_SERVER,'HTTPS')?'s':'') . '://' : '') . Filter::with('core.request.host',$host); |
|
135 | + return ($protocol ? 'http'.(filter_input(INPUT_SERVER, 'HTTPS') ? 's' : '').'://' : '').Filter::with('core.request.host', $host); |
|
137 | 136 | } |
138 | 137 | |
139 | 138 | /** |
@@ -141,8 +140,8 @@ discard block |
||
141 | 140 | * |
142 | 141 | * @return string |
143 | 142 | */ |
144 | - public static function URL(){ |
|
145 | - return static::host(true) . static::URI(false); |
|
143 | + public static function URL() { |
|
144 | + return static::host(true).static::URI(false); |
|
146 | 145 | } |
147 | 146 | |
148 | 147 | /** |
@@ -153,9 +152,9 @@ discard block |
||
153 | 152 | * |
154 | 153 | * @return Object The returned value or null. |
155 | 154 | */ |
156 | - public static function header($key=null,$default=null){ |
|
157 | - $key = 'HTTP_'.strtr(strtoupper($key),'-','_'); |
|
158 | - return $key ? (filter_input(INPUT_SERVER,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_SERVER; |
|
155 | + public static function header($key = null, $default = null) { |
|
156 | + $key = 'HTTP_'.strtr(strtoupper($key), '-', '_'); |
|
157 | + return $key ? (filter_input(INPUT_SERVER, $key) ?: (is_callable($default) ? call_user_func($default) : $default)) : $_SERVER; |
|
159 | 158 | } |
160 | 159 | |
161 | 160 | /** |
@@ -165,25 +164,24 @@ discard block |
||
165 | 164 | * |
166 | 165 | * @return string |
167 | 166 | */ |
168 | - public static function URI($relative=true){ |
|
167 | + public static function URI($relative = true) { |
|
169 | 168 | // On some web server configurations PHP_SELF is not populated. |
170 | - $self = filter_input(INPUT_SERVER,'SCRIPT_NAME') ?: filter_input(INPUT_SERVER,'PHP_SELF'); |
|
169 | + $self = filter_input(INPUT_SERVER, 'SCRIPT_NAME') ?: filter_input(INPUT_SERVER, 'PHP_SELF'); |
|
171 | 170 | // Search REQUEST_URI in $_SERVER |
172 | - $serv_uri = filter_input(INPUT_SERVER,'PATH_INFO') ?: ( |
|
173 | - filter_input(INPUT_SERVER,'ORIG_PATH_INFO') ?: |
|
174 | - filter_input(INPUT_SERVER,'REQUEST_URI') |
|
171 | + $serv_uri = filter_input(INPUT_SERVER, 'PATH_INFO') ?: ( |
|
172 | + filter_input(INPUT_SERVER, 'ORIG_PATH_INFO') ?: filter_input(INPUT_SERVER, 'REQUEST_URI') |
|
175 | 173 | ); |
176 | - $uri = strtok($serv_uri,'?'); |
|
174 | + $uri = strtok($serv_uri, '?'); |
|
177 | 175 | $uri = ($uri == $self) ? '/' : $uri; |
178 | 176 | |
179 | 177 | // Add a filter here, for URL rewriting |
180 | - $uri = Filter::with('core.request.URI',$uri); |
|
178 | + $uri = Filter::with('core.request.URI', $uri); |
|
181 | 179 | |
182 | - $uri = rtrim($uri,'/'); |
|
180 | + $uri = rtrim($uri, '/'); |
|
183 | 181 | |
184 | - if ($relative){ |
|
185 | - $base = rtrim(dirname($self),'/'); |
|
186 | - $uri = str_replace($base,'',$uri); |
|
182 | + if ($relative) { |
|
183 | + $base = rtrim(dirname($self), '/'); |
|
184 | + $uri = str_replace($base, '', $uri); |
|
187 | 185 | } |
188 | 186 | |
189 | 187 | return $uri ?: '/'; |
@@ -194,9 +192,9 @@ discard block |
||
194 | 192 | * |
195 | 193 | * @return string |
196 | 194 | */ |
197 | - public static function baseURI(){ |
|
195 | + public static function baseURI() { |
|
198 | 196 | // On some web server configurations PHP_SELF is not populated. |
199 | - $uri = dirname(filter_input(INPUT_SERVER,'SCRIPT_NAME') ?: filter_input(INPUT_SERVER,'PHP_SELF')); |
|
197 | + $uri = dirname(filter_input(INPUT_SERVER, 'SCRIPT_NAME') ?: filter_input(INPUT_SERVER, 'PHP_SELF')); |
|
200 | 198 | return $uri ?: '/'; |
201 | 199 | } |
202 | 200 | |
@@ -205,8 +203,8 @@ discard block |
||
205 | 203 | * |
206 | 204 | * @return string |
207 | 205 | */ |
208 | - public static function method(){ |
|
209 | - return Filter::with('core.request.method',strtolower(filter_input(INPUT_SERVER,'REQUEST_METHOD')?:'get')); |
|
206 | + public static function method() { |
|
207 | + return Filter::with('core.request.method', strtolower(filter_input(INPUT_SERVER, 'REQUEST_METHOD') ?: 'get')); |
|
210 | 208 | } |
211 | 209 | |
212 | 210 | /** |
@@ -214,8 +212,8 @@ discard block |
||
214 | 212 | * |
215 | 213 | * @return string |
216 | 214 | */ |
217 | - public static function IP(){ |
|
218 | - return Filter::with('core.request.IP',strtolower(filter_input(INPUT_SERVER,'REMOTE_ADDR')?:'')); |
|
215 | + public static function IP() { |
|
216 | + return Filter::with('core.request.IP', strtolower(filter_input(INPUT_SERVER, 'REMOTE_ADDR') ?: '')); |
|
219 | 217 | } |
220 | 218 | |
221 | 219 | /** |
@@ -223,8 +221,8 @@ discard block |
||
223 | 221 | * |
224 | 222 | * @return string |
225 | 223 | */ |
226 | - public static function UA(){ |
|
227 | - return Filter::with('core.request.UA',strtolower(filter_input(INPUT_SERVER,'HTTP_USER_AGENT')?:'')); |
|
224 | + public static function UA() { |
|
225 | + return Filter::with('core.request.UA', strtolower(filter_input(INPUT_SERVER, 'HTTP_USER_AGENT') ?: '')); |
|
228 | 226 | } |
229 | 227 | |
230 | 228 | |
@@ -236,21 +234,21 @@ discard block |
||
236 | 234 | * |
237 | 235 | * @return mixed The request body data |
238 | 236 | */ |
239 | - public static function data($key=null,$default=null){ |
|
240 | - if (null===static::$body){ |
|
241 | - $json = (false !== stripos(filter_input(INPUT_SERVER,'HTTP_CONTENT_TYPE'),'json')) |
|
242 | - || (false !== stripos(filter_input(INPUT_SERVER,'CONTENT_TYPE'),'json')); |
|
237 | + public static function data($key = null, $default = null) { |
|
238 | + if (null === static::$body) { |
|
239 | + $json = (false !== stripos(filter_input(INPUT_SERVER, 'HTTP_CONTENT_TYPE'), 'json')) |
|
240 | + || (false !== stripos(filter_input(INPUT_SERVER, 'CONTENT_TYPE'), 'json')); |
|
243 | 241 | if ($json) { |
244 | 242 | static::$body = json_decode(file_get_contents("php://input")); |
245 | 243 | } else { |
246 | 244 | if (empty($_POST)) { |
247 | 245 | static::$body = file_get_contents("php://input"); |
248 | 246 | } else { |
249 | - static::$body = (object)$_POST; |
|
247 | + static::$body = (object) $_POST; |
|
250 | 248 | } |
251 | 249 | } |
252 | 250 | } |
253 | - return $key ? (isset(static::$body->$key) ? static::$body->$key : (is_callable($default)?call_user_func($default):$default)) : static::$body; |
|
251 | + return $key ? (isset(static::$body->$key) ? static::$body->$key : (is_callable($default) ? call_user_func($default) : $default)) : static::$body; |
|
254 | 252 | } |
255 | 253 | |
256 | 254 | } |
@@ -24,13 +24,15 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return Object The preferred content if $choices is empty else return best match |
26 | 26 | */ |
27 | - public static function accept($key='type',$choices=''){ |
|
28 | - if (null === static::$accepts) static::$accepts = [ |
|
27 | + public static function accept($key='type',$choices='') { |
|
28 | + if (null === static::$accepts) { |
|
29 | + static::$accepts = [ |
|
29 | 30 | 'type' => new Negotiation(isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : ''), |
30 | 31 | 'language' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''), |
31 | 32 | 'encoding' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : ''), |
32 | 33 | 'charset' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : ''), |
33 | 34 | ]; |
35 | + } |
|
34 | 36 | return empty(static::$accepts[$key]) |
35 | 37 | ? false |
36 | 38 | : ( empty($choices) |
@@ -47,7 +49,7 @@ discard block |
||
47 | 49 | * |
48 | 50 | * @return Object The returned value or $default. |
49 | 51 | */ |
50 | - public static function input($key=null,$default=null){ |
|
52 | + public static function input($key=null,$default=null) { |
|
51 | 53 | return $key ? (isset($_REQUEST[$key]) ? new Object($_REQUEST[$key]) : (is_callable($default)?call_user_func($default):$default)) : new Object($_REQUEST[$key]); |
52 | 54 | } |
53 | 55 | |
@@ -59,7 +61,7 @@ discard block |
||
59 | 61 | * |
60 | 62 | * @return Object The returned value or $default. |
61 | 63 | */ |
62 | - public static function env($key=null,$default=null){ |
|
64 | + public static function env($key=null,$default=null) { |
|
63 | 65 | return $key ? (filter_input(INPUT_ENV,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_ENV; |
64 | 66 | } |
65 | 67 | |
@@ -71,7 +73,7 @@ discard block |
||
71 | 73 | * |
72 | 74 | * @return Object The returned value or $default. |
73 | 75 | */ |
74 | - public static function server($key=null,$default=null){ |
|
76 | + public static function server($key=null,$default=null) { |
|
75 | 77 | return $key ? (filter_input(INPUT_SERVER,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_SERVER; |
76 | 78 | } |
77 | 79 | |
@@ -83,7 +85,7 @@ discard block |
||
83 | 85 | * |
84 | 86 | * @return Object The returned value or $default. |
85 | 87 | */ |
86 | - public static function post($key=null,$default=null){ |
|
88 | + public static function post($key=null,$default=null) { |
|
87 | 89 | return $key ? (filter_input(INPUT_POST,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_POST; |
88 | 90 | } |
89 | 91 | |
@@ -95,7 +97,7 @@ discard block |
||
95 | 97 | * |
96 | 98 | * @return Object The returned value or $default. |
97 | 99 | */ |
98 | - public static function get($key=null,$default=null){ |
|
100 | + public static function get($key=null,$default=null) { |
|
99 | 101 | return $key ? (filter_input(INPUT_GET,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_GET; |
100 | 102 | } |
101 | 103 | |
@@ -107,7 +109,7 @@ discard block |
||
107 | 109 | * |
108 | 110 | * @return Object The returned value or $default. |
109 | 111 | */ |
110 | - public static function files($key=null,$default=null){ |
|
112 | + public static function files($key=null,$default=null) { |
|
111 | 113 | return $key ? (isset($_FILES[$key]) ? $_FILES[$key] : (is_callable($default)?call_user_func($default):$default)) : $_FILES; |
112 | 114 | } |
113 | 115 | |
@@ -119,7 +121,7 @@ discard block |
||
119 | 121 | * |
120 | 122 | * @return Object The returned value or $default. |
121 | 123 | */ |
122 | - public static function cookie($key=null,$default=null){ |
|
124 | + public static function cookie($key=null,$default=null) { |
|
123 | 125 | return $key ? (filter_input(INPUT_COOKIE,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_COOKIE; |
124 | 126 | } |
125 | 127 | |
@@ -128,7 +130,7 @@ discard block |
||
128 | 130 | * |
129 | 131 | * @return string |
130 | 132 | */ |
131 | - public static function host($protocol=true){ |
|
133 | + public static function host($protocol=true) { |
|
132 | 134 | $host = filter_input(INPUT_SERVER,'HOSTNAME') ?: ( |
133 | 135 | filter_input(INPUT_SERVER,'SERVER_NAME') ?: |
134 | 136 | filter_input(INPUT_SERVER,'HTTP_HOST') |
@@ -141,7 +143,7 @@ discard block |
||
141 | 143 | * |
142 | 144 | * @return string |
143 | 145 | */ |
144 | - public static function URL(){ |
|
146 | + public static function URL() { |
|
145 | 147 | return static::host(true) . static::URI(false); |
146 | 148 | } |
147 | 149 | |
@@ -153,7 +155,7 @@ discard block |
||
153 | 155 | * |
154 | 156 | * @return Object The returned value or null. |
155 | 157 | */ |
156 | - public static function header($key=null,$default=null){ |
|
158 | + public static function header($key=null,$default=null) { |
|
157 | 159 | $key = 'HTTP_'.strtr(strtoupper($key),'-','_'); |
158 | 160 | return $key ? (filter_input(INPUT_SERVER,$key) ?: (is_callable($default)?call_user_func($default):$default)) : $_SERVER; |
159 | 161 | } |
@@ -165,7 +167,7 @@ discard block |
||
165 | 167 | * |
166 | 168 | * @return string |
167 | 169 | */ |
168 | - public static function URI($relative=true){ |
|
170 | + public static function URI($relative=true) { |
|
169 | 171 | // On some web server configurations PHP_SELF is not populated. |
170 | 172 | $self = filter_input(INPUT_SERVER,'SCRIPT_NAME') ?: filter_input(INPUT_SERVER,'PHP_SELF'); |
171 | 173 | // Search REQUEST_URI in $_SERVER |
@@ -181,7 +183,7 @@ discard block |
||
181 | 183 | |
182 | 184 | $uri = rtrim($uri,'/'); |
183 | 185 | |
184 | - if ($relative){ |
|
186 | + if ($relative) { |
|
185 | 187 | $base = rtrim(dirname($self),'/'); |
186 | 188 | $uri = str_replace($base,'',$uri); |
187 | 189 | } |
@@ -194,7 +196,7 @@ discard block |
||
194 | 196 | * |
195 | 197 | * @return string |
196 | 198 | */ |
197 | - public static function baseURI(){ |
|
199 | + public static function baseURI() { |
|
198 | 200 | // On some web server configurations PHP_SELF is not populated. |
199 | 201 | $uri = dirname(filter_input(INPUT_SERVER,'SCRIPT_NAME') ?: filter_input(INPUT_SERVER,'PHP_SELF')); |
200 | 202 | return $uri ?: '/'; |
@@ -205,7 +207,7 @@ discard block |
||
205 | 207 | * |
206 | 208 | * @return string |
207 | 209 | */ |
208 | - public static function method(){ |
|
210 | + public static function method() { |
|
209 | 211 | return Filter::with('core.request.method',strtolower(filter_input(INPUT_SERVER,'REQUEST_METHOD')?:'get')); |
210 | 212 | } |
211 | 213 | |
@@ -214,7 +216,7 @@ discard block |
||
214 | 216 | * |
215 | 217 | * @return string |
216 | 218 | */ |
217 | - public static function IP(){ |
|
219 | + public static function IP() { |
|
218 | 220 | return Filter::with('core.request.IP',strtolower(filter_input(INPUT_SERVER,'REMOTE_ADDR')?:'')); |
219 | 221 | } |
220 | 222 | |
@@ -223,7 +225,7 @@ discard block |
||
223 | 225 | * |
224 | 226 | * @return string |
225 | 227 | */ |
226 | - public static function UA(){ |
|
228 | + public static function UA() { |
|
227 | 229 | return Filter::with('core.request.UA',strtolower(filter_input(INPUT_SERVER,'HTTP_USER_AGENT')?:'')); |
228 | 230 | } |
229 | 231 | |
@@ -236,8 +238,8 @@ discard block |
||
236 | 238 | * |
237 | 239 | * @return mixed The request body data |
238 | 240 | */ |
239 | - public static function data($key=null,$default=null){ |
|
240 | - if (null===static::$body){ |
|
241 | + public static function data($key=null,$default=null) { |
|
242 | + if (null===static::$body) { |
|
241 | 243 | $json = (false !== stripos(filter_input(INPUT_SERVER,'HTTP_CONTENT_TYPE'),'json')) |
242 | 244 | || (false !== stripos(filter_input(INPUT_SERVER,'CONTENT_TYPE'),'json')); |
243 | 245 | if ($json) { |
@@ -27,51 +27,51 @@ |
||
27 | 27 | return static::$fields->all(); |
28 | 28 | } |
29 | 29 | |
30 | - public static function get($key, $default=null){ |
|
30 | + public static function get($key, $default = null) { |
|
31 | 31 | if (!static::$fields) static::$fields = new Map(); |
32 | 32 | return static::$fields->get($key, $default); |
33 | 33 | } |
34 | 34 | |
35 | - public static function set($key, $value=null){ |
|
35 | + public static function set($key, $value = null) { |
|
36 | 36 | if (!static::$fields) static::$fields = new Map(); |
37 | 37 | return static::$fields->set($key, $value); |
38 | 38 | } |
39 | 39 | |
40 | - public static function delete($key, $compact=true){ |
|
40 | + public static function delete($key, $compact = true) { |
|
41 | 41 | if (!static::$fields) static::$fields = new Map(); |
42 | 42 | static::$fields->delete($key, $compact); |
43 | 43 | } |
44 | 44 | |
45 | - public static function exists($key){ |
|
45 | + public static function exists($key) { |
|
46 | 46 | if (!static::$fields) static::$fields = new Map(); |
47 | 47 | return static::$fields->exists($key); |
48 | 48 | } |
49 | 49 | |
50 | - public static function clear(){ |
|
50 | + public static function clear() { |
|
51 | 51 | if (!static::$fields) static::$fields = new Map(); |
52 | 52 | static::$fields->clear(); |
53 | 53 | } |
54 | 54 | |
55 | - public static function load($fields){ |
|
55 | + public static function load($fields) { |
|
56 | 56 | if (!static::$fields) static::$fields = new Map(); |
57 | 57 | static::$fields->load($fields); |
58 | 58 | } |
59 | 59 | |
60 | - public static function merge(array $array, $merge_back=false){ |
|
60 | + public static function merge(array $array, $merge_back = false) { |
|
61 | 61 | if (!static::$fields) static::$fields = new Map(); |
62 | 62 | static::$fields->merge($array, $merge_back); |
63 | 63 | } |
64 | 64 | |
65 | - protected static function compact(){ |
|
65 | + protected static function compact() { |
|
66 | 66 | if (!static::$fields) static::$fields = new Map(); |
67 | 67 | static::$fields->compact(); |
68 | 68 | } |
69 | 69 | |
70 | - protected static function & find($path, $create=false, callable $operation=null) { |
|
70 | + protected static function & find($path, $create = false, callable $operation = null) { |
|
71 | 71 | return static::$fields->find($path, $create, $operation); |
72 | 72 | } |
73 | 73 | |
74 | - public function jsonSerialize(){ |
|
74 | + public function jsonSerialize() { |
|
75 | 75 | if (!static::$fields) static::$fields = new Map(); |
76 | 76 | return static::$fields->jsonSerialize(); |
77 | 77 | } |
@@ -23,47 +23,65 @@ discard block |
||
23 | 23 | protected static $fields = null; |
24 | 24 | |
25 | 25 | public static function & all(){ |
26 | - if (!static::$fields) static::$fields = new Map(); |
|
26 | + if (!static::$fields) { |
|
27 | + static::$fields = new Map(); |
|
28 | + } |
|
27 | 29 | return static::$fields->all(); |
28 | 30 | } |
29 | 31 | |
30 | - public static function get($key, $default=null){ |
|
31 | - if (!static::$fields) static::$fields = new Map(); |
|
32 | + public static function get($key, $default=null) { |
|
33 | + if (!static::$fields) { |
|
34 | + static::$fields = new Map(); |
|
35 | + } |
|
32 | 36 | return static::$fields->get($key, $default); |
33 | 37 | } |
34 | 38 | |
35 | - public static function set($key, $value=null){ |
|
36 | - if (!static::$fields) static::$fields = new Map(); |
|
39 | + public static function set($key, $value=null) { |
|
40 | + if (!static::$fields) { |
|
41 | + static::$fields = new Map(); |
|
42 | + } |
|
37 | 43 | return static::$fields->set($key, $value); |
38 | 44 | } |
39 | 45 | |
40 | - public static function delete($key, $compact=true){ |
|
41 | - if (!static::$fields) static::$fields = new Map(); |
|
46 | + public static function delete($key, $compact=true) { |
|
47 | + if (!static::$fields) { |
|
48 | + static::$fields = new Map(); |
|
49 | + } |
|
42 | 50 | static::$fields->delete($key, $compact); |
43 | 51 | } |
44 | 52 | |
45 | - public static function exists($key){ |
|
46 | - if (!static::$fields) static::$fields = new Map(); |
|
53 | + public static function exists($key) { |
|
54 | + if (!static::$fields) { |
|
55 | + static::$fields = new Map(); |
|
56 | + } |
|
47 | 57 | return static::$fields->exists($key); |
48 | 58 | } |
49 | 59 | |
50 | - public static function clear(){ |
|
51 | - if (!static::$fields) static::$fields = new Map(); |
|
60 | + public static function clear() { |
|
61 | + if (!static::$fields) { |
|
62 | + static::$fields = new Map(); |
|
63 | + } |
|
52 | 64 | static::$fields->clear(); |
53 | 65 | } |
54 | 66 | |
55 | - public static function load($fields){ |
|
56 | - if (!static::$fields) static::$fields = new Map(); |
|
67 | + public static function load($fields) { |
|
68 | + if (!static::$fields) { |
|
69 | + static::$fields = new Map(); |
|
70 | + } |
|
57 | 71 | static::$fields->load($fields); |
58 | 72 | } |
59 | 73 | |
60 | - public static function merge(array $array, $merge_back=false){ |
|
61 | - if (!static::$fields) static::$fields = new Map(); |
|
74 | + public static function merge(array $array, $merge_back=false) { |
|
75 | + if (!static::$fields) { |
|
76 | + static::$fields = new Map(); |
|
77 | + } |
|
62 | 78 | static::$fields->merge($array, $merge_back); |
63 | 79 | } |
64 | 80 | |
65 | - protected static function compact(){ |
|
66 | - if (!static::$fields) static::$fields = new Map(); |
|
81 | + protected static function compact() { |
|
82 | + if (!static::$fields) { |
|
83 | + static::$fields = new Map(); |
|
84 | + } |
|
67 | 85 | static::$fields->compact(); |
68 | 86 | } |
69 | 87 | |
@@ -71,8 +89,10 @@ discard block |
||
71 | 89 | return static::$fields->find($path, $create, $operation); |
72 | 90 | } |
73 | 91 | |
74 | - public function jsonSerialize(){ |
|
75 | - if (!static::$fields) static::$fields = new Map(); |
|
92 | + public function jsonSerialize() { |
|
93 | + if (!static::$fields) { |
|
94 | + static::$fields = new Map(); |
|
95 | + } |
|
76 | 96 | return static::$fields->jsonSerialize(); |
77 | 97 | } |
78 | 98 |
@@ -14,8 +14,8 @@ |
||
14 | 14 | use Module; |
15 | 15 | |
16 | 16 | protected static $driver, |
17 | - $options, |
|
18 | - $driver_name; |
|
17 | + $options, |
|
18 | + $driver_name; |
|
19 | 19 | |
20 | 20 | public static function using($driver, $options = null){ |
21 | 21 | $class = 'Email\\'.ucfirst(strtolower($driver)); |
@@ -17,17 +17,17 @@ discard block |
||
17 | 17 | $options, |
18 | 18 | $driver_name; |
19 | 19 | |
20 | - public static function using($driver, $options = null){ |
|
20 | + public static function using($driver, $options = null) { |
|
21 | 21 | $class = 'Email\\'.ucfirst(strtolower($driver)); |
22 | - if ( ! class_exists($class) ) throw new Exception("[core.email] : $driver driver not found."); |
|
22 | + if (!class_exists($class)) throw new Exception("[core.email] : $driver driver not found."); |
|
23 | 23 | static::$driver_name = $driver; |
24 | 24 | static::$options = $options; |
25 | 25 | static::$driver = new $class; |
26 | 26 | static::$driver->onInit($options); |
27 | 27 | } |
28 | 28 | |
29 | - public static function create($mail=[]){ |
|
30 | - if (is_a($mail, 'Email\\Envelope')){ |
|
29 | + public static function create($mail = []) { |
|
30 | + if (is_a($mail, 'Email\\Envelope')) { |
|
31 | 31 | return $mail; |
32 | 32 | } else { |
33 | 33 | return new Email\Envelope(array_merge([ |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | - public static function send($mail){ |
|
46 | + public static function send($mail) { |
|
47 | 47 | return static::$driver->onSend(static::create($mail)); |
48 | 48 | } |
49 | 49 |
@@ -17,17 +17,19 @@ discard block |
||
17 | 17 | $options, |
18 | 18 | $driver_name; |
19 | 19 | |
20 | - public static function using($driver, $options = null){ |
|
20 | + public static function using($driver, $options = null) { |
|
21 | 21 | $class = 'Email\\'.ucfirst(strtolower($driver)); |
22 | - if ( ! class_exists($class) ) throw new Exception("[core.email] : $driver driver not found."); |
|
22 | + if ( ! class_exists($class) ) { |
|
23 | + throw new Exception("[core.email] : $driver driver not found."); |
|
24 | + } |
|
23 | 25 | static::$driver_name = $driver; |
24 | 26 | static::$options = $options; |
25 | 27 | static::$driver = new $class; |
26 | 28 | static::$driver->onInit($options); |
27 | 29 | } |
28 | 30 | |
29 | - public static function create($mail=[]){ |
|
30 | - if (is_a($mail, 'Email\\Envelope')){ |
|
31 | + public static function create($mail=[]) { |
|
32 | + if (is_a($mail, 'Email\\Envelope')) { |
|
31 | 33 | return $mail; |
32 | 34 | } else { |
33 | 35 | return new Email\Envelope(array_merge([ |
@@ -43,7 +45,7 @@ discard block |
||
43 | 45 | } |
44 | 46 | } |
45 | 47 | |
46 | - public static function send($mail){ |
|
48 | + public static function send($mail) { |
|
47 | 49 | return static::$driver->onSend(static::create($mail)); |
48 | 50 | } |
49 | 51 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | trait Module { |
14 | 14 | static protected $__classMethods = array(); |
15 | 15 | |
16 | - public function __call($name, $args){ |
|
16 | + public function __call($name, $args) { |
|
17 | 17 | if (isset(static::$__classMethods[$name]) && static::$__classMethods[$name] instanceof \Closure) { |
18 | 18 | return call_user_func_array(static::$__classMethods[$name]->bindTo($this, $this), $args); |
19 | 19 | } |
@@ -25,19 +25,19 @@ discard block |
||
25 | 25 | throw new \BadMethodCallException; |
26 | 26 | } |
27 | 27 | |
28 | - public static function __prototypeAdd($name, \Closure $method){ |
|
28 | + public static function __prototypeAdd($name, \Closure $method) { |
|
29 | 29 | static::$__classMethods[$name] = $method; |
30 | 30 | } |
31 | 31 | |
32 | - public static function __prototypeGet($name){ |
|
33 | - return isset(static::$__classMethods[$name])?static::$__classMethods[$name]:null; |
|
32 | + public static function __prototypeGet($name) { |
|
33 | + return isset(static::$__classMethods[$name]) ? static::$__classMethods[$name] : null; |
|
34 | 34 | } |
35 | 35 | |
36 | - public static function __prototypeRemove($name){ |
|
36 | + public static function __prototypeRemove($name) { |
|
37 | 37 | unset(static::$__classMethods[$name]); |
38 | 38 | } |
39 | 39 | |
40 | - public static function __callStatic($name, $args){ |
|
40 | + public static function __callStatic($name, $args) { |
|
41 | 41 | if (isset(static::$__classMethods[$name]) && static::$__classMethods[$name] instanceof \Closure) { |
42 | 42 | return forward_static_call_array(static::$__classMethods[$name], $args); |
43 | 43 | } |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | throw new \BadMethodCallException; |
50 | 50 | } |
51 | 51 | |
52 | - public static function extend($methodMap=[]){ |
|
52 | + public static function extend($methodMap = []) { |
|
53 | 53 | if ($methodMap) foreach ($methodMap as $name => $method) { |
54 | - if($method && $method instanceof \Closure) { |
|
55 | - static::__prototypeAdd($name,$method); |
|
54 | + if ($method && $method instanceof \Closure) { |
|
55 | + static::__prototypeAdd($name, $method); |
|
56 | 56 | } else throw new \BadMethodCallException; |
57 | 57 | } |
58 | 58 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | trait Module { |
14 | 14 | static protected $__classMethods = array(); |
15 | 15 | |
16 | - public function __call($name, $args){ |
|
16 | + public function __call($name, $args) { |
|
17 | 17 | if (isset(static::$__classMethods[$name]) && static::$__classMethods[$name] instanceof \Closure) { |
18 | 18 | return call_user_func_array(static::$__classMethods[$name]->bindTo($this, $this), $args); |
19 | 19 | } |
@@ -25,19 +25,19 @@ discard block |
||
25 | 25 | throw new \BadMethodCallException; |
26 | 26 | } |
27 | 27 | |
28 | - public static function __prototypeAdd($name, \Closure $method){ |
|
28 | + public static function __prototypeAdd($name, \Closure $method) { |
|
29 | 29 | static::$__classMethods[$name] = $method; |
30 | 30 | } |
31 | 31 | |
32 | - public static function __prototypeGet($name){ |
|
32 | + public static function __prototypeGet($name) { |
|
33 | 33 | return isset(static::$__classMethods[$name])?static::$__classMethods[$name]:null; |
34 | 34 | } |
35 | 35 | |
36 | - public static function __prototypeRemove($name){ |
|
36 | + public static function __prototypeRemove($name) { |
|
37 | 37 | unset(static::$__classMethods[$name]); |
38 | 38 | } |
39 | 39 | |
40 | - public static function __callStatic($name, $args){ |
|
40 | + public static function __callStatic($name, $args) { |
|
41 | 41 | if (isset(static::$__classMethods[$name]) && static::$__classMethods[$name] instanceof \Closure) { |
42 | 42 | return forward_static_call_array(static::$__classMethods[$name], $args); |
43 | 43 | } |
@@ -49,11 +49,15 @@ discard block |
||
49 | 49 | throw new \BadMethodCallException; |
50 | 50 | } |
51 | 51 | |
52 | - public static function extend($methodMap=[]){ |
|
53 | - if ($methodMap) foreach ($methodMap as $name => $method) { |
|
52 | + public static function extend($methodMap=[]) { |
|
53 | + if ($methodMap) { |
|
54 | + foreach ($methodMap as $name => $method) { |
|
54 | 55 | if($method && $method instanceof \Closure) { |
55 | 56 | static::__prototypeAdd($name,$method); |
56 | - } else throw new \BadMethodCallException; |
|
57 | + } |
|
58 | + } else { |
|
59 | + throw new \BadMethodCallException; |
|
60 | + } |
|
57 | 61 | } |
58 | 62 | } |
59 | 63 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | public static function send($id,$passValue) { |
37 | - isset(self::$workers[$id]) && self::$workers[$id]->pass($passValue); |
|
37 | + isset(self::$workers[$id]) && self::$workers[$id]->pass($passValue); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public static function run(){ |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $task = self::$pool->dequeue(); |
44 | 44 | $task->run(); |
45 | 45 | if ($task->complete()) { |
46 | - unset(self::$workers[$task->id()]); |
|
46 | + unset(self::$workers[$task->id()]); |
|
47 | 47 | } else { |
48 | 48 | self::$pool->enqueue($task); |
49 | 49 | } |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | protected static $workers; |
22 | 22 | protected static $lastID = 0; |
23 | 23 | |
24 | - public static function add($id,$job=null){ |
|
25 | - self::$pool or ( self::$pool = new \SplQueue() ); |
|
26 | - if(is_callable($id) && $job===null){ |
|
24 | + public static function add($id, $job = null) { |
|
25 | + self::$pool or (self::$pool = new \SplQueue()); |
|
26 | + if (is_callable($id) && $job === null) { |
|
27 | 27 | $job = $id; |
28 | 28 | $id = ++self::$lastID; |
29 | 29 | } |
@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | return $task; |
34 | 34 | } |
35 | 35 | |
36 | - public static function send($id,$passValue) { |
|
36 | + public static function send($id, $passValue) { |
|
37 | 37 | isset(self::$workers[$id]) && self::$workers[$id]->pass($passValue); |
38 | 38 | } |
39 | 39 | |
40 | - public static function run(){ |
|
41 | - self::$pool or ( self::$pool = new \SplQueue() ); |
|
40 | + public static function run() { |
|
41 | + self::$pool or (self::$pool = new \SplQueue()); |
|
42 | 42 | while (!self::$pool->isEmpty()) { |
43 | 43 | $task = self::$pool->dequeue(); |
44 | 44 | $task->run(); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | public function complete() { |
87 | - return ! $this->coroutine->valid(); |
|
87 | + return !$this->coroutine->valid(); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | } |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | protected static $workers; |
22 | 22 | protected static $lastID = 0; |
23 | 23 | |
24 | - public static function add($id,$job=null){ |
|
24 | + public static function add($id,$job=null) { |
|
25 | 25 | self::$pool or ( self::$pool = new \SplQueue() ); |
26 | - if(is_callable($id) && $job===null){ |
|
26 | + if(is_callable($id) && $job===null) { |
|
27 | 27 | $job = $id; |
28 | 28 | $id = ++self::$lastID; |
29 | 29 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | isset(self::$workers[$id]) && self::$workers[$id]->pass($passValue); |
38 | 38 | } |
39 | 39 | |
40 | - public static function run(){ |
|
40 | + public static function run() { |
|
41 | 41 | self::$pool or ( self::$pool = new \SplQueue() ); |
42 | 42 | while (!self::$pool->isEmpty()) { |
43 | 43 | $task = self::$pool->dequeue(); |
@@ -112,14 +112,14 @@ |
||
112 | 112 | ++$i; |
113 | 113 | $k1 = (((($k1 & 0xffff) * 0xcc9e2d51) |
114 | 114 | + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000)) * 0xcc9e2d51) & 0xffff) << 16))) |
115 | - & 0xffffffff; |
|
115 | + & 0xffffffff; |
|
116 | 116 | $k1 = $k1 << 15 | ($k1 >= 0 ? $k1 >> 17 : (($k1 & 0x7fffffff) >> 17) | 0x4000); |
117 | 117 | $k1 = (((($k1 & 0xffff) * 0x1b873593) + ((((($k1 >= 0 ? $k1 >> 16 : (($k1 & 0x7fffffff) >> 16) | 0x8000)) |
118 | 118 | * 0x1b873593) & 0xffff) << 16))) & 0xffffffff; |
119 | 119 | $h1 ^= $k1; |
120 | 120 | $h1 = $h1 << 13 | ($h1 >= 0 ? $h1 >> 19 : (($h1 & 0x7fffffff) >> 19) | 0x1000); |
121 | 121 | $h1b = (((($h1 & 0xffff) * 5) + ((((($h1 >= 0 ? $h1 >> 16 : (($h1 & 0x7fffffff) >> 16) | 0x8000)) * 5) |
122 | - & 0xffff) << 16))) & 0xffffffff; |
|
122 | + & 0xffff) << 16))) & 0xffffffff; |
|
123 | 123 | $h1 = ((($h1b & 0xffff) + 0x6b64) + ((((($h1b >= 0 ? $h1b >> 16 : (($h1b & 0x7fffffff) >> 16) | 0x8000)) |
124 | 124 | + 0xe654) & 0xffff) << 16)); |
125 | 125 | } |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | * @param integer $method The hashing method, default is "md5" |
21 | 21 | * @return string The hash string |
22 | 22 | */ |
23 | - public static function make($payload,$method='md5'){ |
|
24 | - return hash($method,serialize($payload)); |
|
23 | + public static function make($payload, $method = 'md5') { |
|
24 | + return hash($method, serialize($payload)); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | * @param integer $method The hashing method |
32 | 32 | * @return bool Returns `true` if payload matches hash |
33 | 33 | */ |
34 | - public static function verify($payload,$hash,$method='md5'){ |
|
35 | - return static::make($payload,$method) == $hash; |
|
34 | + public static function verify($payload, $hash, $method = 'md5') { |
|
35 | + return static::make($payload, $method) == $hash; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return array Array containing the list of supported hashing algorithms. |
44 | 44 | */ |
45 | - public static function methods(){ |
|
45 | + public static function methods() { |
|
46 | 46 | return hash_algos(); |
47 | 47 | } |
48 | 48 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return bool |
58 | 58 | */ |
59 | - public static function can($algo){ |
|
60 | - return in_array($algo,hash_algos()); |
|
59 | + public static function can($algo) { |
|
60 | + return in_array($algo, hash_algos()); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,29 +65,29 @@ discard block |
||
65 | 65 | * |
66 | 66 | * See [hash-algos](http://php.net/manual/it/function.hash-algos.php) for a list of algorithms |
67 | 67 | */ |
68 | - public static function __callStatic($method,$params){ |
|
69 | - return self::make(current($params),$method); |
|
68 | + public static function __callStatic($method, $params) { |
|
69 | + return self::make(current($params), $method); |
|
70 | 70 | } |
71 | 71 | |
72 | - public static function uuid($type=4, $namespace='', $name=''){ |
|
73 | - switch($type){ |
|
74 | - case 3: if(preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'. |
|
72 | + public static function uuid($type = 4, $namespace = '', $name = '') { |
|
73 | + switch ($type) { |
|
74 | + case 3: if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'. |
|
75 | 75 | '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) return false; |
76 | - $nhex = str_replace(array('-','{','}'), '', $namespace); |
|
77 | - $nstr = ''; for($i = 0; $i < strlen($nhex); $i+=2) |
|
78 | - $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); |
|
79 | - $hash = md5($nstr . $name); |
|
76 | + $nhex = str_replace(array('-', '{', '}'), '', $namespace); |
|
77 | + $nstr = '';for ($i = 0;$i < strlen($nhex);$i += 2) |
|
78 | + $nstr .= chr(hexdec($nhex[$i].$nhex[$i + 1])); |
|
79 | + $hash = md5($nstr.$name); |
|
80 | 80 | return sprintf('%08s-%04s-%04x-%04x-%12s', |
81 | 81 | substr($hash, 0, 8), substr($hash, 8, 4), |
82 | 82 | (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000, |
83 | 83 | (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000, |
84 | 84 | substr($hash, 20, 12)); |
85 | - case 5: if(preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'. |
|
85 | + case 5: if (preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'. |
|
86 | 86 | '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) return false; |
87 | - $nhex = str_replace(array('-','{','}'), '', $namespace); |
|
88 | - $nstr = ''; for($i = 0; $i < strlen($nhex); $i+=2) |
|
89 | - $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); |
|
90 | - $hash = sha1($nstr . $name); |
|
87 | + $nhex = str_replace(array('-', '{', '}'), '', $namespace); |
|
88 | + $nstr = '';for ($i = 0;$i < strlen($nhex);$i += 2) |
|
89 | + $nstr .= chr(hexdec($nhex[$i].$nhex[$i + 1])); |
|
90 | + $hash = sha1($nstr.$name); |
|
91 | 91 | return sprintf('%08s-%04s-%04x-%04x-%12s', |
92 | 92 | substr($hash, 0, 8), substr($hash, 8, 4), |
93 | 93 | (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000, |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - public static function murmurhash3_int($key, $seed=0){ |
|
103 | + public static function murmurhash3_int($key, $seed = 0) { |
|
104 | 104 | $key = (string) $key; |
105 | 105 | $klen = strlen($key); |
106 | 106 | $h1 = $seed; |
107 | - for ($i=0,$bytes=$klen-($remainder=$klen&3) ; $i<$bytes ; ) { |
|
107 | + for ($i = 0, $bytes = $klen - ($remainder = $klen & 3);$i < $bytes;) { |
|
108 | 108 | $k1 = ((ord($key[$i]) & 0xff)) |
109 | 109 | | ((ord($key[++$i]) & 0xff) << 8) |
110 | 110 | | ((ord($key[++$i]) & 0xff) << 16) |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | return $h1; |
147 | 147 | } |
148 | 148 | |
149 | - public static function murmurhash3($key, $seed=0){ |
|
150 | - return base_convert(static::murmurhash3_int($key, $seed),10,32); |
|
149 | + public static function murmurhash3($key, $seed = 0) { |
|
150 | + return base_convert(static::murmurhash3_int($key, $seed), 10, 32); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @param integer $method The hashing method, default is "md5" |
21 | 21 | * @return string The hash string |
22 | 22 | */ |
23 | - public static function make($payload,$method='md5'){ |
|
23 | + public static function make($payload,$method='md5') { |
|
24 | 24 | return hash($method,serialize($payload)); |
25 | 25 | } |
26 | 26 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param integer $method The hashing method |
32 | 32 | * @return bool Returns `true` if payload matches hash |
33 | 33 | */ |
34 | - public static function verify($payload,$hash,$method='md5'){ |
|
34 | + public static function verify($payload,$hash,$method='md5') { |
|
35 | 35 | return static::make($payload,$method) == $hash; |
36 | 36 | } |
37 | 37 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return array Array containing the list of supported hashing algorithms. |
44 | 44 | */ |
45 | - public static function methods(){ |
|
45 | + public static function methods() { |
|
46 | 46 | return hash_algos(); |
47 | 47 | } |
48 | 48 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return bool |
58 | 58 | */ |
59 | - public static function can($algo){ |
|
59 | + public static function can($algo) { |
|
60 | 60 | return in_array($algo,hash_algos()); |
61 | 61 | } |
62 | 62 | |
@@ -65,14 +65,16 @@ discard block |
||
65 | 65 | * |
66 | 66 | * See [hash-algos](http://php.net/manual/it/function.hash-algos.php) for a list of algorithms |
67 | 67 | */ |
68 | - public static function __callStatic($method,$params){ |
|
68 | + public static function __callStatic($method,$params) { |
|
69 | 69 | return self::make(current($params),$method); |
70 | 70 | } |
71 | 71 | |
72 | - public static function uuid($type=4, $namespace='', $name=''){ |
|
73 | - switch($type){ |
|
72 | + public static function uuid($type=4, $namespace='', $name='') { |
|
73 | + switch($type) { |
|
74 | 74 | case 3: if(preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'. |
75 | - '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) return false; |
|
75 | + '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) { |
|
76 | + return false; |
|
77 | + } |
|
76 | 78 | $nhex = str_replace(array('-','{','}'), '', $namespace); |
77 | 79 | $nstr = ''; for($i = 0; $i < strlen($nhex); $i+=2) |
78 | 80 | $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); |
@@ -83,7 +85,9 @@ discard block |
||
83 | 85 | (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000, |
84 | 86 | substr($hash, 20, 12)); |
85 | 87 | case 5: if(preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'. |
86 | - '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) return false; |
|
88 | + '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/Si', $namespace) !== 1) { |
|
89 | + return false; |
|
90 | + } |
|
87 | 91 | $nhex = str_replace(array('-','{','}'), '', $namespace); |
88 | 92 | $nstr = ''; for($i = 0; $i < strlen($nhex); $i+=2) |
89 | 93 | $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); |
@@ -100,7 +104,7 @@ discard block |
||
100 | 104 | } |
101 | 105 | } |
102 | 106 | |
103 | - public static function murmurhash3_int($key, $seed=0){ |
|
107 | + public static function murmurhash3_int($key, $seed=0) { |
|
104 | 108 | $key = (string) $key; |
105 | 109 | $klen = strlen($key); |
106 | 110 | $h1 = $seed; |
@@ -146,7 +150,7 @@ discard block |
||
146 | 150 | return $h1; |
147 | 151 | } |
148 | 152 | |
149 | - public static function murmurhash3($key, $seed=0){ |
|
153 | + public static function murmurhash3($key, $seed=0) { |
|
150 | 154 | return base_convert(static::murmurhash3_int($key, $seed),10,32); |
151 | 155 | } |
152 | 156 |
@@ -15,23 +15,23 @@ discard block |
||
15 | 15 | class Files implements Adapter { |
16 | 16 | protected $options; |
17 | 17 | |
18 | - public static function valid(){ |
|
18 | + public static function valid() { |
|
19 | 19 | return true; |
20 | 20 | } |
21 | 21 | |
22 | - public function __construct($options=[]){ |
|
23 | - $this->options = (object) array_merge($options,[ |
|
22 | + public function __construct($options = []) { |
|
23 | + $this->options = (object) array_merge($options, [ |
|
24 | 24 | 'cache_dir' => sys_get_temp_dir().'/core_file_cache', |
25 | 25 | ]); |
26 | - $this->options->cache_dir = rtrim($this->options->cache_dir,'/'); |
|
27 | - if(false===is_dir($this->options->cache_dir)) mkdir($this->options->cache_dir,0777,true); |
|
26 | + $this->options->cache_dir = rtrim($this->options->cache_dir, '/'); |
|
27 | + if (false === is_dir($this->options->cache_dir)) mkdir($this->options->cache_dir, 0777, true); |
|
28 | 28 | $this->options->cache_dir .= '/'; |
29 | 29 | } |
30 | 30 | |
31 | - public function get($key){ |
|
31 | + public function get($key) { |
|
32 | 32 | $cache_file_name = $this->options->cache_dir.$key.'.cache.php'; |
33 | - if(is_file($cache_file_name) && $data = @unserialize(file_get_contents($cache_file_name))){ |
|
34 | - if($data[0] && (time() > $data[0])) { |
|
33 | + if (is_file($cache_file_name) && $data = @unserialize(file_get_contents($cache_file_name))) { |
|
34 | + if ($data[0] && (time() > $data[0])) { |
|
35 | 35 | unlink($cache_file_name); |
36 | 36 | return null; |
37 | 37 | } |
@@ -41,39 +41,39 @@ discard block |
||
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | - public function set($key,$value,$expire=0){ |
|
44 | + public function set($key, $value, $expire = 0) { |
|
45 | 45 | $cache_file_name = $this->options->cache_dir.$key.'.cache.php'; |
46 | - file_put_contents($cache_file_name,serialize([$expire?time()+$expire:0,$value])); |
|
46 | + file_put_contents($cache_file_name, serialize([$expire ? time() + $expire : 0, $value])); |
|
47 | 47 | } |
48 | 48 | |
49 | - public function delete($key){ |
|
49 | + public function delete($key) { |
|
50 | 50 | $cache_file_name = $this->options->cache_dir.$key.'.cache.php'; |
51 | - if(is_file($cache_file_name)) unlink($cache_file_name); |
|
51 | + if (is_file($cache_file_name)) unlink($cache_file_name); |
|
52 | 52 | } |
53 | 53 | |
54 | - public function exists($key){ |
|
54 | + public function exists($key) { |
|
55 | 55 | $cache_file_name = $this->options->cache_dir.$key.'.cache.php'; |
56 | - if(false === is_file($cache_file_name)) return false; |
|
57 | - $peek = file_get_contents($cache_file_name,false,null,-1,32); |
|
58 | - $expire = explode('{i:0;i:',$peek,2); |
|
59 | - $expire = explode(';',end($expire),2); |
|
56 | + if (false === is_file($cache_file_name)) return false; |
|
57 | + $peek = file_get_contents($cache_file_name, false, null, -1, 32); |
|
58 | + $expire = explode('{i:0;i:', $peek, 2); |
|
59 | + $expire = explode(';', end($expire), 2); |
|
60 | 60 | $expire = current($expire); |
61 | - if($expire && $expire < time()){ |
|
61 | + if ($expire && $expire < time()) { |
|
62 | 62 | unlink($cache_file_name); |
63 | 63 | return false; |
64 | 64 | } else return true; |
65 | 65 | } |
66 | 66 | |
67 | - public function flush(){ |
|
68 | - exec('rm -f ' . $this->options->cache_dir . '*.cache.php'); |
|
67 | + public function flush() { |
|
68 | + exec('rm -f '.$this->options->cache_dir.'*.cache.php'); |
|
69 | 69 | } |
70 | 70 | |
71 | - public function inc($key,$value=1){ |
|
72 | - if(null === ($current = $this->get($key))) $current = $value; else $current += $value; |
|
73 | - $this->set($key,$current); |
|
71 | + public function inc($key, $value = 1) { |
|
72 | + if (null === ($current = $this->get($key))) $current = $value;else $current += $value; |
|
73 | + $this->set($key, $current); |
|
74 | 74 | } |
75 | 75 | |
76 | - public function dec($key,$value=1){ |
|
77 | - $this->inc($key,-abs($value)); |
|
76 | + public function dec($key, $value = 1) { |
|
77 | + $this->inc($key, -abs($value)); |
|
78 | 78 | } |
79 | 79 | } |
@@ -15,22 +15,24 @@ discard block |
||
15 | 15 | class Files implements Adapter { |
16 | 16 | protected $options; |
17 | 17 | |
18 | - public static function valid(){ |
|
18 | + public static function valid() { |
|
19 | 19 | return true; |
20 | 20 | } |
21 | 21 | |
22 | - public function __construct($options=[]){ |
|
22 | + public function __construct($options=[]) { |
|
23 | 23 | $this->options = (object) array_merge($options,[ |
24 | 24 | 'cache_dir' => sys_get_temp_dir().'/core_file_cache', |
25 | 25 | ]); |
26 | 26 | $this->options->cache_dir = rtrim($this->options->cache_dir,'/'); |
27 | - if(false===is_dir($this->options->cache_dir)) mkdir($this->options->cache_dir,0777,true); |
|
27 | + if(false===is_dir($this->options->cache_dir)) { |
|
28 | + mkdir($this->options->cache_dir,0777,true); |
|
29 | + } |
|
28 | 30 | $this->options->cache_dir .= '/'; |
29 | 31 | } |
30 | 32 | |
31 | - public function get($key){ |
|
33 | + public function get($key) { |
|
32 | 34 | $cache_file_name = $this->options->cache_dir.$key.'.cache.php'; |
33 | - if(is_file($cache_file_name) && $data = @unserialize(file_get_contents($cache_file_name))){ |
|
35 | + if(is_file($cache_file_name) && $data = @unserialize(file_get_contents($cache_file_name))) { |
|
34 | 36 | if($data[0] && (time() > $data[0])) { |
35 | 37 | unlink($cache_file_name); |
36 | 38 | return null; |
@@ -41,39 +43,49 @@ discard block |
||
41 | 43 | } |
42 | 44 | } |
43 | 45 | |
44 | - public function set($key,$value,$expire=0){ |
|
46 | + public function set($key,$value,$expire=0) { |
|
45 | 47 | $cache_file_name = $this->options->cache_dir.$key.'.cache.php'; |
46 | 48 | file_put_contents($cache_file_name,serialize([$expire?time()+$expire:0,$value])); |
47 | 49 | } |
48 | 50 | |
49 | - public function delete($key){ |
|
51 | + public function delete($key) { |
|
50 | 52 | $cache_file_name = $this->options->cache_dir.$key.'.cache.php'; |
51 | - if(is_file($cache_file_name)) unlink($cache_file_name); |
|
53 | + if(is_file($cache_file_name)) { |
|
54 | + unlink($cache_file_name); |
|
55 | + } |
|
52 | 56 | } |
53 | 57 | |
54 | - public function exists($key){ |
|
58 | + public function exists($key) { |
|
55 | 59 | $cache_file_name = $this->options->cache_dir.$key.'.cache.php'; |
56 | - if(false === is_file($cache_file_name)) return false; |
|
60 | + if(false === is_file($cache_file_name)) { |
|
61 | + return false; |
|
62 | + } |
|
57 | 63 | $peek = file_get_contents($cache_file_name,false,null,-1,32); |
58 | 64 | $expire = explode('{i:0;i:',$peek,2); |
59 | 65 | $expire = explode(';',end($expire),2); |
60 | 66 | $expire = current($expire); |
61 | - if($expire && $expire < time()){ |
|
67 | + if($expire && $expire < time()) { |
|
62 | 68 | unlink($cache_file_name); |
63 | 69 | return false; |
64 | - } else return true; |
|
70 | + } else { |
|
71 | + return true; |
|
72 | + } |
|
65 | 73 | } |
66 | 74 | |
67 | - public function flush(){ |
|
75 | + public function flush() { |
|
68 | 76 | exec('rm -f ' . $this->options->cache_dir . '*.cache.php'); |
69 | 77 | } |
70 | 78 | |
71 | - public function inc($key,$value=1){ |
|
72 | - if(null === ($current = $this->get($key))) $current = $value; else $current += $value; |
|
79 | + public function inc($key,$value=1) { |
|
80 | + if(null === ($current = $this->get($key))) { |
|
81 | + $current = $value; |
|
82 | + } else { |
|
83 | + $current += $value; |
|
84 | + } |
|
73 | 85 | $this->set($key,$current); |
74 | 86 | } |
75 | 87 | |
76 | - public function dec($key,$value=1){ |
|
88 | + public function dec($key,$value=1) { |
|
77 | 89 | $this->inc($key,-abs($value)); |
78 | 90 | } |
79 | 91 | } |
@@ -12,15 +12,15 @@ |
||
12 | 12 | |
13 | 13 | namespace Cache; |
14 | 14 | |
15 | -interface Adapter { |
|
15 | +interface Adapter { |
|
16 | 16 | public function get($key); |
17 | - public function set($key,$value,$expire=0); |
|
17 | + public function set($key, $value, $expire = 0); |
|
18 | 18 | public function delete($key); |
19 | 19 | public function exists($key); |
20 | 20 | public function flush(); |
21 | 21 | |
22 | - public function inc($key,$value=1); |
|
23 | - public function dec($key,$value=1); |
|
22 | + public function inc($key, $value = 1); |
|
23 | + public function dec($key, $value = 1); |
|
24 | 24 | |
25 | 25 | public static function valid(); |
26 | 26 | } |
27 | 27 | \ No newline at end of file |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace Cache; |
14 | 14 | |
15 | -interface Adapter { |
|
15 | +interface Adapter { |
|
16 | 16 | public function get($key); |
17 | 17 | public function set($key,$value,$expire=0); |
18 | 18 | public function delete($key); |