@@ -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; |
@@ -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); |
@@ -31,7 +31,7 @@ |
||
31 | 31 | } |
32 | 32 | } |
33 | 33 | } |
34 | - parent::__construct($data, static::ARRAY_AS_PROPS); |
|
34 | + parent::__construct($data, static::ARRAY_AS_PROPS); |
|
35 | 35 | } else { |
36 | 36 | throw new InvalidArgumentException( |
37 | 37 | 'Argument must be a string containing valid JSON, an array or an stdClass.' |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | * @param mixed $input The object/array/json_encoded object to wrap |
22 | 22 | * @param boolean $deep Wrap also deep branches as Objects |
23 | 23 | */ |
24 | - public function __construct($input=[], $deep=true){ |
|
24 | + public function __construct($input=[], $deep=true) { |
|
25 | 25 | $data = is_string($input) ? json_decode($input,true) : (array)$input; |
26 | - if (is_array($data)){ |
|
26 | + if (is_array($data)) { |
|
27 | 27 | if ($deep) { |
28 | 28 | foreach ($data as $key => &$value) { |
29 | - if (is_array($value) || is_a($value,'stdClass')){ |
|
29 | + if (is_array($value) || is_a($value,'stdClass')) { |
|
30 | 30 | $value = new self($value); |
31 | 31 | } |
32 | 32 | } |
@@ -42,17 +42,18 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * ArrayObject::offsetSet |
44 | 44 | */ |
45 | - public function offsetSet($key, $value){ |
|
46 | - if ( is_array($value) ) |
|
47 | - parent::offsetSet($key, new static($value)); |
|
48 | - else |
|
49 | - parent::offsetSet($key, $value); |
|
45 | + public function offsetSet($key, $value) { |
|
46 | + if ( is_array($value) ) { |
|
47 | + parent::offsetSet($key, new static($value)); |
|
48 | + } else { |
|
49 | + parent::offsetSet($key, $value); |
|
50 | + } |
|
50 | 51 | } |
51 | 52 | |
52 | 53 | /** |
53 | 54 | * ArrayObject::offsetGet |
54 | 55 | */ |
55 | - public function offsetGet($key){ |
|
56 | + public function offsetGet($key) { |
|
56 | 57 | $raw = parent::offsetGet($key); |
57 | 58 | return is_callable($raw) ? call_user_func($raw) : $raw; |
58 | 59 | } |
@@ -60,10 +61,12 @@ discard block |
||
60 | 61 | /** |
61 | 62 | * Emulate object methods |
62 | 63 | */ |
63 | - public function __call($method, $args){ |
|
64 | + public function __call($method, $args) { |
|
64 | 65 | $raw = parent::offsetGet($method); |
65 | 66 | if (is_callable($raw)) { |
66 | - if ($raw instanceof \Closure) $raw->bindTo($this); |
|
67 | + if ($raw instanceof \Closure) { |
|
68 | + $raw->bindTo($this); |
|
69 | + } |
|
67 | 70 | return call_user_func_array($raw, $args); |
68 | 71 | } |
69 | 72 | } |
@@ -72,7 +75,7 @@ discard block |
||
72 | 75 | * If casted as a string, return a JSON rappresentation of the wrapped payload |
73 | 76 | * @return string |
74 | 77 | */ |
75 | - public function __toString(){ |
|
78 | + public function __toString() { |
|
76 | 79 | return json_encode($this,JSON_NUMERIC_CHECK); |
77 | 80 | } |
78 | 81 | |
@@ -103,7 +106,7 @@ discard block |
||
103 | 106 | return $frag ? '' : $ptr; |
104 | 107 | } |
105 | 108 | |
106 | - public static function create($class, $args = null){ |
|
109 | + public static function create($class, $args = null) { |
|
107 | 110 | return is_array($args) ? (new ReflectionClass($class))->newInstanceArgs($args) : new $class; |
108 | 111 | } |
109 | 112 |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | * @param mixed $input The object/array/json_encoded object to wrap |
22 | 22 | * @param boolean $deep Wrap also deep branches as Objects |
23 | 23 | */ |
24 | - public function __construct($input=[], $deep=true){ |
|
25 | - $data = is_string($input) ? json_decode($input,true) : (array)$input; |
|
26 | - if (is_array($data)){ |
|
24 | + public function __construct($input = [], $deep = true) { |
|
25 | + $data = is_string($input) ? json_decode($input, true) : (array) $input; |
|
26 | + if (is_array($data)) { |
|
27 | 27 | if ($deep) { |
28 | 28 | foreach ($data as $key => &$value) { |
29 | - if (is_array($value) || is_a($value,'stdClass')){ |
|
29 | + if (is_array($value) || is_a($value, 'stdClass')) { |
|
30 | 30 | $value = new self($value); |
31 | 31 | } |
32 | 32 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * ArrayObject::offsetSet |
44 | 44 | */ |
45 | - public function offsetSet($key, $value){ |
|
46 | - if ( is_array($value) ) |
|
45 | + public function offsetSet($key, $value) { |
|
46 | + if (is_array($value)) |
|
47 | 47 | parent::offsetSet($key, new static($value)); |
48 | 48 | else |
49 | 49 | parent::offsetSet($key, $value); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * ArrayObject::offsetGet |
54 | 54 | */ |
55 | - public function offsetGet($key){ |
|
55 | + public function offsetGet($key) { |
|
56 | 56 | $raw = parent::offsetGet($key); |
57 | 57 | return is_callable($raw) ? call_user_func($raw) : $raw; |
58 | 58 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * Emulate object methods |
62 | 62 | */ |
63 | - public function __call($method, $args){ |
|
63 | + public function __call($method, $args) { |
|
64 | 64 | $raw = parent::offsetGet($method); |
65 | 65 | if (is_callable($raw)) { |
66 | 66 | if ($raw instanceof \Closure) $raw->bindTo($this); |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | * If casted as a string, return a JSON rappresentation of the wrapped payload |
73 | 73 | * @return string |
74 | 74 | */ |
75 | - public function __toString(){ |
|
76 | - return json_encode($this,JSON_NUMERIC_CHECK); |
|
75 | + public function __toString() { |
|
76 | + return json_encode($this, JSON_NUMERIC_CHECK); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -84,22 +84,22 @@ discard block |
||
84 | 84 | */ |
85 | 85 | |
86 | 86 | public static function fetch($path, $root) { |
87 | - $_ = (array)$root; |
|
88 | - if (strpos($path,'.') === false) { |
|
87 | + $_ = (array) $root; |
|
88 | + if (strpos($path, '.') === false) { |
|
89 | 89 | return isset($_[$path]) ? $_[$path] : null; |
90 | 90 | } else { |
91 | - list($frag,$rest) = explode('.', $path, 2); |
|
91 | + list($frag, $rest) = explode('.', $path, 2); |
|
92 | 92 | if ($rest) { |
93 | 93 | return isset($_[$frag]) ? self::fetch($rest, $_[$frag]) : null; |
94 | 94 | } elseif ($frag) { |
95 | - return (array)$_[$frag]; |
|
95 | + return (array) $_[$frag]; |
|
96 | 96 | } else { |
97 | 97 | return null; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - public static function create($class, $args = null){ |
|
102 | + public static function create($class, $args = null) { |
|
103 | 103 | return is_array($args) ? (new ReflectionClass($class))->newInstanceArgs($args) : new $class; |
104 | 104 | } |
105 | 105 |
@@ -15,41 +15,41 @@ discard block |
||
15 | 15 | protected static $loaded = false; |
16 | 16 | protected static $fields = []; |
17 | 17 | |
18 | - protected static function init(){ |
|
19 | - if(false===static::$loaded){ |
|
20 | - static::load(Session::get('core.messages',[])); |
|
18 | + protected static function init() { |
|
19 | + if (false === static::$loaded) { |
|
20 | + static::load(Session::get('core.messages', [])); |
|
21 | 21 | static::$loaded = true; |
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | - public static function & get($key,$default=null){ |
|
25 | + public static function & get($key, $default = null){ |
|
26 | 26 | static::init(); |
27 | - $value = parent::get($key,''); |
|
28 | - parent::delete($key,''); |
|
29 | - Session::set('core.messages',parent::all()); |
|
27 | + $value = parent::get($key, ''); |
|
28 | + parent::delete($key, ''); |
|
29 | + Session::set('core.messages', parent::all()); |
|
30 | 30 | return $value; |
31 | 31 | } |
32 | 32 | |
33 | - public static function set($key,$data=null){ |
|
33 | + public static function set($key, $data = null) { |
|
34 | 34 | static::init(); |
35 | - parent::set($key,$data); |
|
36 | - return Session::set('core.messages',parent::all()); |
|
35 | + parent::set($key, $data); |
|
36 | + return Session::set('core.messages', parent::all()); |
|
37 | 37 | } |
38 | 38 | |
39 | - public static function add($key,$data=null){ |
|
39 | + public static function add($key, $data = null) { |
|
40 | 40 | static::init(); |
41 | - $d = parent::get($key,[]); |
|
41 | + $d = parent::get($key, []); |
|
42 | 42 | $d[] = $data; |
43 | - parent::set($key,$d); |
|
44 | - return Session::set('core.messages',parent::all()); |
|
43 | + parent::set($key, $d); |
|
44 | + return Session::set('core.messages', parent::all()); |
|
45 | 45 | } |
46 | 46 | |
47 | - public static function & all($key=null){ |
|
47 | + public static function & all($key = null){ |
|
48 | 48 | static::init(); |
49 | - if($key){ |
|
50 | - $all = parent::get($key,[]); |
|
49 | + if ($key) { |
|
50 | + $all = parent::get($key, []); |
|
51 | 51 | parent::delete($key); |
52 | - Session::set('core.messages',parent::all()); |
|
52 | + Session::set('core.messages', parent::all()); |
|
53 | 53 | } else { |
54 | 54 | $all = parent::all(); |
55 | 55 | static::clear(); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | return $all; |
58 | 58 | } |
59 | 59 | |
60 | - public static function clear(){ |
|
60 | + public static function clear() { |
|
61 | 61 | static::init(); |
62 | 62 | parent::clear(); |
63 | 63 | Session::delete('core.messages'); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * Return a read-only accessor to messages variables for in-view use. |
69 | 69 | * @return MessageReadOnly |
70 | 70 | */ |
71 | - public static function readOnly(){ |
|
71 | + public static function readOnly() { |
|
72 | 72 | return new MessageReadOnly(); |
73 | 73 | } |
74 | 74 | |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | |
82 | 82 | class MessageReadOnly { |
83 | 83 | |
84 | - public function __get($key){ |
|
84 | + public function __get($key) { |
|
85 | 85 | return Message::get($key); |
86 | 86 | } |
87 | 87 | |
88 | - public function __isset($key){ |
|
88 | + public function __isset($key) { |
|
89 | 89 | return true; |
90 | 90 | } |
91 | 91 |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | protected static $loaded = false; |
16 | 16 | protected static $fields = []; |
17 | 17 | |
18 | - protected static function init(){ |
|
19 | - if(false===static::$loaded){ |
|
18 | + protected static function init() { |
|
19 | + if(false===static::$loaded) { |
|
20 | 20 | static::load(Session::get('core.messages',[])); |
21 | 21 | static::$loaded = true; |
22 | 22 | } |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | return $value; |
31 | 31 | } |
32 | 32 | |
33 | - public static function set($key,$data=null){ |
|
33 | + public static function set($key,$data=null) { |
|
34 | 34 | static::init(); |
35 | 35 | parent::set($key,$data); |
36 | 36 | return Session::set('core.messages',parent::all()); |
37 | 37 | } |
38 | 38 | |
39 | - public static function add($key,$data=null){ |
|
39 | + public static function add($key,$data=null) { |
|
40 | 40 | static::init(); |
41 | 41 | $d = parent::get($key,[]); |
42 | 42 | $d[] = $data; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | public static function & all($key=null){ |
48 | 48 | static::init(); |
49 | - if($key){ |
|
49 | + if($key) { |
|
50 | 50 | $all = parent::get($key,[]); |
51 | 51 | parent::delete($key); |
52 | 52 | Session::set('core.messages',parent::all()); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | return $all; |
58 | 58 | } |
59 | 59 | |
60 | - public static function clear(){ |
|
60 | + public static function clear() { |
|
61 | 61 | static::init(); |
62 | 62 | parent::clear(); |
63 | 63 | Session::delete('core.messages'); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * Return a read-only accessor to messages variables for in-view use. |
69 | 69 | * @return MessageReadOnly |
70 | 70 | */ |
71 | - public static function readOnly(){ |
|
71 | + public static function readOnly() { |
|
72 | 72 | return new MessageReadOnly(); |
73 | 73 | } |
74 | 74 | |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | |
82 | 82 | class MessageReadOnly { |
83 | 83 | |
84 | - public function __get($key){ |
|
84 | + public function __get($key) { |
|
85 | 85 | return Message::get($key); |
86 | 86 | } |
87 | 87 | |
88 | - public function __isset($key){ |
|
88 | + public function __isset($key) { |
|
89 | 89 | return true; |
90 | 90 | } |
91 | 91 |
@@ -27,54 +27,54 @@ discard block |
||
27 | 27 | $format = self::STANDARD, |
28 | 28 | $savedheaders = false; |
29 | 29 | |
30 | - public static function open($file, $format=self::AUTO){ |
|
31 | - return new static($file,self::READ,$format); |
|
30 | + public static function open($file, $format = self::AUTO) { |
|
31 | + return new static($file, self::READ, $format); |
|
32 | 32 | } |
33 | 33 | |
34 | - public static function create($file, $format=self::STANDARD){ |
|
35 | - return new static($file,self::WRITE, $format); |
|
34 | + public static function create($file, $format = self::STANDARD) { |
|
35 | + return new static($file, self::WRITE, $format); |
|
36 | 36 | } |
37 | 37 | |
38 | - public static function fromSQL($sql, $format=self::AUTO){ |
|
38 | + public static function fromSQL($sql, $format = self::AUTO) { |
|
39 | 39 | $csv = static::create(tempnam(sys_get_temp_dir(), 'CSVx'), $format); |
40 | - SQL::each($sql,function($row) use (&$csv){ |
|
40 | + SQL::each($sql, function($row) use (&$csv){ |
|
41 | 41 | $csv->write($row); |
42 | 42 | }); |
43 | 43 | return $csv; |
44 | 44 | } |
45 | 45 | |
46 | - public static function fromTable($table, $format=self::AUTO){ |
|
46 | + public static function fromTable($table, $format = self::AUTO) { |
|
47 | 47 | $csv = static::create(tempnam(sys_get_temp_dir(), 'CSVx'), $format); |
48 | - foreach($table as $row){ |
|
48 | + foreach ($table as $row) { |
|
49 | 49 | $csv->write($row); |
50 | 50 | } |
51 | 51 | return $csv; |
52 | 52 | } |
53 | 53 | |
54 | - public function __construct($file, $mode=self::READ, $format=self::AUTO){ |
|
54 | + public function __construct($file, $mode = self::READ, $format = self::AUTO) { |
|
55 | 55 | $this->mode = $mode; |
56 | - $this->file = new \SplFileObject($file,'c+'); |
|
56 | + $this->file = new \SplFileObject($file, 'c+'); |
|
57 | 57 | if (!$this->file->valid()) throw new Exception("Error opening CSV file [$file]", 1); |
58 | 58 | $this->file->setFlags( |
59 | - \SplFileObject::READ_CSV | // set file reading mode to csv |
|
60 | - \SplFileObject::SKIP_EMPTY | // ignore empty lines |
|
59 | + \SplFileObject::READ_CSV | // set file reading mode to csv |
|
60 | + \SplFileObject::SKIP_EMPTY | // ignore empty lines |
|
61 | 61 | \SplFileObject::DROP_NEW_LINE // drop new line from last column in record |
62 | 62 | ); |
63 | - $this->format = ($format==self::AUTO ? $this->guessSeparator() : $format); |
|
64 | - $this->file->setCsvControl($this->format,'"',"\\"); |
|
63 | + $this->format = ($format == self::AUTO ? $this->guessSeparator() : $format); |
|
64 | + $this->file->setCsvControl($this->format, '"', "\\"); |
|
65 | 65 | } |
66 | 66 | |
67 | - private function guessSeparator($checkLines = 2){ |
|
67 | + private function guessSeparator($checkLines = 2) { |
|
68 | 68 | if ($this->mode == self::WRITE) return self::STANDARD; |
69 | - $delimiters = [",","\t",";"]; |
|
69 | + $delimiters = [",", "\t", ";"]; |
|
70 | 70 | $results = []; |
71 | 71 | $this->file->rewind(); |
72 | 72 | while ($checkLines--) { |
73 | 73 | $line = $this->file->fgets(); |
74 | - foreach ($delimiters as $delimiter){ |
|
74 | + foreach ($delimiters as $delimiter) { |
|
75 | 75 | $fields = preg_split('/['.$delimiter.']/', $line); |
76 | - if(count($fields) > 1){ |
|
77 | - if(empty($results[$delimiter])){ |
|
76 | + if (count($fields) > 1) { |
|
77 | + if (empty($results[$delimiter])) { |
|
78 | 78 | $results[$delimiter] = 1; |
79 | 79 | } else { |
80 | 80 | $results[$delimiter]++; |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | return $results[0]; |
88 | 88 | } |
89 | 89 | |
90 | - public function write($row){ |
|
90 | + public function write($row) { |
|
91 | 91 | if ($this->mode != self::WRITE) return; |
92 | - $row = (array)$row; |
|
92 | + $row = (array) $row; |
|
93 | 93 | if (false === $this->savedheaders) { |
94 | 94 | $this->schema(array_keys($row)); |
95 | 95 | } |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | $this->file->fputcsv($row_t); |
101 | 101 | } |
102 | 102 | |
103 | - public function read(){ |
|
103 | + public function read() { |
|
104 | 104 | if ($this->mode != self::READ) return; |
105 | - foreach($this->file as $row){ |
|
106 | - if ($row){ |
|
107 | - if(!$this->headers) { |
|
105 | + foreach ($this->file as $row) { |
|
106 | + if ($row) { |
|
107 | + if (!$this->headers) { |
|
108 | 108 | $this->headers = $row; |
109 | 109 | continue; |
110 | 110 | } |
@@ -114,18 +114,18 @@ discard block |
||
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
117 | - public function each(callable $looper = null){ |
|
117 | + public function each(callable $looper = null) { |
|
118 | 118 | if ($looper) { |
119 | - foreach($this->read() as $row) $looper($row); |
|
119 | + foreach ($this->read() as $row) $looper($row); |
|
120 | 120 | return $this; |
121 | 121 | } else { |
122 | 122 | $results = []; |
123 | - foreach($this->read() as $row) $results[] = $row; |
|
123 | + foreach ($this->read() as $row) $results[] = $row; |
|
124 | 124 | return $results; |
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - public function convert($filename, $format=self::STANDARD){ |
|
128 | + public function convert($filename, $format = self::STANDARD) { |
|
129 | 129 | if ($this->mode != self::READ) return; |
130 | 130 | if ($format == self::AUTO) $format = self::STANDARD; |
131 | 131 | $csv = CSV::create($filename, CSV::EXCEL); |
@@ -135,18 +135,18 @@ discard block |
||
135 | 135 | return $csv; |
136 | 136 | } |
137 | 137 | |
138 | - public function flush(){ |
|
138 | + public function flush() { |
|
139 | 139 | if ($this->mode == self::WRITE) { |
140 | 140 | $this->file->fflush(); |
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | - public function schema($schema=null){ |
|
145 | - if($schema){ |
|
146 | - $this->headers = array_values((array)$schema); |
|
144 | + public function schema($schema = null) { |
|
145 | + if ($schema) { |
|
146 | + $this->headers = array_values((array) $schema); |
|
147 | 147 | if ($this->mode == self::WRITE) { |
148 | 148 | $this->savedheaders = true; |
149 | - $this->template = array_combine($this->headers, array_pad([],count($this->headers),'')); |
|
149 | + $this->template = array_combine($this->headers, array_pad([], count($this->headers), '')); |
|
150 | 150 | $this->file->fputcsv($this->headers); |
151 | 151 | } |
152 | 152 | return $this; |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
158 | - public function asString(){ |
|
158 | + public function asString() { |
|
159 | 159 | $this->flush(); |
160 | 160 | return file_get_contents($this->file->getPathname()); |
161 | 161 | } |
162 | 162 | |
163 | - public function __toString(){ |
|
164 | - try { return $this->asString(); } catch(\Exception $e) { return ''; } |
|
163 | + public function __toString() { |
|
164 | + try { return $this->asString();} catch (\Exception $e) { return '';} |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | } |
@@ -27,34 +27,36 @@ discard block |
||
27 | 27 | $format = self::STANDARD, |
28 | 28 | $savedheaders = false; |
29 | 29 | |
30 | - public static function open($file, $format=self::AUTO){ |
|
30 | + public static function open($file, $format=self::AUTO) { |
|
31 | 31 | return new static($file,self::READ,$format); |
32 | 32 | } |
33 | 33 | |
34 | - public static function create($file, $format=self::STANDARD){ |
|
34 | + public static function create($file, $format=self::STANDARD) { |
|
35 | 35 | return new static($file,self::WRITE, $format); |
36 | 36 | } |
37 | 37 | |
38 | - public static function fromSQL($sql, $format=self::AUTO){ |
|
38 | + public static function fromSQL($sql, $format=self::AUTO) { |
|
39 | 39 | $csv = static::create(tempnam(sys_get_temp_dir(), 'CSVx'), $format); |
40 | - SQL::each($sql,function($row) use (&$csv){ |
|
40 | + SQL::each($sql,function($row) use (&$csv) { |
|
41 | 41 | $csv->write($row); |
42 | 42 | }); |
43 | 43 | return $csv; |
44 | 44 | } |
45 | 45 | |
46 | - public static function fromTable($table, $format=self::AUTO){ |
|
46 | + public static function fromTable($table, $format=self::AUTO) { |
|
47 | 47 | $csv = static::create(tempnam(sys_get_temp_dir(), 'CSVx'), $format); |
48 | - foreach($table as $row){ |
|
48 | + foreach($table as $row) { |
|
49 | 49 | $csv->write($row); |
50 | 50 | } |
51 | 51 | return $csv; |
52 | 52 | } |
53 | 53 | |
54 | - public function __construct($file, $mode=self::READ, $format=self::AUTO){ |
|
54 | + public function __construct($file, $mode=self::READ, $format=self::AUTO) { |
|
55 | 55 | $this->mode = $mode; |
56 | 56 | $this->file = new \SplFileObject($file,'c+'); |
57 | - if (!$this->file->valid()) throw new Exception("Error opening CSV file [$file]", 1); |
|
57 | + if (!$this->file->valid()) { |
|
58 | + throw new Exception("Error opening CSV file [$file]", 1); |
|
59 | + } |
|
58 | 60 | $this->file->setFlags( |
59 | 61 | \SplFileObject::READ_CSV | // set file reading mode to csv |
60 | 62 | \SplFileObject::SKIP_EMPTY | // ignore empty lines |
@@ -64,17 +66,19 @@ discard block |
||
64 | 66 | $this->file->setCsvControl($this->format,'"',"\\"); |
65 | 67 | } |
66 | 68 | |
67 | - private function guessSeparator($checkLines = 2){ |
|
68 | - if ($this->mode == self::WRITE) return self::STANDARD; |
|
69 | + private function guessSeparator($checkLines = 2) { |
|
70 | + if ($this->mode == self::WRITE) { |
|
71 | + return self::STANDARD; |
|
72 | + } |
|
69 | 73 | $delimiters = [",","\t",";"]; |
70 | 74 | $results = []; |
71 | 75 | $this->file->rewind(); |
72 | 76 | while ($checkLines--) { |
73 | 77 | $line = $this->file->fgets(); |
74 | - foreach ($delimiters as $delimiter){ |
|
78 | + foreach ($delimiters as $delimiter) { |
|
75 | 79 | $fields = preg_split('/['.$delimiter.']/', $line); |
76 | - if(count($fields) > 1){ |
|
77 | - if(empty($results[$delimiter])){ |
|
80 | + if(count($fields) > 1) { |
|
81 | + if(empty($results[$delimiter])) { |
|
78 | 82 | $results[$delimiter] = 1; |
79 | 83 | } else { |
80 | 84 | $results[$delimiter]++; |
@@ -87,23 +91,29 @@ discard block |
||
87 | 91 | return $results[0]; |
88 | 92 | } |
89 | 93 | |
90 | - public function write($row){ |
|
91 | - if ($this->mode != self::WRITE) return; |
|
94 | + public function write($row) { |
|
95 | + if ($this->mode != self::WRITE) { |
|
96 | + return; |
|
97 | + } |
|
92 | 98 | $row = (array)$row; |
93 | 99 | if (false === $this->savedheaders) { |
94 | 100 | $this->schema(array_keys($row)); |
95 | 101 | } |
96 | 102 | $row_t = $this->template; |
97 | 103 | foreach ($this->headers as $key) { |
98 | - if (isset($row[$key])) $row_t[$key] = $row[$key]; |
|
104 | + if (isset($row[$key])) { |
|
105 | + $row_t[$key] = $row[$key]; |
|
106 | + } |
|
99 | 107 | } |
100 | 108 | $this->file->fputcsv($row_t); |
101 | 109 | } |
102 | 110 | |
103 | - public function read(){ |
|
104 | - if ($this->mode != self::READ) return; |
|
105 | - foreach($this->file as $row){ |
|
106 | - if ($row){ |
|
111 | + public function read() { |
|
112 | + if ($this->mode != self::READ) { |
|
113 | + return; |
|
114 | + } |
|
115 | + foreach($this->file as $row) { |
|
116 | + if ($row) { |
|
107 | 117 | if(!$this->headers) { |
108 | 118 | $this->headers = $row; |
109 | 119 | continue; |
@@ -114,7 +124,7 @@ discard block |
||
114 | 124 | return; |
115 | 125 | } |
116 | 126 | |
117 | - public function each(callable $looper = null){ |
|
127 | + public function each(callable $looper = null) { |
|
118 | 128 | if ($looper) { |
119 | 129 | foreach($this->read() as $row) $looper($row); |
120 | 130 | return $this; |
@@ -125,9 +135,13 @@ discard block |
||
125 | 135 | } |
126 | 136 | } |
127 | 137 | |
128 | - public function convert($filename, $format=self::STANDARD){ |
|
129 | - if ($this->mode != self::READ) return; |
|
130 | - if ($format == self::AUTO) $format = self::STANDARD; |
|
138 | + public function convert($filename, $format=self::STANDARD) { |
|
139 | + if ($this->mode != self::READ) { |
|
140 | + return; |
|
141 | + } |
|
142 | + if ($format == self::AUTO) { |
|
143 | + $format = self::STANDARD; |
|
144 | + } |
|
131 | 145 | $csv = CSV::create($filename, CSV::EXCEL); |
132 | 146 | $this->each(function($row) use ($csv) { |
133 | 147 | $csv->write($row); |
@@ -135,14 +149,14 @@ discard block |
||
135 | 149 | return $csv; |
136 | 150 | } |
137 | 151 | |
138 | - public function flush(){ |
|
152 | + public function flush() { |
|
139 | 153 | if ($this->mode == self::WRITE) { |
140 | 154 | $this->file->fflush(); |
141 | 155 | } |
142 | 156 | } |
143 | 157 | |
144 | - public function schema($schema=null){ |
|
145 | - if($schema){ |
|
158 | + public function schema($schema=null) { |
|
159 | + if($schema) { |
|
146 | 160 | $this->headers = array_values((array)$schema); |
147 | 161 | if ($this->mode == self::WRITE) { |
148 | 162 | $this->savedheaders = true; |
@@ -155,12 +169,12 @@ discard block |
||
155 | 169 | } |
156 | 170 | } |
157 | 171 | |
158 | - public function asString(){ |
|
172 | + public function asString() { |
|
159 | 173 | $this->flush(); |
160 | 174 | return file_get_contents($this->file->getPathname()); |
161 | 175 | } |
162 | 176 | |
163 | - public function __toString(){ |
|
177 | + public function __toString() { |
|
164 | 178 | try { return $this->asString(); } catch(\Exception $e) { return ''; } |
165 | 179 | } |
166 | 180 |
@@ -13,52 +13,52 @@ |
||
13 | 13 | class Options extends Dictionary { |
14 | 14 | protected static $fields = []; |
15 | 15 | |
16 | - /** |
|
17 | - * Load a PHP configuration file (script must return array) |
|
18 | - * @param string $filepath The path of the PHP config file |
|
19 | - * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
|
20 | - */ |
|
21 | - public static function loadPHP($filepath,$prefix_path=null){ |
|
22 | - ob_start(); |
|
23 | - $results = include($filepath); |
|
24 | - ob_end_clean(); |
|
25 | - if($results) static::loadArray($results,$prefix_path); |
|
26 | - } |
|
16 | + /** |
|
17 | + * Load a PHP configuration file (script must return array) |
|
18 | + * @param string $filepath The path of the PHP config file |
|
19 | + * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
|
20 | + */ |
|
21 | + public static function loadPHP($filepath,$prefix_path=null){ |
|
22 | + ob_start(); |
|
23 | + $results = include($filepath); |
|
24 | + ob_end_clean(); |
|
25 | + if($results) static::loadArray($results,$prefix_path); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Load an INI configuration file |
|
30 | - * @param string $filepath The path of the INI config file |
|
31 | - * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
|
32 | - */ |
|
33 | - public static function loadINI($filepath,$prefix_path=null){ |
|
34 | - $results = parse_ini_file($filepath,true); |
|
35 | - if($results) static::loadArray($results,$prefix_path); |
|
36 | - } |
|
28 | + /** |
|
29 | + * Load an INI configuration file |
|
30 | + * @param string $filepath The path of the INI config file |
|
31 | + * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
|
32 | + */ |
|
33 | + public static function loadINI($filepath,$prefix_path=null){ |
|
34 | + $results = parse_ini_file($filepath,true); |
|
35 | + if($results) static::loadArray($results,$prefix_path); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Load a JSON configuration file |
|
40 | - * @param string $filepath The path of the JSON config file |
|
41 | - * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
|
42 | - */ |
|
43 | - public static function loadJSON($filepath,$prefix_path=null){ |
|
44 | - $data = file_get_contents($filepath); |
|
45 | - $results = $data?json_decode($data,true):[]; |
|
46 | - if($results) static::loadArray($results,$prefix_path); |
|
47 | - } |
|
38 | + /** |
|
39 | + * Load a JSON configuration file |
|
40 | + * @param string $filepath The path of the JSON config file |
|
41 | + * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
|
42 | + */ |
|
43 | + public static function loadJSON($filepath,$prefix_path=null){ |
|
44 | + $data = file_get_contents($filepath); |
|
45 | + $results = $data?json_decode($data,true):[]; |
|
46 | + if($results) static::loadArray($results,$prefix_path); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Load an array to the configuration |
|
51 | - * @param array $array The array to load |
|
52 | - * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
|
53 | - */ |
|
54 | - public static function loadArray(array $array,$prefix_path=null){ |
|
55 | - if (is_array($array)) { |
|
56 | - if ($prefix_path){ |
|
57 | - static::set($prefix_path,$array); |
|
58 | - } else { |
|
59 | - static::merge($array); |
|
60 | - } |
|
61 | - } |
|
62 | - } |
|
49 | + /** |
|
50 | + * Load an array to the configuration |
|
51 | + * @param array $array The array to load |
|
52 | + * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
|
53 | + */ |
|
54 | + public static function loadArray(array $array,$prefix_path=null){ |
|
55 | + if (is_array($array)) { |
|
56 | + if ($prefix_path){ |
|
57 | + static::set($prefix_path,$array); |
|
58 | + } else { |
|
59 | + static::merge($array); |
|
60 | + } |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | * @param string $filepath The path of the PHP config file |
19 | 19 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
20 | 20 | */ |
21 | - public static function loadPHP($filepath,$prefix_path=null){ |
|
21 | + public static function loadPHP($filepath, $prefix_path = null) { |
|
22 | 22 | ob_start(); |
23 | 23 | $results = include($filepath); |
24 | 24 | ob_end_clean(); |
25 | - if($results) static::loadArray($results,$prefix_path); |
|
25 | + if ($results) static::loadArray($results, $prefix_path); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * @param string $filepath The path of the INI config file |
31 | 31 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
32 | 32 | */ |
33 | - public static function loadINI($filepath,$prefix_path=null){ |
|
34 | - $results = parse_ini_file($filepath,true); |
|
35 | - if($results) static::loadArray($results,$prefix_path); |
|
33 | + public static function loadINI($filepath, $prefix_path = null) { |
|
34 | + $results = parse_ini_file($filepath, true); |
|
35 | + if ($results) static::loadArray($results, $prefix_path); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | * @param string $filepath The path of the JSON config file |
41 | 41 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
42 | 42 | */ |
43 | - public static function loadJSON($filepath,$prefix_path=null){ |
|
43 | + public static function loadJSON($filepath, $prefix_path = null) { |
|
44 | 44 | $data = file_get_contents($filepath); |
45 | - $results = $data?json_decode($data,true):[]; |
|
46 | - if($results) static::loadArray($results,$prefix_path); |
|
45 | + $results = $data ? json_decode($data, true) : []; |
|
46 | + if ($results) static::loadArray($results, $prefix_path); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | * @param array $array The array to load |
52 | 52 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
53 | 53 | */ |
54 | - public static function loadArray(array $array,$prefix_path=null){ |
|
54 | + public static function loadArray(array $array, $prefix_path = null) { |
|
55 | 55 | if (is_array($array)) { |
56 | - if ($prefix_path){ |
|
57 | - static::set($prefix_path,$array); |
|
56 | + if ($prefix_path) { |
|
57 | + static::set($prefix_path, $array); |
|
58 | 58 | } else { |
59 | 59 | static::merge($array); |
60 | 60 | } |
@@ -18,11 +18,13 @@ discard block |
||
18 | 18 | * @param string $filepath The path of the PHP config file |
19 | 19 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
20 | 20 | */ |
21 | - public static function loadPHP($filepath,$prefix_path=null){ |
|
21 | + public static function loadPHP($filepath,$prefix_path=null) { |
|
22 | 22 | ob_start(); |
23 | 23 | $results = include($filepath); |
24 | 24 | ob_end_clean(); |
25 | - if($results) static::loadArray($results,$prefix_path); |
|
25 | + if($results) { |
|
26 | + static::loadArray($results,$prefix_path); |
|
27 | + } |
|
26 | 28 | } |
27 | 29 | |
28 | 30 | /** |
@@ -30,9 +32,11 @@ discard block |
||
30 | 32 | * @param string $filepath The path of the INI config file |
31 | 33 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
32 | 34 | */ |
33 | - public static function loadINI($filepath,$prefix_path=null){ |
|
35 | + public static function loadINI($filepath,$prefix_path=null) { |
|
34 | 36 | $results = parse_ini_file($filepath,true); |
35 | - if($results) static::loadArray($results,$prefix_path); |
|
37 | + if($results) { |
|
38 | + static::loadArray($results,$prefix_path); |
|
39 | + } |
|
36 | 40 | } |
37 | 41 | |
38 | 42 | /** |
@@ -40,10 +44,12 @@ discard block |
||
40 | 44 | * @param string $filepath The path of the JSON config file |
41 | 45 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
42 | 46 | */ |
43 | - public static function loadJSON($filepath,$prefix_path=null){ |
|
47 | + public static function loadJSON($filepath,$prefix_path=null) { |
|
44 | 48 | $data = file_get_contents($filepath); |
45 | 49 | $results = $data?json_decode($data,true):[]; |
46 | - if($results) static::loadArray($results,$prefix_path); |
|
50 | + if($results) { |
|
51 | + static::loadArray($results,$prefix_path); |
|
52 | + } |
|
47 | 53 | } |
48 | 54 | |
49 | 55 | /** |
@@ -51,9 +57,9 @@ discard block |
||
51 | 57 | * @param array $array The array to load |
52 | 58 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
53 | 59 | */ |
54 | - public static function loadArray(array $array,$prefix_path=null){ |
|
60 | + public static function loadArray(array $array,$prefix_path=null) { |
|
55 | 61 | if (is_array($array)) { |
56 | - if ($prefix_path){ |
|
62 | + if ($prefix_path) { |
|
57 | 63 | static::set($prefix_path,$array); |
58 | 64 | } else { |
59 | 65 | static::merge($array); |
@@ -22,11 +22,11 @@ |
||
22 | 22 | } |
23 | 23 | |
24 | 24 | public static function unmount($alias) { |
25 | - unset(static::$mount_points[$alias]); |
|
25 | + unset(static::$mount_points[$alias]); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | public static function mounts() { |
29 | - return array_keys(static::$mount_points); |
|
29 | + return array_keys(static::$mount_points); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public static function __callStatic($name, $params) { |
@@ -31,22 +31,22 @@ discard block |
||
31 | 31 | |
32 | 32 | public static function __callStatic($name, $params) { |
33 | 33 | $uri = array_shift($params); |
34 | - if ($file_location = static::locate($uri)){ |
|
34 | + if ($file_location = static::locate($uri)) { |
|
35 | 35 | list($mount, $path) = $file_location; |
36 | 36 | array_unshift($params, static::resolvePath($path)); |
37 | 37 | if (empty(static::$mount_points[$mount])) return false; |
38 | - return call_user_func_array([static::$mount_points[$mount],$name],$params); |
|
38 | + return call_user_func_array([static::$mount_points[$mount], $name], $params); |
|
39 | 39 | } else return false; |
40 | 40 | } |
41 | 41 | |
42 | 42 | public static function locate($path) { |
43 | - if (strpos($path,'://')!==false) { |
|
44 | - list($mount, $filepath) = explode('://',$path,2); |
|
43 | + if (strpos($path, '://') !== false) { |
|
44 | + list($mount, $filepath) = explode('://', $path, 2); |
|
45 | 45 | $filepath = static::resolvePath($filepath); |
46 | 46 | return isset(static::$mount_points[$mount]) ? [$mount, $filepath] : false; |
47 | 47 | } else { |
48 | 48 | $path = static::resolvePath($path); |
49 | - foreach(static::$mount_points as $mount => $fs){ |
|
49 | + foreach (static::$mount_points as $mount => $fs) { |
|
50 | 50 | if ($fs->exists($path)) return [$mount, $path]; |
51 | 51 | } |
52 | 52 | return false; |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | $absolutes[] = $part; |
66 | 66 | } |
67 | 67 | } |
68 | - return trim(implode('/', $absolutes),'/'); |
|
68 | + return trim(implode('/', $absolutes), '/'); |
|
69 | 69 | } |
70 | 70 | |
71 | - public static function search($pattern, $recursive=true){ |
|
71 | + public static function search($pattern, $recursive = true) { |
|
72 | 72 | $results = []; |
73 | 73 | foreach (static::$mount_points as $mount => $fs) { |
74 | - foreach($fs->search($pattern, $recursive) as $path) { |
|
74 | + foreach ($fs->search($pattern, $recursive) as $path) { |
|
75 | 75 | $results[] = $mount.'://'.$path; |
76 | 76 | } |
77 | 77 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | |
82 | - public static function move($old,$new) { |
|
82 | + public static function move($old, $new) { |
|
83 | 83 | $src = static::locate($old); |
84 | 84 | $dest = static::locate($new); |
85 | 85 | if ($src && $dest) { |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | $_dfs = static::$mount_points[$dest[0]]; |
88 | 88 | if ($src[0] == $dest[0]) { |
89 | 89 | // Same filesystem |
90 | - return $_sfs->move($src[1],$dest[1]); |
|
90 | + return $_sfs->move($src[1], $dest[1]); |
|
91 | 91 | } else { |
92 | - return $_dfs->write($dest[1],$_sfs->read($src[1])) && $_sfs->delete($src[1]); |
|
92 | + return $_dfs->write($dest[1], $_sfs->read($src[1])) && $_sfs->delete($src[1]); |
|
93 | 93 | } |
94 | 94 | } else return false; |
95 | 95 | } |
@@ -17,7 +17,9 @@ discard block |
||
17 | 17 | |
18 | 18 | public static function mount($alias, $driver, $options = null) { |
19 | 19 | $driver_class = '\\FileSystem\\'.ucfirst(strtolower($driver)); |
20 | - if (!class_exists($driver_class)) throw new \Exception('Filesystem adapter '.$driver.' not found.'); |
|
20 | + if (!class_exists($driver_class)) { |
|
21 | + throw new \Exception('Filesystem adapter '.$driver.' not found.'); |
|
22 | + } |
|
21 | 23 | static::$mount_points[$alias] = new $driver_class($options); |
22 | 24 | } |
23 | 25 | |
@@ -31,12 +33,16 @@ discard block |
||
31 | 33 | |
32 | 34 | public static function __callStatic($name, $params) { |
33 | 35 | $uri = array_shift($params); |
34 | - if ($file_location = static::locate($uri)){ |
|
36 | + if ($file_location = static::locate($uri)) { |
|
35 | 37 | list($mount, $path) = $file_location; |
36 | 38 | array_unshift($params, static::resolvePath($path)); |
37 | - if (empty(static::$mount_points[$mount])) return false; |
|
39 | + if (empty(static::$mount_points[$mount])) { |
|
40 | + return false; |
|
41 | + } |
|
38 | 42 | return call_user_func_array([static::$mount_points[$mount],$name],$params); |
39 | - } else return false; |
|
43 | + } else { |
|
44 | + return false; |
|
45 | + } |
|
40 | 46 | } |
41 | 47 | |
42 | 48 | public static function locate($path) { |
@@ -46,8 +52,10 @@ discard block |
||
46 | 52 | return isset(static::$mount_points[$mount]) ? [$mount, $filepath] : false; |
47 | 53 | } else { |
48 | 54 | $path = static::resolvePath($path); |
49 | - foreach(static::$mount_points as $mount => $fs){ |
|
50 | - if ($fs->exists($path)) return [$mount, $path]; |
|
55 | + foreach(static::$mount_points as $mount => $fs) { |
|
56 | + if ($fs->exists($path)) { |
|
57 | + return [$mount, $path]; |
|
58 | + } |
|
51 | 59 | } |
52 | 60 | return false; |
53 | 61 | } |
@@ -58,7 +66,9 @@ discard block |
||
58 | 66 | $parts = array_filter(explode('/', $path), 'strlen'); |
59 | 67 | $absolutes = []; |
60 | 68 | foreach ($parts as $part) { |
61 | - if ('.' == $part) continue; |
|
69 | + if ('.' == $part) { |
|
70 | + continue; |
|
71 | + } |
|
62 | 72 | if ('..' == $part) { |
63 | 73 | array_pop($absolutes); |
64 | 74 | } else { |
@@ -68,7 +78,7 @@ discard block |
||
68 | 78 | return trim(implode('/', $absolutes),'/'); |
69 | 79 | } |
70 | 80 | |
71 | - public static function search($pattern, $recursive=true){ |
|
81 | + public static function search($pattern, $recursive=true) { |
|
72 | 82 | $results = []; |
73 | 83 | foreach (static::$mount_points as $mount => $fs) { |
74 | 84 | foreach($fs->search($pattern, $recursive) as $path) { |
@@ -91,7 +101,9 @@ discard block |
||
91 | 101 | } else { |
92 | 102 | return $_dfs->write($dest[1],$_sfs->read($src[1])) && $_sfs->delete($src[1]); |
93 | 103 | } |
94 | - } else return false; |
|
104 | + } else { |
|
105 | + return false; |
|
106 | + } |
|
95 | 107 | } |
96 | 108 | |
97 | 109 |