@@ -15,40 +15,40 @@ |
||
15 | 15 | class Memory implements Adapter { |
16 | 16 | protected $storage = []; |
17 | 17 | |
18 | - public function exists($path){ |
|
18 | + public function exists($path) { |
|
19 | 19 | return isset($this->storage[$path]); |
20 | 20 | } |
21 | 21 | |
22 | - public function read($path){ |
|
22 | + public function read($path) { |
|
23 | 23 | return $this->exists($path) ? $this->storage[$path] : false; |
24 | 24 | } |
25 | 25 | |
26 | - public function write($path, $data){ |
|
26 | + public function write($path, $data) { |
|
27 | 27 | $this->storage[$path] = $data; |
28 | 28 | } |
29 | 29 | |
30 | - public function append($path, $data){ |
|
30 | + public function append($path, $data) { |
|
31 | 31 | @$this->storage[$path] .= $data; |
32 | 32 | } |
33 | 33 | |
34 | - public function move($old, $new){ |
|
35 | - if($this->exists($old)){ |
|
34 | + public function move($old, $new) { |
|
35 | + if ($this->exists($old)) { |
|
36 | 36 | $this->storage[$new] = $this->storage[$old]; |
37 | 37 | unset($this->storage[$old]); |
38 | 38 | return true; |
39 | 39 | } else return false; |
40 | 40 | } |
41 | 41 | |
42 | - public function delete($path){ |
|
42 | + public function delete($path) { |
|
43 | 43 | unset($this->storage[$path]); |
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | |
47 | - public function search($pattern, $recursive=true){ |
|
47 | + public function search($pattern, $recursive = true) { |
|
48 | 48 | $results = []; |
49 | - $rx_pattern = '('.strtr($pattern,['.'=>'\.','*'=>'.*','?'=>'.']).')Ai'; |
|
49 | + $rx_pattern = '('.strtr($pattern, ['.'=>'\.', '*'=>'.*', '?'=>'.']).')Ai'; |
|
50 | 50 | foreach (array_keys($this->storage) as $path) { |
51 | - if (preg_match($rx_pattern,$path)) $results[] = $path; |
|
51 | + if (preg_match($rx_pattern, $path)) $results[] = $path; |
|
52 | 52 | } |
53 | 53 | return $results; |
54 | 54 | } |
@@ -15,40 +15,44 @@ |
||
15 | 15 | class Memory implements Adapter { |
16 | 16 | protected $storage = []; |
17 | 17 | |
18 | - public function exists($path){ |
|
18 | + public function exists($path) { |
|
19 | 19 | return isset($this->storage[$path]); |
20 | 20 | } |
21 | 21 | |
22 | - public function read($path){ |
|
22 | + public function read($path) { |
|
23 | 23 | return $this->exists($path) ? $this->storage[$path] : false; |
24 | 24 | } |
25 | 25 | |
26 | - public function write($path, $data){ |
|
26 | + public function write($path, $data) { |
|
27 | 27 | $this->storage[$path] = $data; |
28 | 28 | } |
29 | 29 | |
30 | - public function append($path, $data){ |
|
30 | + public function append($path, $data) { |
|
31 | 31 | @$this->storage[$path] .= $data; |
32 | 32 | } |
33 | 33 | |
34 | - public function move($old, $new){ |
|
35 | - if($this->exists($old)){ |
|
34 | + public function move($old, $new) { |
|
35 | + if($this->exists($old)) { |
|
36 | 36 | $this->storage[$new] = $this->storage[$old]; |
37 | 37 | unset($this->storage[$old]); |
38 | 38 | return true; |
39 | - } else return false; |
|
39 | + } else { |
|
40 | + return false; |
|
41 | + } |
|
40 | 42 | } |
41 | 43 | |
42 | - public function delete($path){ |
|
44 | + public function delete($path) { |
|
43 | 45 | unset($this->storage[$path]); |
44 | 46 | return true; |
45 | 47 | } |
46 | 48 | |
47 | - public function search($pattern, $recursive=true){ |
|
49 | + public function search($pattern, $recursive=true) { |
|
48 | 50 | $results = []; |
49 | 51 | $rx_pattern = '('.strtr($pattern,['.'=>'\.','*'=>'.*','?'=>'.']).')Ai'; |
50 | 52 | foreach (array_keys($this->storage) as $path) { |
51 | - if (preg_match($rx_pattern,$path)) $results[] = $path; |
|
53 | + if (preg_match($rx_pattern,$path)) { |
|
54 | + $results[] = $path; |
|
55 | + } |
|
52 | 56 | } |
53 | 57 | return $results; |
54 | 58 | } |
@@ -135,14 +135,14 @@ discard block |
||
135 | 135 | */ |
136 | 136 | private static function persistenceLoadDefault($pk, $table, $options){ |
137 | 137 | if ( $data = SQL::single("SELECT * FROM $table WHERE {$options['key']}=? LIMIT 1",[$pk]) ){ |
138 | - $obj = new static; |
|
139 | - foreach ((array)$data as $key => $value) { |
|
140 | - $obj->$key = $value; |
|
141 | - } |
|
142 | - return $obj; |
|
143 | - } else { |
|
144 | - return null; |
|
145 | - } |
|
138 | + $obj = new static; |
|
139 | + foreach ((array)$data as $key => $value) { |
|
140 | + $obj->$key = $value; |
|
141 | + } |
|
142 | + return $obj; |
|
143 | + } else { |
|
144 | + return null; |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * Private Standard Save Method |
164 | 164 | */ |
165 | 165 | private function persistenceSaveDefault($table,$options){ |
166 | - return SQL::insertOrUpdate($table,array_filter((array)$this),$options['key']); |
|
166 | + return SQL::insertOrUpdate($table,array_filter((array)$this),$options['key']); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @param mixed $options The options passed to the persistence layer. |
21 | 21 | * @return mixed All options array or a single value |
22 | 22 | */ |
23 | - protected static function persistenceOptions($options=null){ |
|
23 | + protected static function persistenceOptions($options = null) { |
|
24 | 24 | static $_options = []; |
25 | 25 | |
26 | 26 | if ($options === null) return $_options; |
@@ -29,18 +29,18 @@ discard block |
||
29 | 29 | } else { |
30 | 30 | if (empty($_options['table'])) { |
31 | 31 | $self = get_called_class(); |
32 | - if (defined("$self::_PRIMARY_KEY_")){ |
|
32 | + if (defined("$self::_PRIMARY_KEY_")) { |
|
33 | 33 | $x = explode('.', $self::_PRIMARY_KEY_); |
34 | 34 | $_options = [ |
35 | 35 | 'table' => current($x), |
36 | - 'key' => isset($x[1])?$x[1]:'id', |
|
36 | + 'key' => isset($x[1]) ? $x[1] : 'id', |
|
37 | 37 | ]; |
38 | 38 | } else { |
39 | 39 | // User pluralized class name as default table |
40 | - switch(substr($s = strtolower($self),-1)){ |
|
41 | - case 'y': $table = substr($s,0,-1).'ies'; break; |
|
42 | - case 's': $table = substr($s,0,-1).'es'; break; |
|
43 | - default: $table = $s.'s'; break; |
|
40 | + switch (substr($s = strtolower($self), -1)) { |
|
41 | + case 'y': $table = substr($s, 0, -1).'ies';break; |
|
42 | + case 's': $table = substr($s, 0, -1).'es';break; |
|
43 | + default: $table = $s.'s';break; |
|
44 | 44 | } |
45 | 45 | // Default ID |
46 | 46 | $_options = [ |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param callable $callback The callback to use on model save |
62 | 62 | * @return callable Current save callback |
63 | 63 | */ |
64 | - protected static function persistenceSave(callable $callback=null){ |
|
64 | + protected static function persistenceSave(callable $callback = null) { |
|
65 | 65 | static $save_cb = null; |
66 | 66 | return $callback ? $save_cb = $callback : $save_cb; |
67 | 67 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param callable $callback The callback to use on model load |
75 | 75 | * @return callable Current load callback |
76 | 76 | */ |
77 | - protected static function persistenceLoad(callable $callback=null){ |
|
77 | + protected static function persistenceLoad(callable $callback = null) { |
|
78 | 78 | static $retrieve_cb = null; |
79 | 79 | return $callback ? $retrieve_cb = $callback : $retrieve_cb; |
80 | 80 | } |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | * @param array $options An associative array with options for the persistance layer. |
90 | 90 | * @return void |
91 | 91 | */ |
92 | - public static function persistOn($table, array $options=[]){ |
|
93 | - $options = array_merge($options,[ |
|
92 | + public static function persistOn($table, array $options = []) { |
|
93 | + $options = array_merge($options, [ |
|
94 | 94 | 'key' => 'id' |
95 | 95 | ]); |
96 | 96 | $options['table'] = $table; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param callable $callback The callback to use on model save |
104 | 104 | * @return void |
105 | 105 | */ |
106 | - public static function onSave(callable $callback){ |
|
106 | + public static function onSave(callable $callback) { |
|
107 | 107 | static::persistenceSave($callback); |
108 | 108 | } |
109 | 109 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param callable $callback The callback to use on model load |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - public static function onLoad(callable $callback){ |
|
115 | + public static function onLoad(callable $callback) { |
|
116 | 116 | static::persistenceLoad($callback); |
117 | 117 | } |
118 | 118 | |
@@ -120,23 +120,23 @@ discard block |
||
120 | 120 | * Load the model from the persistence layer |
121 | 121 | * @return mixed The retrieved object |
122 | 122 | */ |
123 | - public static function load($pk){ |
|
123 | + public static function load($pk) { |
|
124 | 124 | $table = static::persistenceOptions('table'); |
125 | 125 | $cb = static::persistenceLoad(); |
126 | 126 | $op = static::persistenceOptions(); |
127 | 127 | |
128 | 128 | // Use standard persistence on DB layer |
129 | - return ( false == is_callable($cb) ) ? |
|
130 | - static::persistenceLoadDefault($pk,$table,$op) : $cb($pk,$table,$op); |
|
129 | + return (false == is_callable($cb)) ? |
|
130 | + static::persistenceLoadDefault($pk, $table, $op) : $cb($pk, $table, $op); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * Private Standard Load Method |
135 | 135 | */ |
136 | - private static function persistenceLoadDefault($pk, $table, $options){ |
|
137 | - if ( $data = SQL::single("SELECT * FROM $table WHERE {$options['key']}=? LIMIT 1",[$pk]) ){ |
|
136 | + private static function persistenceLoadDefault($pk, $table, $options) { |
|
137 | + if ($data = SQL::single("SELECT * FROM $table WHERE {$options['key']}=? LIMIT 1", [$pk])) { |
|
138 | 138 | $obj = new static; |
139 | - foreach ((array)$data as $key => $value) { |
|
139 | + foreach ((array) $data as $key => $value) { |
|
140 | 140 | $obj->$key = $value; |
141 | 141 | } |
142 | 142 | return $obj; |
@@ -149,21 +149,21 @@ discard block |
||
149 | 149 | * Save the model to the persistence layer |
150 | 150 | * @return mixed The results from the save callback. (default: lastInsertID) |
151 | 151 | */ |
152 | - public function save(){ |
|
152 | + public function save() { |
|
153 | 153 | $table = static::persistenceOptions('table'); |
154 | 154 | $op = static::persistenceOptions(); |
155 | 155 | $cb = static::persistenceSave(); |
156 | 156 | |
157 | 157 | // Use standard persistence on DB layer |
158 | - $cb = $cb ? Closure::bind($cb, $this) : [$this,'persistenceSaveDefault']; |
|
159 | - return $cb($table,$op); |
|
158 | + $cb = $cb ? Closure::bind($cb, $this) : [$this, 'persistenceSaveDefault']; |
|
159 | + return $cb($table, $op); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | 163 | * Private Standard Save Method |
164 | 164 | */ |
165 | - private function persistenceSaveDefault($table,$options){ |
|
166 | - return SQL::insertOrUpdate($table,array_filter((array)$this),$options['key']); |
|
165 | + private function persistenceSaveDefault($table, $options) { |
|
166 | + return SQL::insertOrUpdate($table, array_filter((array) $this), $options['key']); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 |
@@ -20,16 +20,18 @@ discard block |
||
20 | 20 | * @param mixed $options The options passed to the persistence layer. |
21 | 21 | * @return mixed All options array or a single value |
22 | 22 | */ |
23 | - protected static function persistenceOptions($options=null){ |
|
23 | + protected static function persistenceOptions($options=null) { |
|
24 | 24 | static $_options = []; |
25 | 25 | |
26 | - if ($options === null) return $_options; |
|
26 | + if ($options === null) { |
|
27 | + return $_options; |
|
28 | + } |
|
27 | 29 | if (is_array($options)) { |
28 | 30 | return $_options = $options; |
29 | 31 | } else { |
30 | 32 | if (empty($_options['table'])) { |
31 | 33 | $self = get_called_class(); |
32 | - if (defined("$self::_PRIMARY_KEY_")){ |
|
34 | + if (defined("$self::_PRIMARY_KEY_")) { |
|
33 | 35 | $x = explode('.', $self::_PRIMARY_KEY_); |
34 | 36 | $_options = [ |
35 | 37 | 'table' => current($x), |
@@ -37,7 +39,7 @@ discard block |
||
37 | 39 | ]; |
38 | 40 | } else { |
39 | 41 | // User pluralized class name as default table |
40 | - switch(substr($s = strtolower($self),-1)){ |
|
42 | + switch(substr($s = strtolower($self),-1)) { |
|
41 | 43 | case 'y': $table = substr($s,0,-1).'ies'; break; |
42 | 44 | case 's': $table = substr($s,0,-1).'es'; break; |
43 | 45 | default: $table = $s.'s'; break; |
@@ -61,7 +63,7 @@ discard block |
||
61 | 63 | * @param callable $callback The callback to use on model save |
62 | 64 | * @return callable Current save callback |
63 | 65 | */ |
64 | - protected static function persistenceSave(callable $callback=null){ |
|
66 | + protected static function persistenceSave(callable $callback=null) { |
|
65 | 67 | static $save_cb = null; |
66 | 68 | return $callback ? $save_cb = $callback : $save_cb; |
67 | 69 | } |
@@ -74,7 +76,7 @@ discard block |
||
74 | 76 | * @param callable $callback The callback to use on model load |
75 | 77 | * @return callable Current load callback |
76 | 78 | */ |
77 | - protected static function persistenceLoad(callable $callback=null){ |
|
79 | + protected static function persistenceLoad(callable $callback=null) { |
|
78 | 80 | static $retrieve_cb = null; |
79 | 81 | return $callback ? $retrieve_cb = $callback : $retrieve_cb; |
80 | 82 | } |
@@ -89,7 +91,7 @@ discard block |
||
89 | 91 | * @param array $options An associative array with options for the persistance layer. |
90 | 92 | * @return void |
91 | 93 | */ |
92 | - public static function persistOn($table, array $options=[]){ |
|
94 | + public static function persistOn($table, array $options=[]) { |
|
93 | 95 | $options = array_merge($options,[ |
94 | 96 | 'key' => 'id' |
95 | 97 | ]); |
@@ -103,7 +105,7 @@ discard block |
||
103 | 105 | * @param callable $callback The callback to use on model save |
104 | 106 | * @return void |
105 | 107 | */ |
106 | - public static function onSave(callable $callback){ |
|
108 | + public static function onSave(callable $callback) { |
|
107 | 109 | static::persistenceSave($callback); |
108 | 110 | } |
109 | 111 | |
@@ -112,7 +114,7 @@ discard block |
||
112 | 114 | * @param callable $callback The callback to use on model load |
113 | 115 | * @return void |
114 | 116 | */ |
115 | - public static function onLoad(callable $callback){ |
|
117 | + public static function onLoad(callable $callback) { |
|
116 | 118 | static::persistenceLoad($callback); |
117 | 119 | } |
118 | 120 | |
@@ -120,7 +122,7 @@ discard block |
||
120 | 122 | * Load the model from the persistence layer |
121 | 123 | * @return mixed The retrieved object |
122 | 124 | */ |
123 | - public static function load($pk){ |
|
125 | + public static function load($pk) { |
|
124 | 126 | $table = static::persistenceOptions('table'); |
125 | 127 | $cb = static::persistenceLoad(); |
126 | 128 | $op = static::persistenceOptions(); |
@@ -133,8 +135,8 @@ discard block |
||
133 | 135 | /** |
134 | 136 | * Private Standard Load Method |
135 | 137 | */ |
136 | - private static function persistenceLoadDefault($pk, $table, $options){ |
|
137 | - if ( $data = SQL::single("SELECT * FROM $table WHERE {$options['key']}=? LIMIT 1",[$pk]) ){ |
|
138 | + private static function persistenceLoadDefault($pk, $table, $options) { |
|
139 | + if ( $data = SQL::single("SELECT * FROM $table WHERE {$options['key']}=? LIMIT 1",[$pk]) ) { |
|
138 | 140 | $obj = new static; |
139 | 141 | foreach ((array)$data as $key => $value) { |
140 | 142 | $obj->$key = $value; |
@@ -149,7 +151,7 @@ discard block |
||
149 | 151 | * Save the model to the persistence layer |
150 | 152 | * @return mixed The results from the save callback. (default: lastInsertID) |
151 | 153 | */ |
152 | - public function save(){ |
|
154 | + public function save() { |
|
153 | 155 | $table = static::persistenceOptions('table'); |
154 | 156 | $op = static::persistenceOptions(); |
155 | 157 | $cb = static::persistenceSave(); |
@@ -162,7 +164,7 @@ discard block |
||
162 | 164 | /** |
163 | 165 | * Private Standard Save Method |
164 | 166 | */ |
165 | - private function persistenceSaveDefault($table,$options){ |
|
167 | + private function persistenceSaveDefault($table,$options) { |
|
166 | 168 | return SQL::insertOrUpdate($table,array_filter((array)$this),$options['key']); |
167 | 169 | } |
168 | 170 |
@@ -17,15 +17,15 @@ discard block |
||
17 | 17 | $encoded_payload = implode('.', [rtrim(strtr(base64_encode(json_encode([ |
18 | 18 | 'typ' => 'JWT', |
19 | 19 | 'alg' => $algo, |
20 | - ])), '+/', '-_'),'='), |
|
21 | - rtrim(strtr(base64_encode(json_encode($payload)), '+/', '-_'),'='), |
|
20 | + ])), '+/', '-_'), '='), |
|
21 | + rtrim(strtr(base64_encode(json_encode($payload)), '+/', '-_'), '='), |
|
22 | 22 | ]); |
23 | - return $encoded_payload . '.' . static::sign($encoded_payload, $secret, $algo); |
|
23 | + return $encoded_payload.'.'.static::sign($encoded_payload, $secret, $algo); |
|
24 | 24 | } |
25 | 25 | |
26 | - public static function decode($jwt, $secret = null, $verify = true){ |
|
26 | + public static function decode($jwt, $secret = null, $verify = true) { |
|
27 | 27 | |
28 | - if (substr_count($jwt,'.') != 2) throw new \Exception('Token not valid'); |
|
28 | + if (substr_count($jwt, '.') != 2) throw new \Exception('Token not valid'); |
|
29 | 29 | |
30 | 30 | list($encoded_header, $encoded_payload, $client_sig) = explode('.', $jwt); |
31 | 31 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | 'HS256' => 'sha256', |
54 | 54 | ]; |
55 | 55 | if (empty($algos[$algo])) throw new \Exception('Signing algorithm not supported'); |
56 | - return rtrim(strtr(base64_encode(hash_hmac($algos[$algo], $payload, $secret, true)), '+/', '-_'),'='); |
|
56 | + return rtrim(strtr(base64_encode(hash_hmac($algos[$algo], $payload, $secret, true)), '+/', '-_'), '='); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | } |
@@ -23,24 +23,31 @@ discard block |
||
23 | 23 | return $encoded_payload . '.' . static::sign($encoded_payload, $secret, $algo); |
24 | 24 | } |
25 | 25 | |
26 | - public static function decode($jwt, $secret = null, $verify = true){ |
|
26 | + public static function decode($jwt, $secret = null, $verify = true) { |
|
27 | 27 | |
28 | - if (substr_count($jwt,'.') != 2) throw new \Exception('Token not valid'); |
|
28 | + if (substr_count($jwt,'.') != 2) { |
|
29 | + throw new \Exception('Token not valid'); |
|
30 | + } |
|
29 | 31 | |
30 | 32 | list($encoded_header, $encoded_payload, $client_sig) = explode('.', $jwt); |
31 | 33 | |
32 | - if (null === ($payload = json_decode(base64_decode(strtr($encoded_payload, '-_', '+/'))))) |
|
33 | - throw new \Exception('Invalid encoding'); |
|
34 | + if (null === ($payload = json_decode(base64_decode(strtr($encoded_payload, '-_', '+/'))))) { |
|
35 | + throw new \Exception('Invalid encoding'); |
|
36 | + } |
|
34 | 37 | |
35 | 38 | |
36 | 39 | if ($verify) { |
37 | - if (null === ($header = json_decode(base64_decode(strtr($encoded_header, '-_', '+/'))))) |
|
38 | - throw new \Exception('Invalid encoding'); |
|
40 | + if (null === ($header = json_decode(base64_decode(strtr($encoded_header, '-_', '+/'))))) { |
|
41 | + throw new \Exception('Invalid encoding'); |
|
42 | + } |
|
39 | 43 | |
40 | - if (empty($header->alg)) throw new \Exception('Invalid encoding'); |
|
44 | + if (empty($header->alg)) { |
|
45 | + throw new \Exception('Invalid encoding'); |
|
46 | + } |
|
41 | 47 | |
42 | - if ($client_sig != static::sign("$encoded_header.$encoded_payload", $secret, $header->alg)) |
|
43 | - throw new \Exception('Token verification failed'); |
|
48 | + if ($client_sig != static::sign("$encoded_header.$encoded_payload", $secret, $header->alg)) { |
|
49 | + throw new \Exception('Token verification failed'); |
|
50 | + } |
|
44 | 51 | } |
45 | 52 | |
46 | 53 | return $payload; |
@@ -52,7 +59,9 @@ discard block |
||
52 | 59 | 'HS384' => 'sha384', |
53 | 60 | 'HS256' => 'sha256', |
54 | 61 | ]; |
55 | - if (empty($algos[$algo])) throw new \Exception('Signing algorithm not supported'); |
|
62 | + if (empty($algos[$algo])) { |
|
63 | + throw new \Exception('Signing algorithm not supported'); |
|
64 | + } |
|
56 | 65 | return rtrim(strtr(base64_encode(hash_hmac($algos[$algo], $payload, $secret, true)), '+/', '-_'),'='); |
57 | 66 | } |
58 | 67 |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | * @param mixed $default (optional) The default value. If is a callable it will executed and the return value will be used. |
30 | 30 | * @return mixed The value of the key or the default (resolved) value if the key not existed. |
31 | 31 | */ |
32 | - public function get($key, $default=null){ |
|
33 | - if ($ptr =& static::find($key,false)){ |
|
32 | + public function get($key, $default = null) { |
|
33 | + if ($ptr = & static::find($key, false)) { |
|
34 | 34 | return $ptr; |
35 | 35 | } else { |
36 | - if ($default !== null){ |
|
36 | + if ($default !== null) { |
|
37 | 37 | return static::set($key, is_callable($default) ? call_user_func($default) : $default); |
38 | 38 | } else { |
39 | 39 | return null; |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | * @param mixed $value (optional) The value. If is a callable it will executed and the return value will be used. |
48 | 48 | * @return mixed The value of the key or the default (resolved) value if the key not existed. |
49 | 49 | */ |
50 | - public function set($key, $value=null){ |
|
50 | + public function set($key, $value = null) { |
|
51 | 51 | if (is_array($key)) { |
52 | 52 | return static::merge($key); |
53 | 53 | } else { |
54 | - $ptr = & static::find($key,true); |
|
54 | + $ptr = & static::find($key, true); |
|
55 | 55 | return $ptr = $value; |
56 | 56 | } |
57 | 57 | } |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param string $key The key path in dot notation |
62 | 62 | * @param boolean $compact (optional) Compact map removing empty paths. |
63 | 63 | */ |
64 | - public function delete($key, $compact=true){ |
|
65 | - static::set($key,null); |
|
64 | + public function delete($key, $compact = true) { |
|
65 | + static::set($key, null); |
|
66 | 66 | if ($compact) static::compact(); |
67 | 67 | } |
68 | 68 | |
@@ -71,18 +71,18 @@ discard block |
||
71 | 71 | * @param string $key The key path in dot notation |
72 | 72 | * @return boolean |
73 | 73 | */ |
74 | - public function exists($key){ |
|
75 | - return null !== static::find($key,false); |
|
74 | + public function exists($key) { |
|
75 | + return null !== static::find($key, false); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Clear all key path in map. |
80 | 80 | */ |
81 | - public function clear(){ |
|
81 | + public function clear() { |
|
82 | 82 | $this->fields = []; |
83 | 83 | } |
84 | 84 | |
85 | - public function __construct($fields=null){ |
|
85 | + public function __construct($fields = null) { |
|
86 | 86 | $this->load($fields); |
87 | 87 | } |
88 | 88 | |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | * Load an associative array/object as the map source. |
91 | 91 | * @param string $fields The array to merge |
92 | 92 | */ |
93 | - public function load($fields){ |
|
94 | - if ($fields) $this->fields = (array)$fields; |
|
93 | + public function load($fields) { |
|
94 | + if ($fields) $this->fields = (array) $fields; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param array $array The array to merge |
100 | 100 | * @param boolean $merge_back If `true` merge the map over the $array, if `false` (default) the reverse. |
101 | 101 | */ |
102 | - public function merge(array $array, $merge_back=false){ |
|
102 | + public function merge(array $array, $merge_back = false) { |
|
103 | 103 | $this->fields = $merge_back |
104 | 104 | ? array_replace_recursive($array, $this->fields) |
105 | 105 | : array_replace_recursive($this->fields, $array); |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | /** |
109 | 109 | * Compact map removing empty paths |
110 | 110 | */ |
111 | - public function compact(){ |
|
111 | + public function compact() { |
|
112 | 112 | function array_filter_rec($input, $callback = null) { |
113 | 113 | foreach ($input as &$value) { |
114 | 114 | if (is_array($value)) { |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | return array_filter($input, $callback); |
119 | 119 | } |
120 | 120 | |
121 | - $this->fields = array_filter_rec($this->fields,function($a){ return $a !== null; }); |
|
121 | + $this->fields = array_filter_rec($this->fields, function($a) { return $a !== null;}); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -128,15 +128,15 @@ discard block |
||
128 | 128 | * @param callable If passed this callback will be applied to the founded value. |
129 | 129 | * @return mixed The founded value. |
130 | 130 | */ |
131 | - public function & find($path, $create=false, callable $operation=null) { |
|
132 | - $tok = strtok($path,'.'); |
|
133 | - if($create){ |
|
134 | - $value =& $this->fields; |
|
131 | + public function & find($path, $create = false, callable $operation = null) { |
|
132 | + $tok = strtok($path, '.'); |
|
133 | + if ($create) { |
|
134 | + $value = & $this->fields; |
|
135 | 135 | } else { |
136 | 136 | $value = $this->fields; |
137 | 137 | } |
138 | - while($tok !== false){ |
|
139 | - $value =& $value[$tok]; |
|
138 | + while ($tok !== false) { |
|
139 | + $value = & $value[$tok]; |
|
140 | 140 | $tok = strtok('.'); |
141 | 141 | } |
142 | 142 | if (is_callable($operation)) $operation($value); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return string The json object |
152 | 152 | */ |
153 | - public function jsonSerialize(){ |
|
153 | + public function jsonSerialize() { |
|
154 | 154 | return $this->fields; |
155 | 155 | } |
156 | 156 |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | * @param mixed $default (optional) The default value. If is a callable it will executed and the return value will be used. |
30 | 30 | * @return mixed The value of the key or the default (resolved) value if the key not existed. |
31 | 31 | */ |
32 | - public function get($key, $default=null){ |
|
33 | - if ($ptr =& static::find($key,false)){ |
|
32 | + public function get($key, $default=null) { |
|
33 | + if ($ptr =& static::find($key,false)) { |
|
34 | 34 | return $ptr; |
35 | 35 | } else { |
36 | - if ($default !== null){ |
|
36 | + if ($default !== null) { |
|
37 | 37 | return static::set($key, is_callable($default) ? call_user_func($default) : $default); |
38 | 38 | } else { |
39 | 39 | return null; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param mixed $value (optional) The value. If is a callable it will executed and the return value will be used. |
48 | 48 | * @return mixed The value of the key or the default (resolved) value if the key not existed. |
49 | 49 | */ |
50 | - public function set($key, $value=null){ |
|
50 | + public function set($key, $value=null) { |
|
51 | 51 | if (is_array($key)) { |
52 | 52 | return static::merge($key); |
53 | 53 | } else { |
@@ -61,9 +61,11 @@ discard block |
||
61 | 61 | * @param string $key The key path in dot notation |
62 | 62 | * @param boolean $compact (optional) Compact map removing empty paths. |
63 | 63 | */ |
64 | - public function delete($key, $compact=true){ |
|
64 | + public function delete($key, $compact=true) { |
|
65 | 65 | static::set($key,null); |
66 | - if ($compact) static::compact(); |
|
66 | + if ($compact) { |
|
67 | + static::compact(); |
|
68 | + } |
|
67 | 69 | } |
68 | 70 | |
69 | 71 | /** |
@@ -71,18 +73,18 @@ discard block |
||
71 | 73 | * @param string $key The key path in dot notation |
72 | 74 | * @return boolean |
73 | 75 | */ |
74 | - public function exists($key){ |
|
76 | + public function exists($key) { |
|
75 | 77 | return null !== static::find($key,false); |
76 | 78 | } |
77 | 79 | |
78 | 80 | /** |
79 | 81 | * Clear all key path in map. |
80 | 82 | */ |
81 | - public function clear(){ |
|
83 | + public function clear() { |
|
82 | 84 | $this->fields = []; |
83 | 85 | } |
84 | 86 | |
85 | - public function __construct($fields=null){ |
|
87 | + public function __construct($fields=null) { |
|
86 | 88 | $this->load($fields); |
87 | 89 | } |
88 | 90 | |
@@ -90,8 +92,10 @@ discard block |
||
90 | 92 | * Load an associative array/object as the map source. |
91 | 93 | * @param string $fields The array to merge |
92 | 94 | */ |
93 | - public function load($fields){ |
|
94 | - if ($fields) $this->fields = (array)$fields; |
|
95 | + public function load($fields) { |
|
96 | + if ($fields) { |
|
97 | + $this->fields = (array)$fields; |
|
98 | + } |
|
95 | 99 | } |
96 | 100 | |
97 | 101 | /** |
@@ -99,7 +103,7 @@ discard block |
||
99 | 103 | * @param array $array The array to merge |
100 | 104 | * @param boolean $merge_back If `true` merge the map over the $array, if `false` (default) the reverse. |
101 | 105 | */ |
102 | - public function merge(array $array, $merge_back=false){ |
|
106 | + public function merge(array $array, $merge_back=false) { |
|
103 | 107 | $this->fields = $merge_back |
104 | 108 | ? array_replace_recursive($array, $this->fields) |
105 | 109 | : array_replace_recursive($this->fields, $array); |
@@ -108,7 +112,7 @@ discard block |
||
108 | 112 | /** |
109 | 113 | * Compact map removing empty paths |
110 | 114 | */ |
111 | - public function compact(){ |
|
115 | + public function compact() { |
|
112 | 116 | function array_filter_rec($input, $callback = null) { |
113 | 117 | foreach ($input as &$value) { |
114 | 118 | if (is_array($value)) { |
@@ -130,16 +134,18 @@ discard block |
||
130 | 134 | */ |
131 | 135 | public function & find($path, $create=false, callable $operation=null) { |
132 | 136 | $tok = strtok($path,'.'); |
133 | - if($create){ |
|
137 | + if($create) { |
|
134 | 138 | $value =& $this->fields; |
135 | 139 | } else { |
136 | 140 | $value = $this->fields; |
137 | 141 | } |
138 | - while($tok !== false){ |
|
142 | + while($tok !== false) { |
|
139 | 143 | $value =& $value[$tok]; |
140 | 144 | $tok = strtok('.'); |
141 | 145 | } |
142 | - if (is_callable($operation)) $operation($value); |
|
146 | + if (is_callable($operation)) { |
|
147 | + $operation($value); |
|
148 | + } |
|
143 | 149 | return $value; |
144 | 150 | } |
145 | 151 | |
@@ -150,7 +156,7 @@ discard block |
||
150 | 156 | * |
151 | 157 | * @return string The json object |
152 | 158 | */ |
153 | - public function jsonSerialize(){ |
|
159 | + public function jsonSerialize() { |
|
154 | 160 | return $this->fields; |
155 | 161 | } |
156 | 162 |
@@ -15,40 +15,40 @@ |
||
15 | 15 | |
16 | 16 | protected static $_listeners = []; |
17 | 17 | |
18 | - public static function on($name,callable $listener){ |
|
18 | + public static function on($name, callable $listener) { |
|
19 | 19 | static::$_listeners[$name][] = $listener; |
20 | 20 | } |
21 | 21 | |
22 | - public static function single($name,callable $listener){ |
|
22 | + public static function single($name, callable $listener) { |
|
23 | 23 | static::$_listeners[$name] = [$listener]; |
24 | 24 | } |
25 | 25 | |
26 | - public static function off($name,callable $listener = null){ |
|
27 | - if($listener === null) { |
|
26 | + public static function off($name, callable $listener = null) { |
|
27 | + if ($listener === null) { |
|
28 | 28 | unset(static::$_listeners[$name]); |
29 | 29 | } else { |
30 | - if ($idx = array_search($listener,static::$_listeners[$name],true)) |
|
30 | + if ($idx = array_search($listener, static::$_listeners[$name], true)) |
|
31 | 31 | unset(static::$_listeners[$name][$idx]); |
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | - public static function alias($source,$alias){ |
|
36 | - static::$_listeners[$alias] =& static::$_listeners[$source]; |
|
35 | + public static function alias($source, $alias) { |
|
36 | + static::$_listeners[$alias] = & static::$_listeners[$source]; |
|
37 | 37 | } |
38 | 38 | |
39 | - public static function trigger($name){ |
|
40 | - if (false === empty(static::$_listeners[$name])){ |
|
39 | + public static function trigger($name) { |
|
40 | + if (false === empty(static::$_listeners[$name])) { |
|
41 | 41 | $args = func_get_args(); |
42 | 42 | array_shift($args); |
43 | 43 | $results = []; |
44 | 44 | foreach (static::$_listeners[$name] as $listener) { |
45 | - $results[] = call_user_func_array($listener,$args); |
|
45 | + $results[] = call_user_func_array($listener, $args); |
|
46 | 46 | } |
47 | 47 | return $results; |
48 | 48 | }; |
49 | 49 | } |
50 | 50 | |
51 | - public static function triggerOnce($name){ |
|
51 | + public static function triggerOnce($name) { |
|
52 | 52 | $res = static::trigger($name); |
53 | 53 | unset(static::$_listeners[$name]); |
54 | 54 | return $res; |
@@ -15,29 +15,30 @@ discard block |
||
15 | 15 | |
16 | 16 | protected static $_listeners = []; |
17 | 17 | |
18 | - public static function on($name,callable $listener){ |
|
18 | + public static function on($name,callable $listener) { |
|
19 | 19 | static::$_listeners[$name][] = $listener; |
20 | 20 | } |
21 | 21 | |
22 | - public static function single($name,callable $listener){ |
|
22 | + public static function single($name,callable $listener) { |
|
23 | 23 | static::$_listeners[$name] = [$listener]; |
24 | 24 | } |
25 | 25 | |
26 | - public static function off($name,callable $listener = null){ |
|
26 | + public static function off($name,callable $listener = null) { |
|
27 | 27 | if($listener === null) { |
28 | 28 | unset(static::$_listeners[$name]); |
29 | 29 | } else { |
30 | - if ($idx = array_search($listener,static::$_listeners[$name],true)) |
|
31 | - unset(static::$_listeners[$name][$idx]); |
|
30 | + if ($idx = array_search($listener,static::$_listeners[$name],true)) { |
|
31 | + unset(static::$_listeners[$name][$idx]); |
|
32 | + } |
|
32 | 33 | } |
33 | 34 | } |
34 | 35 | |
35 | - public static function alias($source,$alias){ |
|
36 | + public static function alias($source,$alias) { |
|
36 | 37 | static::$_listeners[$alias] =& static::$_listeners[$source]; |
37 | 38 | } |
38 | 39 | |
39 | - public static function trigger($name){ |
|
40 | - if (false === empty(static::$_listeners[$name])){ |
|
40 | + public static function trigger($name) { |
|
41 | + if (false === empty(static::$_listeners[$name])) { |
|
41 | 42 | $args = func_get_args(); |
42 | 43 | array_shift($args); |
43 | 44 | $results = []; |
@@ -48,7 +49,7 @@ discard block |
||
48 | 49 | }; |
49 | 50 | } |
50 | 51 | |
51 | - public static function triggerOnce($name){ |
|
52 | + public static function triggerOnce($name) { |
|
52 | 53 | $res = static::trigger($name); |
53 | 54 | unset(static::$_listeners[$name]); |
54 | 55 | return $res; |
@@ -12,44 +12,44 @@ |
||
12 | 12 | |
13 | 13 | class Defer { |
14 | 14 | |
15 | - use Module; |
|
15 | + use Module; |
|
16 | 16 | |
17 | - protected static $inited = false; |
|
17 | + protected static $inited = false; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Defer callback execution after script execution |
|
21 | - * @param callable $callback The deferred callback |
|
22 | - */ |
|
23 | - public static function after(callable $callback){ |
|
24 | - static::$inited || static::install(); |
|
25 | - Event::on('core.shutdown',$callback); |
|
26 | - } |
|
19 | + /** |
|
20 | + * Defer callback execution after script execution |
|
21 | + * @param callable $callback The deferred callback |
|
22 | + */ |
|
23 | + public static function after(callable $callback){ |
|
24 | + static::$inited || static::install(); |
|
25 | + Event::on('core.shutdown',$callback); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Single shot defer handeler install |
|
30 | - */ |
|
31 | - protected static function install(){ |
|
32 | - if (static::$inited) return; |
|
28 | + /** |
|
29 | + * Single shot defer handeler install |
|
30 | + */ |
|
31 | + protected static function install(){ |
|
32 | + if (static::$inited) return; |
|
33 | 33 | |
34 | - // Disable time limit |
|
35 | - set_time_limit(0); |
|
34 | + // Disable time limit |
|
35 | + set_time_limit(0); |
|
36 | 36 | |
37 | - // HHVM support |
|
38 | - if(function_exists('register_postsend_function')){ |
|
39 | - register_postsend_function(function(){ |
|
40 | - Event::trigger('core.shutdown'); |
|
41 | - }); |
|
42 | - } else if(function_exists('fastcgi_finish_request')) { |
|
43 | - register_shutdown_function(function(){ |
|
44 | - fastcgi_finish_request(); |
|
45 | - Event::trigger('core.shutdown'); |
|
46 | - }); |
|
47 | - } else { |
|
48 | - register_shutdown_function(function(){ |
|
49 | - Event::trigger('core.shutdown'); |
|
50 | - }); |
|
51 | - } |
|
37 | + // HHVM support |
|
38 | + if(function_exists('register_postsend_function')){ |
|
39 | + register_postsend_function(function(){ |
|
40 | + Event::trigger('core.shutdown'); |
|
41 | + }); |
|
42 | + } else if(function_exists('fastcgi_finish_request')) { |
|
43 | + register_shutdown_function(function(){ |
|
44 | + fastcgi_finish_request(); |
|
45 | + Event::trigger('core.shutdown'); |
|
46 | + }); |
|
47 | + } else { |
|
48 | + register_shutdown_function(function(){ |
|
49 | + Event::trigger('core.shutdown'); |
|
50 | + }); |
|
51 | + } |
|
52 | 52 | |
53 | - static::$inited = true; |
|
54 | - } |
|
53 | + static::$inited = true; |
|
54 | + } |
|
55 | 55 | } |
@@ -20,32 +20,32 @@ |
||
20 | 20 | * Defer callback execution after script execution |
21 | 21 | * @param callable $callback The deferred callback |
22 | 22 | */ |
23 | - public static function after(callable $callback){ |
|
23 | + public static function after(callable $callback) { |
|
24 | 24 | static::$inited || static::install(); |
25 | - Event::on('core.shutdown',$callback); |
|
25 | + Event::on('core.shutdown', $callback); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Single shot defer handeler install |
30 | 30 | */ |
31 | - protected static function install(){ |
|
31 | + protected static function install() { |
|
32 | 32 | if (static::$inited) return; |
33 | 33 | |
34 | 34 | // Disable time limit |
35 | 35 | set_time_limit(0); |
36 | 36 | |
37 | 37 | // HHVM support |
38 | - if(function_exists('register_postsend_function')){ |
|
39 | - register_postsend_function(function(){ |
|
38 | + if (function_exists('register_postsend_function')) { |
|
39 | + register_postsend_function(function() { |
|
40 | 40 | Event::trigger('core.shutdown'); |
41 | 41 | }); |
42 | - } else if(function_exists('fastcgi_finish_request')) { |
|
43 | - register_shutdown_function(function(){ |
|
42 | + } else if (function_exists('fastcgi_finish_request')) { |
|
43 | + register_shutdown_function(function() { |
|
44 | 44 | fastcgi_finish_request(); |
45 | 45 | Event::trigger('core.shutdown'); |
46 | 46 | }); |
47 | 47 | } else { |
48 | - register_shutdown_function(function(){ |
|
48 | + register_shutdown_function(function() { |
|
49 | 49 | Event::trigger('core.shutdown'); |
50 | 50 | }); |
51 | 51 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * Defer callback execution after script execution |
21 | 21 | * @param callable $callback The deferred callback |
22 | 22 | */ |
23 | - public static function after(callable $callback){ |
|
23 | + public static function after(callable $callback) { |
|
24 | 24 | static::$inited || static::install(); |
25 | 25 | Event::on('core.shutdown',$callback); |
26 | 26 | } |
@@ -28,24 +28,26 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * Single shot defer handeler install |
30 | 30 | */ |
31 | - protected static function install(){ |
|
32 | - if (static::$inited) return; |
|
31 | + protected static function install() { |
|
32 | + if (static::$inited) { |
|
33 | + return; |
|
34 | + } |
|
33 | 35 | |
34 | 36 | // Disable time limit |
35 | 37 | set_time_limit(0); |
36 | 38 | |
37 | 39 | // HHVM support |
38 | - if(function_exists('register_postsend_function')){ |
|
39 | - register_postsend_function(function(){ |
|
40 | + if(function_exists('register_postsend_function')) { |
|
41 | + register_postsend_function(function() { |
|
40 | 42 | Event::trigger('core.shutdown'); |
41 | 43 | }); |
42 | 44 | } else if(function_exists('fastcgi_finish_request')) { |
43 | - register_shutdown_function(function(){ |
|
45 | + register_shutdown_function(function() { |
|
44 | 46 | fastcgi_finish_request(); |
45 | 47 | Event::trigger('core.shutdown'); |
46 | 48 | }); |
47 | 49 | } else { |
48 | - register_shutdown_function(function(){ |
|
50 | + register_shutdown_function(function() { |
|
49 | 51 | Event::trigger('core.shutdown'); |
50 | 52 | }); |
51 | 53 | } |
@@ -13,15 +13,15 @@ discard block |
||
13 | 13 | class Negotiation { |
14 | 14 | protected $list; |
15 | 15 | |
16 | - public static function parse($query){ |
|
16 | + public static function parse($query) { |
|
17 | 17 | $list = new \SplPriorityQueue(); |
18 | 18 | array_map(function($e) use ($list) { |
19 | - preg_match_all('(([^;]+)(?=\s*;\s*(\w+)\s*=\s*([^;]+))*)',$e,$p); |
|
20 | - $params = array_map('trim',array_merge( |
|
21 | - [ 'type' => current($p[0]) ], array_combine($p[2], $p[3])) |
|
19 | + preg_match_all('(([^;]+)(?=\s*;\s*(\w+)\s*=\s*([^;]+))*)', $e, $p); |
|
20 | + $params = array_map('trim', array_merge( |
|
21 | + ['type' => current($p[0])], array_combine($p[2], $p[3])) |
|
22 | 22 | ); |
23 | 23 | unset($params['']); |
24 | - $params['q'] = isset($params['q']) ? 1.0*$params['q'] : $params['q'] = 1.0; |
|
24 | + $params['q'] = isset($params['q']) ? 1.0 * $params['q'] : $params['q'] = 1.0; |
|
25 | 25 | $list->insert($params, $params['q']); |
26 | 26 | },preg_split('(\s*,\s*)', $query)); |
27 | 27 | return array_values(iterator_to_array($list)); |
@@ -35,26 +35,26 @@ discard block |
||
35 | 35 | $this->list = self::parse(trim($query)); |
36 | 36 | } |
37 | 37 | |
38 | - public function preferred(){ |
|
38 | + public function preferred() { |
|
39 | 39 | return self::encodeParsedValue(current($this->list)); |
40 | 40 | } |
41 | 41 | |
42 | - protected static function encodeParsedValue($parsed){ |
|
43 | - unset($parsed['q']); // Hide quality key from output |
|
44 | - $type = $parsed['type']; // Extract type |
|
42 | + protected static function encodeParsedValue($parsed) { |
|
43 | + unset($parsed['q']);// Hide quality key from output |
|
44 | + $type = $parsed['type'];// Extract type |
|
45 | 45 | unset($parsed['type']); |
46 | - return implode(';', array_merge([$type], array_map(function($k,$v){ |
|
46 | + return implode(';', array_merge([$type], array_map(function($k, $v) { |
|
47 | 47 | return "$k=$v"; |
48 | 48 | }, array_keys($parsed), $parsed))); |
49 | 49 | } |
50 | 50 | |
51 | - public function best($choices){ |
|
52 | - $_choices = self::parse(trim($choices)); |
|
53 | - foreach ($this->list as $accept){ |
|
54 | - foreach ($_choices as $choice){ |
|
51 | + public function best($choices) { |
|
52 | + $_choices = self::parse(trim($choices)); |
|
53 | + foreach ($this->list as $accept) { |
|
54 | + foreach ($_choices as $choice) { |
|
55 | 55 | if (preg_match('('.strtr($accept["type"], |
56 | - [ '.' => '\.', '+' => '\+', '*' => '.+' ] |
|
57 | - ).')', $choice["type"])){ |
|
56 | + ['.' => '\.', '+' => '\+', '*' => '.+'] |
|
57 | + ).')', $choice["type"])) { |
|
58 | 58 | return self::encodeParsedValue($choice); |
59 | 59 | } |
60 | 60 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | class Negotiation { |
14 | 14 | protected $list; |
15 | 15 | |
16 | - public static function parse($query){ |
|
16 | + public static function parse($query) { |
|
17 | 17 | $list = new \SplPriorityQueue(); |
18 | 18 | array_map(function($e) use ($list) { |
19 | 19 | preg_match_all('(([^;]+)(?=\s*;\s*(\w+)\s*=\s*([^;]+))*)',$e,$p); |
@@ -35,26 +35,26 @@ discard block |
||
35 | 35 | $this->list = self::parse(trim($query)); |
36 | 36 | } |
37 | 37 | |
38 | - public function preferred(){ |
|
38 | + public function preferred() { |
|
39 | 39 | return self::encodeParsedValue(current($this->list)); |
40 | 40 | } |
41 | 41 | |
42 | - protected static function encodeParsedValue($parsed){ |
|
42 | + protected static function encodeParsedValue($parsed) { |
|
43 | 43 | unset($parsed['q']); // Hide quality key from output |
44 | 44 | $type = $parsed['type']; // Extract type |
45 | 45 | unset($parsed['type']); |
46 | - return implode(';', array_merge([$type], array_map(function($k,$v){ |
|
46 | + return implode(';', array_merge([$type], array_map(function($k,$v) { |
|
47 | 47 | return "$k=$v"; |
48 | 48 | }, array_keys($parsed), $parsed))); |
49 | 49 | } |
50 | 50 | |
51 | - public function best($choices){ |
|
51 | + public function best($choices) { |
|
52 | 52 | $_choices = self::parse(trim($choices)); |
53 | - foreach ($this->list as $accept){ |
|
54 | - foreach ($_choices as $choice){ |
|
53 | + foreach ($this->list as $accept) { |
|
54 | + foreach ($_choices as $choice) { |
|
55 | 55 | if (preg_match('('.strtr($accept["type"], |
56 | 56 | [ '.' => '\.', '+' => '\+', '*' => '.+' ] |
57 | - ).')', $choice["type"])){ |
|
57 | + ).')', $choice["type"])) { |
|
58 | 58 | return self::encodeParsedValue($choice); |
59 | 59 | } |
60 | 60 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | * @copyright Caffeina srl - 2015 - http://caffeina.it |
11 | 11 | */ |
12 | 12 | |
13 | - class Password { |
|
13 | + class Password { |
|
14 | 14 | use Module; |
15 | 15 | |
16 | 16 | /** |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | * @param string $password |
19 | 19 | * @return string |
20 | 20 | */ |
21 | - public static function make($password){ |
|
21 | + public static function make($password) { |
|
22 | 22 | // Pre PHP 5.5 support |
23 | 23 | if (!defined('PASSWORD_DEFAULT')) { |
24 | - return '$5h$'.hash('sha1',$password); |
|
24 | + return '$5h$'.hash('sha1', $password); |
|
25 | 25 | } else { |
26 | - return password_hash($password,PASSWORD_BCRYPT,['cost' => 12]); |
|
26 | + return password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]); |
|
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | * @param string $hash The hash to match against |
34 | 34 | * @return bool Returns `true` if hash match password |
35 | 35 | */ |
36 | - public static function verify($password, $hash){ |
|
36 | + public static function verify($password, $hash) { |
|
37 | 37 | // Pre PHP 5.5 support |
38 | - if (!defined('PASSWORD_DEFAULT') || substr($hash,0,4)=='$5h$') { |
|
39 | - return '$5h$'.hash('sha1',$password) == $hash; |
|
38 | + if (!defined('PASSWORD_DEFAULT') || substr($hash, 0, 4) == '$5h$') { |
|
39 | + return '$5h$'.hash('sha1', $password) == $hash; |
|
40 | 40 | } else { |
41 | - return password_verify($password,$hash); |
|
41 | + return password_verify($password, $hash); |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param string $b Second string to compare |
50 | 50 | * @return boll Returns `true` if strings are the same |
51 | 51 | */ |
52 | - public static function compare($a, $b){ |
|
52 | + public static function compare($a, $b) { |
|
53 | 53 | return hash_equals($a, $b); |
54 | 54 | } |
55 | 55 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | // Polyfill hash_equals (PHP < 5.6.0) |
60 | 60 | // http://php.net/manual/en/function.hash-equals.php |
61 | -if(!function_exists('hash_equals')) { |
|
61 | +if (!function_exists('hash_equals')) { |
|
62 | 62 | function hash_equals($a, $b) { |
63 | 63 | return substr_count("$a" ^ "$b", "\0") * 2 === strlen("$a$b"); |
64 | 64 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param string $password |
19 | 19 | * @return string |
20 | 20 | */ |
21 | - public static function make($password){ |
|
21 | + public static function make($password) { |
|
22 | 22 | // Pre PHP 5.5 support |
23 | 23 | if (!defined('PASSWORD_DEFAULT')) { |
24 | 24 | return '$5h$'.hash('sha1',$password); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param string $hash The hash to match against |
34 | 34 | * @return bool Returns `true` if hash match password |
35 | 35 | */ |
36 | - public static function verify($password, $hash){ |
|
36 | + public static function verify($password, $hash) { |
|
37 | 37 | // Pre PHP 5.5 support |
38 | 38 | if (!defined('PASSWORD_DEFAULT') || substr($hash,0,4)=='$5h$') { |
39 | 39 | return '$5h$'.hash('sha1',$password) == $hash; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param string $b Second string to compare |
50 | 50 | * @return boll Returns `true` if strings are the same |
51 | 51 | */ |
52 | - public static function compare($a, $b){ |
|
52 | + public static function compare($a, $b) { |
|
53 | 53 | return hash_equals($a, $b); |
54 | 54 | } |
55 | 55 |
@@ -14,8 +14,8 @@ |
||
14 | 14 | use Module; |
15 | 15 | |
16 | 16 | public $file, |
17 | - $name, |
|
18 | - $zip; |
|
17 | + $name, |
|
18 | + $zip; |
|
19 | 19 | |
20 | 20 | public static function create($name=''){ |
21 | 21 | return new ZIP($name); |
@@ -17,42 +17,42 @@ discard block |
||
17 | 17 | $name, |
18 | 18 | $zip; |
19 | 19 | |
20 | - public static function create($name=''){ |
|
20 | + public static function create($name = '') { |
|
21 | 21 | return new ZIP($name); |
22 | 22 | } |
23 | 23 | |
24 | - public function __construct($name=''){ |
|
25 | - $this->name = preg_replace('/\.zip$/','',($name?:tempnam(sys_get_temp_dir(), 'ZExp').'-archive')); |
|
26 | - $this->file = $this->name . '.zip'; |
|
27 | - if (!preg_match('~^/|\./|\.\./~',$this->file)) $this->file = './'.$this->file; |
|
24 | + public function __construct($name = '') { |
|
25 | + $this->name = preg_replace('/\.zip$/', '', ($name ?: tempnam(sys_get_temp_dir(), 'ZExp').'-archive')); |
|
26 | + $this->file = $this->name.'.zip'; |
|
27 | + if (!preg_match('~^/|\./|\.\./~', $this->file)) $this->file = './'.$this->file; |
|
28 | 28 | $this->zip = new \ZipArchive; |
29 | - if ( true !== ($e = $this->zip->open($this->file, |
|
29 | + if (true !== ($e = $this->zip->open($this->file, |
|
30 | 30 | \ZipArchive::CREATE || \ZipArchive::OVERWRITE |
31 | 31 | ))) { |
32 | 32 | throw new Exception("Error opening temp ZIP file [".($this->file)."] Code $e", 1); |
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
36 | - public function __destruct(){ |
|
36 | + public function __destruct() { |
|
37 | 37 | $this->close(); |
38 | 38 | } |
39 | 39 | |
40 | - public function path(){ |
|
40 | + public function path() { |
|
41 | 41 | return $this->file; |
42 | 42 | } |
43 | 43 | |
44 | - public function write($filename, $data){ |
|
44 | + public function write($filename, $data) { |
|
45 | 45 | $this->zip->addFromString($filename, $data); |
46 | 46 | return $this; |
47 | 47 | } |
48 | 48 | |
49 | - public function close(){ |
|
50 | - if($this->zip) @$this->zip->close(); |
|
49 | + public function close() { |
|
50 | + if ($this->zip) @$this->zip->close(); |
|
51 | 51 | return $this; |
52 | 52 | } |
53 | 53 | |
54 | - public function addDirectory($folder, $root=null) { |
|
55 | - $folder = rtrim($folder,'/'); |
|
54 | + public function addDirectory($folder, $root = null) { |
|
55 | + $folder = rtrim($folder, '/'); |
|
56 | 56 | if (null === $root) { |
57 | 57 | $root = dirname($folder); |
58 | 58 | $folder = basename($folder); |
@@ -60,25 +60,25 @@ discard block |
||
60 | 60 | $this->zip->addEmptyDir($folder); |
61 | 61 | foreach (glob("$root/$folder/*") as $item) { |
62 | 62 | if (is_dir($item)) { |
63 | - $this->addDirectory(str_replace($root,'',$item),$root); |
|
64 | - } else if (is_file($item)) { |
|
65 | - $this->zip->addFile($item, str_replace($root,'',$item)); |
|
63 | + $this->addDirectory(str_replace($root, '', $item), $root); |
|
64 | + } else if (is_file($item)) { |
|
65 | + $this->zip->addFile($item, str_replace($root, '', $item)); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | 69 | return $this; |
70 | 70 | } |
71 | 71 | |
72 | - public function download(){ |
|
72 | + public function download() { |
|
73 | 73 | @$this->zip->close(); |
74 | 74 | header('Content-Type: application/zip'); |
75 | - header('Content-Disposition: attachment;filename="'.$this->name.'"',true); |
|
75 | + header('Content-Disposition: attachment;filename="'.$this->name.'"', true); |
|
76 | 76 | header('Content-Transfer-Encoding: binary'); |
77 | 77 | header('Expires: 0'); |
78 | 78 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
79 | 79 | header('Pragma: public'); |
80 | 80 | header('Content-Length: '.filesize($this->file)); |
81 | - while(ob_get_level()) ob_end_clean(); |
|
81 | + while (ob_get_level()) ob_end_clean(); |
|
82 | 82 | readfile($this->file); |
83 | 83 | exit; |
84 | 84 | } |
@@ -17,14 +17,16 @@ discard block |
||
17 | 17 | $name, |
18 | 18 | $zip; |
19 | 19 | |
20 | - public static function create($name=''){ |
|
20 | + public static function create($name='') { |
|
21 | 21 | return new ZIP($name); |
22 | 22 | } |
23 | 23 | |
24 | - public function __construct($name=''){ |
|
24 | + public function __construct($name='') { |
|
25 | 25 | $this->name = preg_replace('/\.zip$/','',($name?:tempnam(sys_get_temp_dir(), 'ZExp').'-archive')); |
26 | 26 | $this->file = $this->name . '.zip'; |
27 | - if (!preg_match('~^/|\./|\.\./~',$this->file)) $this->file = './'.$this->file; |
|
27 | + if (!preg_match('~^/|\./|\.\./~',$this->file)) { |
|
28 | + $this->file = './'.$this->file; |
|
29 | + } |
|
28 | 30 | $this->zip = new \ZipArchive; |
29 | 31 | if ( true !== ($e = $this->zip->open($this->file, |
30 | 32 | \ZipArchive::CREATE || \ZipArchive::OVERWRITE |
@@ -33,21 +35,23 @@ discard block |
||
33 | 35 | } |
34 | 36 | } |
35 | 37 | |
36 | - public function __destruct(){ |
|
38 | + public function __destruct() { |
|
37 | 39 | $this->close(); |
38 | 40 | } |
39 | 41 | |
40 | - public function path(){ |
|
42 | + public function path() { |
|
41 | 43 | return $this->file; |
42 | 44 | } |
43 | 45 | |
44 | - public function write($filename, $data){ |
|
46 | + public function write($filename, $data) { |
|
45 | 47 | $this->zip->addFromString($filename, $data); |
46 | 48 | return $this; |
47 | 49 | } |
48 | 50 | |
49 | - public function close(){ |
|
50 | - if($this->zip) @$this->zip->close(); |
|
51 | + public function close() { |
|
52 | + if($this->zip) { |
|
53 | + @$this->zip->close(); |
|
54 | + } |
|
51 | 55 | return $this; |
52 | 56 | } |
53 | 57 | |
@@ -61,7 +65,7 @@ discard block |
||
61 | 65 | foreach (glob("$root/$folder/*") as $item) { |
62 | 66 | if (is_dir($item)) { |
63 | 67 | $this->addDirectory(str_replace($root,'',$item),$root); |
64 | - } else if (is_file($item)) { |
|
68 | + } else if (is_file($item)) { |
|
65 | 69 | $this->zip->addFile($item, str_replace($root,'',$item)); |
66 | 70 | } |
67 | 71 | } |
@@ -69,7 +73,7 @@ discard block |
||
69 | 73 | return $this; |
70 | 74 | } |
71 | 75 | |
72 | - public function download(){ |
|
76 | + public function download() { |
|
73 | 77 | @$this->zip->close(); |
74 | 78 | header('Content-Type: application/zip'); |
75 | 79 | header('Content-Disposition: attachment;filename="'.$this->name.'"',true); |