@@ -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; |
@@ -13,9 +13,9 @@ |
||
13 | 13 | namespace View; |
14 | 14 | |
15 | 15 | interface Adapter { |
16 | - public function __construct($path=null, $options=[]); |
|
17 | - public function render($template,$data=[]); |
|
16 | + public function __construct($path = null, $options = []); |
|
17 | + public function render($template, $data = []); |
|
18 | 18 | public static function exists($path); |
19 | - public static function addGlobal($key,$val); |
|
19 | + public static function addGlobal($key, $val); |
|
20 | 20 | public static function addGlobals(array $defs); |
21 | 21 | } |
@@ -12,12 +12,12 @@ discard block |
||
12 | 12 | |
13 | 13 | class Deferred { |
14 | 14 | |
15 | - protected $callback, |
|
15 | + protected $callback, |
|
16 | 16 | $enabled = true; |
17 | 17 | |
18 | - public function __construct( callable $callback ) { |
|
19 | - $this->callback = $callback; |
|
20 | - } |
|
18 | + public function __construct( callable $callback ) { |
|
19 | + $this->callback = $callback; |
|
20 | + } |
|
21 | 21 | |
22 | 22 | public function disarm() { |
23 | 23 | $this->enabled = false; |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | $this->enabled = true; |
28 | 28 | } |
29 | 29 | |
30 | - public function __destruct() { |
|
31 | - if ( $this->enabled ) call_user_func( $this->callback ); |
|
32 | - } |
|
30 | + public function __destruct() { |
|
31 | + if ( $this->enabled ) call_user_func( $this->callback ); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | protected $callback, |
16 | 16 | $enabled = true; |
17 | 17 | |
18 | - public function __construct( callable $callback ) { |
|
18 | + public function __construct(callable $callback) { |
|
19 | 19 | $this->callback = $callback; |
20 | 20 | } |
21 | 21 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | public function __destruct() { |
31 | - if ( $this->enabled ) call_user_func( $this->callback ); |
|
31 | + if ($this->enabled) call_user_func($this->callback); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -28,7 +28,9 @@ |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | public function __destruct() { |
31 | - if ( $this->enabled ) call_user_func( $this->callback ); |
|
31 | + if ( $this->enabled ) { |
|
32 | + call_user_func( $this->callback ); |
|
33 | + } |
|
32 | 34 | } |
33 | 35 | |
34 | 36 | } |
35 | 37 | \ No newline at end of file |