@@ -25,36 +25,36 @@ discard block |
||
| 25 | 25 | $password; |
| 26 | 26 | |
| 27 | 27 | public function onInit($options) { |
| 28 | - $options = (object)$options; |
|
| 29 | - $this->host = isset($options->host) ? $options->host : 'localhost'; |
|
| 28 | + $options = (object) $options; |
|
| 29 | + $this->host = isset($options->host) ? $options->host : 'localhost'; |
|
| 30 | 30 | $this->username = isset($options->username) ? $options->username : false; |
| 31 | - $this->secure = isset($options->secure) ? $options->secure : ($this->username ? true : false); |
|
| 32 | - $this->port = isset($options->port) ? $options->port : ($this->secure ? 465 : 25); |
|
| 31 | + $this->secure = isset($options->secure) ? $options->secure : ($this->username ? true : false); |
|
| 32 | + $this->port = isset($options->port) ? $options->port : ($this->secure ? 465 : 25); |
|
| 33 | 33 | $this->password = isset($options->password) ? $options->password : false; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - protected function connect(){ |
|
| 36 | + protected function connect() { |
|
| 37 | 37 | if ($this->socket) $this->close(); |
| 38 | - $url = ($this->secure ? 'tls' : 'tcp') ."://{$this->host}"; |
|
| 39 | - $this->socket = fsockopen( $url, $this->port, $errno, $errstr, 30 ); |
|
| 40 | - if ( ! $this->socket ) throw new \Exception("Unable to connect to $url on port {$this->port}."); |
|
| 38 | + $url = ($this->secure ? 'tls' : 'tcp')."://{$this->host}"; |
|
| 39 | + $this->socket = fsockopen($url, $this->port, $errno, $errstr, 30); |
|
| 40 | + if (!$this->socket) throw new \Exception("Unable to connect to $url on port {$this->port}."); |
|
| 41 | 41 | $this->lastMessage = ''; |
| 42 | 42 | $this->lastCode = 0; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function close(){ |
|
| 45 | + public function close() { |
|
| 46 | 46 | $this->socket && @fclose($this->socket); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - protected function write($data, $nl = 1){ |
|
| 50 | - $payload = $data . str_repeat("\r\n",$nl); |
|
| 49 | + protected function write($data, $nl = 1) { |
|
| 50 | + $payload = $data.str_repeat("\r\n", $nl); |
|
| 51 | 51 | fwrite($this->socket, $payload); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - protected function expectCode($code){ |
|
| 54 | + protected function expectCode($code) { |
|
| 55 | 55 | |
| 56 | 56 | $this->lastMessage = ''; |
| 57 | - while (substr($this->lastMessage, 3, 1) != ' '){ |
|
| 57 | + while (substr($this->lastMessage, 3, 1) != ' ') { |
|
| 58 | 58 | $this->lastMessage = fgets($this->socket, 256); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -62,14 +62,14 @@ discard block |
||
| 62 | 62 | return $code == $this->lastCode; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - protected function SMTPmail($from,$to,$body){ |
|
| 65 | + protected function SMTPmail($from, $to, $body) { |
|
| 66 | 66 | $this->connect(); |
| 67 | 67 | $this->expectCode(220); |
| 68 | 68 | |
| 69 | 69 | $this->write("EHLO {$this->host}"); |
| 70 | 70 | $this->expectCode(250); |
| 71 | 71 | |
| 72 | - if ($this->username){ |
|
| 72 | + if ($this->username) { |
|
| 73 | 73 | $this->write("AUTH LOGIN"); |
| 74 | 74 | $this->expectCode(334); |
| 75 | 75 | $this->write(base64_encode($this->username)); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | return $success; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public function onSend(Envelope $envelope){ |
|
| 101 | + public function onSend(Envelope $envelope) { |
|
| 102 | 102 | // PHP requires direct handling of To and Subject Headers. |
| 103 | 103 | $success = true; |
| 104 | 104 | $recipients = $envelope->to(); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | $envelope->from(false); |
| 108 | 108 | foreach ($recipients as $to) { |
| 109 | 109 | $current_success = $this->SMTPmail($from, $to, $envelope->build()); |
| 110 | - \Event::trigger('core.email.send',$to,$envelope,'smtp'); |
|
| 110 | + \Event::trigger('core.email.send', $to, $envelope, 'smtp'); |
|
| 111 | 111 | $success = $success && $current_success; |
| 112 | 112 | } |
| 113 | 113 | return $success; |
@@ -33,28 +33,32 @@ discard block |
||
| 33 | 33 | $this->password = isset($options->password) ? $options->password : false; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - protected function connect(){ |
|
| 37 | - if ($this->socket) $this->close(); |
|
| 36 | + protected function connect() { |
|
| 37 | + if ($this->socket) { |
|
| 38 | + $this->close(); |
|
| 39 | + } |
|
| 38 | 40 | $url = ($this->secure ? 'tls' : 'tcp') ."://{$this->host}"; |
| 39 | 41 | $this->socket = fsockopen( $url, $this->port, $errno, $errstr, 30 ); |
| 40 | - if ( ! $this->socket ) throw new \Exception("Unable to connect to $url on port {$this->port}."); |
|
| 42 | + if ( ! $this->socket ) { |
|
| 43 | + throw new \Exception("Unable to connect to $url on port {$this->port}."); |
|
| 44 | + } |
|
| 41 | 45 | $this->lastMessage = ''; |
| 42 | 46 | $this->lastCode = 0; |
| 43 | 47 | } |
| 44 | 48 | |
| 45 | - public function close(){ |
|
| 49 | + public function close() { |
|
| 46 | 50 | $this->socket && @fclose($this->socket); |
| 47 | 51 | } |
| 48 | 52 | |
| 49 | - protected function write($data, $nl = 1){ |
|
| 53 | + protected function write($data, $nl = 1) { |
|
| 50 | 54 | $payload = $data . str_repeat("\r\n",$nl); |
| 51 | 55 | fwrite($this->socket, $payload); |
| 52 | 56 | } |
| 53 | 57 | |
| 54 | - protected function expectCode($code){ |
|
| 58 | + protected function expectCode($code) { |
|
| 55 | 59 | |
| 56 | 60 | $this->lastMessage = ''; |
| 57 | - while (substr($this->lastMessage, 3, 1) != ' '){ |
|
| 61 | + while (substr($this->lastMessage, 3, 1) != ' ') { |
|
| 58 | 62 | $this->lastMessage = fgets($this->socket, 256); |
| 59 | 63 | } |
| 60 | 64 | |
@@ -62,14 +66,14 @@ discard block |
||
| 62 | 66 | return $code == $this->lastCode; |
| 63 | 67 | } |
| 64 | 68 | |
| 65 | - protected function SMTPmail($from,$to,$body){ |
|
| 69 | + protected function SMTPmail($from,$to,$body) { |
|
| 66 | 70 | $this->connect(); |
| 67 | 71 | $this->expectCode(220); |
| 68 | 72 | |
| 69 | 73 | $this->write("EHLO {$this->host}"); |
| 70 | 74 | $this->expectCode(250); |
| 71 | 75 | |
| 72 | - if ($this->username){ |
|
| 76 | + if ($this->username) { |
|
| 73 | 77 | $this->write("AUTH LOGIN"); |
| 74 | 78 | $this->expectCode(334); |
| 75 | 79 | $this->write(base64_encode($this->username)); |
@@ -98,7 +102,7 @@ discard block |
||
| 98 | 102 | return $success; |
| 99 | 103 | } |
| 100 | 104 | |
| 101 | - public function onSend(Envelope $envelope){ |
|
| 105 | + public function onSend(Envelope $envelope) { |
|
| 102 | 106 | // PHP requires direct handling of To and Subject Headers. |
| 103 | 107 | $success = true; |
| 104 | 108 | $recipients = $envelope->to(); |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | $this->connect(); |
| 67 | 67 | $this->expectCode(220); |
| 68 | 68 | |
| 69 | - $this->write("EHLO {$this->host}"); |
|
| 69 | + $this->write("ehlo {$this->host}"); |
|
| 70 | 70 | $this->expectCode(250); |
| 71 | 71 | |
| 72 | 72 | if ($this->username){ |
@@ -13,8 +13,8 @@ discard block |
||
| 13 | 13 | class Redirect { |
| 14 | 14 | use Module; |
| 15 | 15 | |
| 16 | - public static function to($url){ |
|
| 17 | - if ($link = Filter::with('core.redirect',$url)) { |
|
| 16 | + public static function to($url) { |
|
| 17 | + if ($link = Filter::with('core.redirect', $url)) { |
|
| 18 | 18 | Response::clean(); |
| 19 | 19 | Response::header('Location', $link); |
| 20 | 20 | Response::send(); |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public static function back(){ |
|
| 26 | - if ($link = Filter::with('core.redirect', (empty($_SERVER['HTTP_REFERER']) ? Request::get('redirect_uri',false) : $_SERVER['HTTP_REFERER']) )){ |
|
| 25 | + public static function back() { |
|
| 26 | + if ($link = Filter::with('core.redirect', (empty($_SERVER['HTTP_REFERER']) ? Request::get('redirect_uri', false) : $_SERVER['HTTP_REFERER']))) { |
|
| 27 | 27 | Response::clean(); |
| 28 | 28 | Response::header('Location', $link); |
| 29 | 29 | Response::send(); |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public static function viaJavaScript($url, $parent=false){ |
|
| 35 | - if ($link = Filter::with('core.redirect', $url)){ |
|
| 34 | + public static function viaJavaScript($url, $parent = false) { |
|
| 35 | + if ($link = Filter::with('core.redirect', $url)) { |
|
| 36 | 36 | Response::type('text/html'); |
| 37 | - Response::add('<script>'.($parent?'parent.':'').'location.href="',addslashes($link),'"</script>'); |
|
| 37 | + Response::add('<script>'.($parent ? 'parent.' : '').'location.href="', addslashes($link), '"</script>'); |
|
| 38 | 38 | Response::send(); |
| 39 | 39 | exit; |
| 40 | 40 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | class Redirect { |
| 14 | 14 | use Module; |
| 15 | 15 | |
| 16 | - public static function to($url){ |
|
| 16 | + public static function to($url) { |
|
| 17 | 17 | if ($link = Filter::with('core.redirect',$url)) { |
| 18 | 18 | Response::clean(); |
| 19 | 19 | Response::header('Location', $link); |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public static function back(){ |
|
| 26 | - if ($link = Filter::with('core.redirect', (empty($_SERVER['HTTP_REFERER']) ? Request::get('redirect_uri',false) : $_SERVER['HTTP_REFERER']) )){ |
|
| 25 | + public static function back() { |
|
| 26 | + if ($link = Filter::with('core.redirect', (empty($_SERVER['HTTP_REFERER']) ? Request::get('redirect_uri',false) : $_SERVER['HTTP_REFERER']) )) { |
|
| 27 | 27 | Response::clean(); |
| 28 | 28 | Response::header('Location', $link); |
| 29 | 29 | Response::send(); |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public static function viaJavaScript($url, $parent=false){ |
|
| 35 | - if ($link = Filter::with('core.redirect', $url)){ |
|
| 34 | + public static function viaJavaScript($url, $parent=false) { |
|
| 35 | + if ($link = Filter::with('core.redirect', $url)) { |
|
| 36 | 36 | Response::type('text/html'); |
| 37 | 37 | Response::add('<script>'.($parent?'parent.':'').'location.href="',addslashes($link),'"</script>'); |
| 38 | 38 | Response::send(); |
@@ -20,6 +20,6 @@ |
||
| 20 | 20 | public function append($path, $data); |
| 21 | 21 | public function delete($path); |
| 22 | 22 | public function move($old_path, $new_path); |
| 23 | - public function search($pattern, $recursive=true); |
|
| 23 | + public function search($pattern, $recursive = true); |
|
| 24 | 24 | |
| 25 | 25 | } |
@@ -19,50 +19,50 @@ |
||
| 19 | 19 | $fileCache; |
| 20 | 20 | |
| 21 | 21 | public function __construct(array $options = []) { |
| 22 | - $this->path = empty($options['root'])?(tempnam(sys_get_temp_dir(), 'CFZ_').'.zip'):rtrim($options['root']); |
|
| 22 | + $this->path = empty($options['root']) ? (tempnam(sys_get_temp_dir(), 'CFZ_').'.zip') : rtrim($options['root']); |
|
| 23 | 23 | $this->zipfile = new \ZipArchive(); |
| 24 | - if ( !$this->zipfile->open($this->path, \ZipArchive::CREATE) ){ |
|
| 24 | + if (!$this->zipfile->open($this->path, \ZipArchive::CREATE)) { |
|
| 25 | 25 | throw new \Exception("File::ZIP Cannot open or create ".$this->path); |
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - public function exists($path){ |
|
| 29 | + public function exists($path) { |
|
| 30 | 30 | return false !== $this->zipfile->locateName($path); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function read($path){ |
|
| 33 | + public function read($path) { |
|
| 34 | 34 | if (isset($this->fileCache[$path])) return $this->fileCache[$path]; |
| 35 | 35 | return $this->exists($path) ? $this->zipfile->getFromName($path) : false; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function write($path, $data){ |
|
| 38 | + public function write($path, $data) { |
|
| 39 | 39 | // This is needed because we cant write and read from the same archive. |
| 40 | 40 | $this->fileCache[$path] = $data; |
| 41 | 41 | return $this->zipfile->addFromString($path, $data); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function append($path, $data){ |
|
| 45 | - return $this->write($path, ($this->read($path) ?: '') . $data); |
|
| 44 | + public function append($path, $data) { |
|
| 45 | + return $this->write($path, ($this->read($path) ?: '').$data); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function delete($path){ |
|
| 48 | + public function delete($path) { |
|
| 49 | 49 | return $this->exists($path) ? $this->zipfile->deleteName($path) : false; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function move($old, $new){ |
|
| 52 | + public function move($old, $new) { |
|
| 53 | 53 | // Atomic rename |
| 54 | 54 | // This is needed because we cant write and read from the same archive. |
| 55 | - return $this->write($new,$this->read($old)) && $this->delete($old); |
|
| 55 | + return $this->write($new, $this->read($old)) && $this->delete($old); |
|
| 56 | 56 | // return $this->zipfile->renameName($old, $new); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public function search($pattern, $recursive=true){ |
|
| 59 | + public function search($pattern, $recursive = true) { |
|
| 60 | 60 | $results = []; |
| 61 | - $rx_pattern = '('.strtr($pattern,['.'=>'\.','*'=>'.*','?'=>'.']).')Ai'; |
|
| 61 | + $rx_pattern = '('.strtr($pattern, ['.'=>'\.', '*'=>'.*', '?'=>'.']).')Ai'; |
|
| 62 | 62 | |
| 63 | - for( $i = 0, $c = $this->zipfile->numFiles; $i < $c; $i++ ){ |
|
| 64 | - $stat = $this->zipfile->statIndex( $i ); |
|
| 65 | - if (preg_match($rx_pattern,$stat['name'])) $results[] = $stat['name']; |
|
| 63 | + for ($i = 0, $c = $this->zipfile->numFiles;$i < $c;$i++) { |
|
| 64 | + $stat = $this->zipfile->statIndex($i); |
|
| 65 | + if (preg_match($rx_pattern, $stat['name'])) $results[] = $stat['name']; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | return $results; |
@@ -21,48 +21,52 @@ |
||
| 21 | 21 | public function __construct(array $options = []) { |
| 22 | 22 | $this->path = empty($options['root'])?(tempnam(sys_get_temp_dir(), 'CFZ_').'.zip'):rtrim($options['root']); |
| 23 | 23 | $this->zipfile = new \ZipArchive(); |
| 24 | - if ( !$this->zipfile->open($this->path, \ZipArchive::CREATE) ){ |
|
| 24 | + if ( !$this->zipfile->open($this->path, \ZipArchive::CREATE) ) { |
|
| 25 | 25 | throw new \Exception("File::ZIP Cannot open or create ".$this->path); |
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - public function exists($path){ |
|
| 29 | + public function exists($path) { |
|
| 30 | 30 | return false !== $this->zipfile->locateName($path); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function read($path){ |
|
| 34 | - if (isset($this->fileCache[$path])) return $this->fileCache[$path]; |
|
| 33 | + public function read($path) { |
|
| 34 | + if (isset($this->fileCache[$path])) { |
|
| 35 | + return $this->fileCache[$path]; |
|
| 36 | + } |
|
| 35 | 37 | return $this->exists($path) ? $this->zipfile->getFromName($path) : false; |
| 36 | 38 | } |
| 37 | 39 | |
| 38 | - public function write($path, $data){ |
|
| 40 | + public function write($path, $data) { |
|
| 39 | 41 | // This is needed because we cant write and read from the same archive. |
| 40 | 42 | $this->fileCache[$path] = $data; |
| 41 | 43 | return $this->zipfile->addFromString($path, $data); |
| 42 | 44 | } |
| 43 | 45 | |
| 44 | - public function append($path, $data){ |
|
| 46 | + public function append($path, $data) { |
|
| 45 | 47 | return $this->write($path, ($this->read($path) ?: '') . $data); |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | - public function delete($path){ |
|
| 50 | + public function delete($path) { |
|
| 49 | 51 | return $this->exists($path) ? $this->zipfile->deleteName($path) : false; |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | - public function move($old, $new){ |
|
| 54 | + public function move($old, $new) { |
|
| 53 | 55 | // Atomic rename |
| 54 | 56 | // This is needed because we cant write and read from the same archive. |
| 55 | 57 | return $this->write($new,$this->read($old)) && $this->delete($old); |
| 56 | 58 | // return $this->zipfile->renameName($old, $new); |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | - public function search($pattern, $recursive=true){ |
|
| 61 | + public function search($pattern, $recursive=true) { |
|
| 60 | 62 | $results = []; |
| 61 | 63 | $rx_pattern = '('.strtr($pattern,['.'=>'\.','*'=>'.*','?'=>'.']).')Ai'; |
| 62 | 64 | |
| 63 | - for( $i = 0, $c = $this->zipfile->numFiles; $i < $c; $i++ ){ |
|
| 65 | + for( $i = 0, $c = $this->zipfile->numFiles; $i < $c; $i++ ) { |
|
| 64 | 66 | $stat = $this->zipfile->statIndex( $i ); |
| 65 | - if (preg_match($rx_pattern,$stat['name'])) $results[] = $stat['name']; |
|
| 67 | + if (preg_match($rx_pattern,$stat['name'])) { |
|
| 68 | + $results[] = $stat['name']; |
|
| 69 | + } |
|
| 66 | 70 | } |
| 67 | 71 | |
| 68 | 72 | return $results; |
@@ -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 | |
@@ -27,12 +27,12 @@ |
||
| 27 | 27 | * @param mixed $v (default: null) The array of values exposed in template. |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | - public static function render($t,$v=null){ |
|
| 31 | - for($r=$ox=$x=false;false!==($x=$y=strpos($t,'{{',$x)); |
|
| 32 | - $r.=substr($t,$ox,$x-$ox), |
|
| 33 | - $c=substr($t,$x+=2,$l=($y=strpos($t,'}}',$x))-$x), |
|
| 34 | - $ox=$x+=$l+2,$r.=Object::fetch($c,$v) |
|
| 35 | - ); return $r===false?$t:$r.substr($t,$ox); |
|
| 36 | - } |
|
| 30 | + public static function render($t,$v=null){ |
|
| 31 | + for($r=$ox=$x=false;false!==($x=$y=strpos($t,'{{',$x)); |
|
| 32 | + $r.=substr($t,$ox,$x-$ox), |
|
| 33 | + $c=substr($t,$x+=2,$l=($y=strpos($t,'}}',$x))-$x), |
|
| 34 | + $ox=$x+=$l+2,$r.=Object::fetch($c,$v) |
|
| 35 | + ); return $r===false?$t:$r.substr($t,$ox); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | } /* End of class */ |
@@ -27,12 +27,12 @@ |
||
| 27 | 27 | * @param mixed $v (default: null) The array of values exposed in template. |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | - public static function render($t,$v=null){ |
|
| 31 | - for($r=$ox=$x=false;false!==($x=$y=strpos($t,'{{',$x)); |
|
| 32 | - $r.=substr($t,$ox,$x-$ox), |
|
| 33 | - $c=substr($t,$x+=2,$l=($y=strpos($t,'}}',$x))-$x), |
|
| 34 | - $ox=$x+=$l+2,$r.=Object::fetch($c,$v) |
|
| 35 | - ); return $r===false?$t:$r.substr($t,$ox); |
|
| 30 | + public static function render($t, $v = null) { |
|
| 31 | + for ($r = $ox = $x = false;false !== ($x = $y = strpos($t, '{{', $x)); |
|
| 32 | + $r .= substr($t, $ox, $x - $ox), |
|
| 33 | + $c = substr($t, $x += 2, $l = ($y = strpos($t, '}}', $x)) - $x), |
|
| 34 | + $ox = $x += $l + 2, $r .= Object::fetch($c, $v) |
|
| 35 | + );return $r === false ? $t : $r.substr($t, $ox); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | } /* End of class */ |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | * @param mixed $v (default: null) The array of values exposed in template. |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | - public static function render($t,$v=null){ |
|
| 30 | + public static function render($t,$v=null) { |
|
| 31 | 31 | for($r=$ox=$x=false;false!==($x=$y=strpos($t,'{{',$x)); |
| 32 | 32 | $r.=substr($t,$ox,$x-$ox), |
| 33 | 33 | $c=substr($t,$x+=2,$l=($y=strpos($t,'}}',$x))-$x), |
@@ -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 | |