@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | // private static $modes_create_unexisting_file = ['w', 'w+', 'a', 'a+', 'c', 'c+']; |
14 | 14 | // private static $modes_require_unexisting_file = ['x', 'x+']; |
15 | 15 | |
16 | - public function __construct($path_to_file, $mode='r') |
|
16 | + public function __construct($path_to_file, $mode = 'r') |
|
17 | 17 | { |
18 | - if(!FileSystem::exists($path_to_file) && self::requires_existing_file($mode)) |
|
18 | + if (!FileSystem::exists($path_to_file) && self::requires_existing_file($mode)) |
|
19 | 19 | throw new \Exception('FILE_MUST_ALREADY_EXIST ('.$this->filepath().', '.$this->mode.')'); |
20 | 20 | |
21 | 21 | $this->filepath = new FilePath($path_to_file); |
@@ -25,17 +25,17 @@ discard block |
||
25 | 25 | public function open() |
26 | 26 | { |
27 | 27 | $this->pointer = fopen($this->filepath, $this->mode); |
28 | - if($this->pointer === false) |
|
28 | + if ($this->pointer === false) |
|
29 | 29 | throw new \Exception('FILE_OPEN_FAILURE ('.$this->filepath().', '.$this->mode.')'); |
30 | 30 | return $this->pointer; |
31 | 31 | } |
32 | 32 | |
33 | 33 | public function close() |
34 | 34 | { |
35 | - if(!is_resource($this->pointer)) |
|
35 | + if (!is_resource($this->pointer)) |
|
36 | 36 | return true; |
37 | 37 | |
38 | - if(fclose($this->pointer) === false) |
|
38 | + if (fclose($this->pointer) === false) |
|
39 | 39 | throw new \Exception('FILE_CLOSE_FAILURE ('.$this->filepath().', '.$this->mode.')'); |
40 | 40 | |
41 | 41 | return true; |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | |
49 | 49 | public function set_content($content) |
50 | 50 | { |
51 | - if(is_writable($this->filepath) !== true && self::requires_existing_file($this->mode)) |
|
51 | + if (is_writable($this->filepath) !== true && self::requires_existing_file($this->mode)) |
|
52 | 52 | throw new \Exception('FILE_IS_NOT_WRITABLE ('.$this->filepath().', '.$this->mode.')'); |
53 | 53 | |
54 | 54 | $this->open(); |
55 | - if(fwrite($this->pointer, $content) === false) |
|
55 | + if (fwrite($this->pointer, $content) === false) |
|
56 | 56 | throw new \Exception('FILE_WRITE_FAILURE ('.$this->filepath().', '.$this->mode.')'); |
57 | 57 | $this->close(); |
58 | 58 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | { |
72 | 72 | $res = $this->size_in_bytes; |
73 | 73 | |
74 | - if(is_null($res) && ($res = filesize("$this->filepath")) !== false) |
|
74 | + if (is_null($res) && ($res = filesize("$this->filepath")) !== false) |
|
75 | 75 | $this->size_in_bytes = $res; |
76 | 76 | |
77 | 77 | return $res; |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | |
16 | 16 | public function __construct($path_to_file, $mode='r') |
17 | 17 | { |
18 | - if(!FileSystem::exists($path_to_file) && self::requires_existing_file($mode)) |
|
19 | - throw new \Exception('FILE_MUST_ALREADY_EXIST ('.$this->filepath().', '.$this->mode.')'); |
|
18 | + if(!FileSystem::exists($path_to_file) && self::requires_existing_file($mode)) { |
|
19 | + throw new \Exception('FILE_MUST_ALREADY_EXIST ('.$this->filepath().', '.$this->mode.')'); |
|
20 | + } |
|
20 | 21 | |
21 | 22 | $this->filepath = new FilePath($path_to_file); |
22 | 23 | $this->mode = $mode; |
@@ -25,18 +26,21 @@ discard block |
||
25 | 26 | public function open() |
26 | 27 | { |
27 | 28 | $this->pointer = fopen($this->filepath, $this->mode); |
28 | - if($this->pointer === false) |
|
29 | - throw new \Exception('FILE_OPEN_FAILURE ('.$this->filepath().', '.$this->mode.')'); |
|
29 | + if($this->pointer === false) { |
|
30 | + throw new \Exception('FILE_OPEN_FAILURE ('.$this->filepath().', '.$this->mode.')'); |
|
31 | + } |
|
30 | 32 | return $this->pointer; |
31 | 33 | } |
32 | 34 | |
33 | 35 | public function close() |
34 | 36 | { |
35 | - if(!is_resource($this->pointer)) |
|
36 | - return true; |
|
37 | + if(!is_resource($this->pointer)) { |
|
38 | + return true; |
|
39 | + } |
|
37 | 40 | |
38 | - if(fclose($this->pointer) === false) |
|
39 | - throw new \Exception('FILE_CLOSE_FAILURE ('.$this->filepath().', '.$this->mode.')'); |
|
41 | + if(fclose($this->pointer) === false) { |
|
42 | + throw new \Exception('FILE_CLOSE_FAILURE ('.$this->filepath().', '.$this->mode.')'); |
|
43 | + } |
|
40 | 44 | |
41 | 45 | return true; |
42 | 46 | } |
@@ -48,12 +52,14 @@ discard block |
||
48 | 52 | |
49 | 53 | public function set_content($content) |
50 | 54 | { |
51 | - if(is_writable($this->filepath) !== true && self::requires_existing_file($this->mode)) |
|
52 | - throw new \Exception('FILE_IS_NOT_WRITABLE ('.$this->filepath().', '.$this->mode.')'); |
|
55 | + if(is_writable($this->filepath) !== true && self::requires_existing_file($this->mode)) { |
|
56 | + throw new \Exception('FILE_IS_NOT_WRITABLE ('.$this->filepath().', '.$this->mode.')'); |
|
57 | + } |
|
53 | 58 | |
54 | 59 | $this->open(); |
55 | - if(fwrite($this->pointer, $content) === false) |
|
56 | - throw new \Exception('FILE_WRITE_FAILURE ('.$this->filepath().', '.$this->mode.')'); |
|
60 | + if(fwrite($this->pointer, $content) === false) { |
|
61 | + throw new \Exception('FILE_WRITE_FAILURE ('.$this->filepath().', '.$this->mode.')'); |
|
62 | + } |
|
57 | 63 | $this->close(); |
58 | 64 | } |
59 | 65 | |
@@ -71,8 +77,9 @@ discard block |
||
71 | 77 | { |
72 | 78 | $res = $this->size_in_bytes; |
73 | 79 | |
74 | - if(is_null($res) && ($res = filesize("$this->filepath")) !== false) |
|
75 | - $this->size_in_bytes = $res; |
|
80 | + if(is_null($res) && ($res = filesize("$this->filepath")) !== false) { |
|
81 | + $this->size_in_bytes = $res; |
|
82 | + } |
|
76 | 83 | |
77 | 84 | return $res; |
78 | 85 | } |
@@ -19,8 +19,8 @@ |
||
19 | 19 | |
20 | 20 | public function filenames($regex=null) : array |
21 | 21 | { |
22 | - if(!file_exists($this->root_path) && mkdir($this->root_path) === false) |
|
23 | - return []; |
|
22 | + if(!file_exists($this->root_path) && mkdir($this->root_path) === false) |
|
23 | + return []; |
|
24 | 24 | |
25 | 25 | $filenames = self::preg_scandir($this->root_path, $regex);// ID_SEQUENCENUMBER.ext |
26 | 26 | if(!is_null($filenames)) |
@@ -17,23 +17,23 @@ discard block |
||
17 | 17 | return $this->root_path.'/'.$filename; |
18 | 18 | } |
19 | 19 | |
20 | - public function filenames($regex=null) : array |
|
20 | + public function filenames($regex = null) : array |
|
21 | 21 | { |
22 | - if(!file_exists($this->root_path) && mkdir($this->root_path) === false) |
|
22 | + if (!file_exists($this->root_path) && mkdir($this->root_path) === false) |
|
23 | 23 | return []; |
24 | 24 | |
25 | - $filenames = self::preg_scandir($this->root_path, $regex);// ID_SEQUENCENUMBER.ext |
|
26 | - if(!is_null($filenames)) |
|
25 | + $filenames = self::preg_scandir($this->root_path, $regex); // ID_SEQUENCENUMBER.ext |
|
26 | + if (!is_null($filenames)) |
|
27 | 27 | sort($filenames); |
28 | 28 | |
29 | 29 | return $filenames; |
30 | 30 | } |
31 | 31 | |
32 | - public function filepathes($regex=null) : array |
|
32 | + public function filepathes($regex = null) : array |
|
33 | 33 | { |
34 | 34 | $filenames = $this->filenames($regex); |
35 | 35 | $filepathes = []; |
36 | - foreach($filenames as $filename) |
|
36 | + foreach ($filenames as $filename) |
|
37 | 37 | $filepathes[] = $this->path_to($filename); |
38 | 38 | |
39 | 39 | return $filepathes; |
@@ -41,18 +41,18 @@ discard block |
||
41 | 41 | |
42 | 42 | |
43 | 43 | // kontrolas ĉu la dosiero aŭ dosierujo ekzistas |
44 | - public static function exists($src_path){ return file_exists($src_path);} |
|
45 | - public static function is_file($src_path){ return is_file($src_path);} |
|
46 | - public static function is_dir($src_path){ return is_dir($src_path);} |
|
47 | - public static function is_link($src_path){ return is_link($src_path);} |
|
44 | + public static function exists($src_path) { return file_exists($src_path); } |
|
45 | + public static function is_file($src_path) { return is_file($src_path); } |
|
46 | + public static function is_dir($src_path) { return is_dir($src_path); } |
|
47 | + public static function is_link($src_path) { return is_link($src_path); } |
|
48 | 48 | |
49 | 49 | |
50 | 50 | public static function resolve_symlink($path) |
51 | 51 | { |
52 | - if(is_link($path)) |
|
52 | + if (is_link($path)) |
|
53 | 53 | { |
54 | 54 | $res = readlink($path); |
55 | - if($res === false) |
|
55 | + if ($res === false) |
|
56 | 56 | throw new \Exception('readlink failed on '.$path); |
57 | 57 | |
58 | 58 | $path = $res; |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | |
63 | 63 | public static function copy($src_path, $dst_path) |
64 | 64 | { |
65 | - if(self::exists($src_path) && self::is_file($src_path)) |
|
65 | + if (self::exists($src_path) && self::is_file($src_path)) |
|
66 | 66 | { |
67 | 67 | $dst = new FilePath($dst_path); |
68 | - if(self::exists($dst->dir()) && self::is_dir($dst->dir())) |
|
68 | + if (self::exists($dst->dir()) && self::is_dir($dst->dir())) |
|
69 | 69 | return copy($src_path, $dst_path); // Returns TRUE on success or FALSE on failure. |
70 | 70 | |
71 | 71 | // vd(__FUNCTION__.'ERR: self::exists('.$dst->dir().') && self::is_dir('.$dst->dir().')'); |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | |
77 | 77 | public static function move($src_path, $dst_path) |
78 | 78 | { |
79 | - if(self::exists($src_path) && self::is_file($src_path)) |
|
79 | + if (self::exists($src_path) && self::is_file($src_path)) |
|
80 | 80 | { |
81 | 81 | $dst = new FilePath($dst_path, true); |
82 | - if(self::exists($dst->dir()) && self::is_dir($dst->dir())) |
|
82 | + if (self::exists($dst->dir()) && self::is_dir($dst->dir())) |
|
83 | 83 | { |
84 | 84 | return rename($src_path, $dst_path); // Returns TRUE on success or FALSE on failure. |
85 | 85 | } |
@@ -92,33 +92,33 @@ discard block |
||
92 | 92 | } |
93 | 93 | |
94 | 94 | |
95 | - public static function make_dir($dst_path, $permission=0777, $recursive=true) : bool |
|
95 | + public static function make_dir($dst_path, $permission = 0777, $recursive = true) : bool |
|
96 | 96 | { |
97 | 97 | return mkdir($dst_path, $permission, $recursive); |
98 | 98 | } |
99 | 99 | |
100 | - public static function remove($src_path, $follow_link=false) |
|
100 | + public static function remove($src_path, $follow_link = false) |
|
101 | 101 | { |
102 | 102 | $ret = false; |
103 | - if(self::exists($src_path)) |
|
103 | + if (self::exists($src_path)) |
|
104 | 104 | { |
105 | - if(self::is_link($src_path) && $follow_link === true) |
|
105 | + if (self::is_link($src_path) && $follow_link === true) |
|
106 | 106 | $ret = self::remove(readlink($src_path)); |
107 | - elseif(self::is_file($src_path)) |
|
107 | + elseif (self::is_file($src_path)) |
|
108 | 108 | $ret = unlink($src_path); // Returns TRUE on success or FALSE on failure. |
109 | - else if(self::is_dir($src_path)) |
|
109 | + else if (self::is_dir($src_path)) |
|
110 | 110 | $ret = rmdir($src_path); // Returns TRUE on success or FALSE on failure. |
111 | 111 | } |
112 | 112 | return $ret; |
113 | 113 | } |
114 | 114 | |
115 | - public static function preg_scandir($dir_path, $regex=null) |
|
115 | + public static function preg_scandir($dir_path, $regex = null) |
|
116 | 116 | { |
117 | - if(!self::exists($dir_path) || !self::is_dir($dir_path)) |
|
117 | + if (!self::exists($dir_path) || !self::is_dir($dir_path)) |
|
118 | 118 | return null; |
119 | 119 | |
120 | - if(($filenames = scandir($dir_path, SCANDIR_SORT_ASCENDING)) !== false) |
|
121 | - return is_null($regex)? $filenames : preg_grep($regex, $filenames); |
|
120 | + if (($filenames = scandir($dir_path, SCANDIR_SORT_ASCENDING)) !== false) |
|
121 | + return is_null($regex) ? $filenames : preg_grep($regex, $filenames); |
|
122 | 122 | |
123 | 123 | throw new \Exception("directory path '$dir_path' cannot be scanned"); |
124 | 124 | } |
@@ -19,12 +19,14 @@ discard block |
||
19 | 19 | |
20 | 20 | public function filenames($regex=null) : array |
21 | 21 | { |
22 | - if(!file_exists($this->root_path) && mkdir($this->root_path) === false) |
|
23 | - return []; |
|
22 | + if(!file_exists($this->root_path) && mkdir($this->root_path) === false) { |
|
23 | + return []; |
|
24 | + } |
|
24 | 25 | |
25 | 26 | $filenames = self::preg_scandir($this->root_path, $regex);// ID_SEQUENCENUMBER.ext |
26 | - if(!is_null($filenames)) |
|
27 | - sort($filenames); |
|
27 | + if(!is_null($filenames)) { |
|
28 | + sort($filenames); |
|
29 | + } |
|
28 | 30 | |
29 | 31 | return $filenames; |
30 | 32 | } |
@@ -33,8 +35,9 @@ discard block |
||
33 | 35 | { |
34 | 36 | $filenames = $this->filenames($regex); |
35 | 37 | $filepathes = []; |
36 | - foreach($filenames as $filename) |
|
37 | - $filepathes[] = $this->path_to($filename); |
|
38 | + foreach($filenames as $filename) { |
|
39 | + $filepathes[] = $this->path_to($filename); |
|
40 | + } |
|
38 | 41 | |
39 | 42 | return $filepathes; |
40 | 43 | } |
@@ -52,8 +55,9 @@ discard block |
||
52 | 55 | if(is_link($path)) |
53 | 56 | { |
54 | 57 | $res = readlink($path); |
55 | - if($res === false) |
|
56 | - throw new \Exception('readlink failed on '.$path); |
|
58 | + if($res === false) { |
|
59 | + throw new \Exception('readlink failed on '.$path); |
|
60 | + } |
|
57 | 61 | |
58 | 62 | $path = $res; |
59 | 63 | } |
@@ -65,8 +69,10 @@ discard block |
||
65 | 69 | if(self::exists($src_path) && self::is_file($src_path)) |
66 | 70 | { |
67 | 71 | $dst = new FilePath($dst_path); |
68 | - if(self::exists($dst->dir()) && self::is_dir($dst->dir())) |
|
69 | - return copy($src_path, $dst_path); // Returns TRUE on success or FALSE on failure. |
|
72 | + if(self::exists($dst->dir()) && self::is_dir($dst->dir())) { |
|
73 | + return copy($src_path, $dst_path); |
|
74 | + } |
|
75 | + // Returns TRUE on success or FALSE on failure. |
|
70 | 76 | |
71 | 77 | // vd(__FUNCTION__.'ERR: self::exists('.$dst->dir().') && self::is_dir('.$dst->dir().')'); |
72 | 78 | } |
@@ -102,23 +108,29 @@ discard block |
||
102 | 108 | $ret = false; |
103 | 109 | if(self::exists($src_path)) |
104 | 110 | { |
105 | - if(self::is_link($src_path) && $follow_link === true) |
|
106 | - $ret = self::remove(readlink($src_path)); |
|
107 | - elseif(self::is_file($src_path)) |
|
108 | - $ret = unlink($src_path); // Returns TRUE on success or FALSE on failure. |
|
109 | - else if(self::is_dir($src_path)) |
|
110 | - $ret = rmdir($src_path); // Returns TRUE on success or FALSE on failure. |
|
111 | + if(self::is_link($src_path) && $follow_link === true) { |
|
112 | + $ret = self::remove(readlink($src_path)); |
|
113 | + } elseif(self::is_file($src_path)) { |
|
114 | + $ret = unlink($src_path); |
|
115 | + } |
|
116 | + // Returns TRUE on success or FALSE on failure. |
|
117 | + else if(self::is_dir($src_path)) { |
|
118 | + $ret = rmdir($src_path); |
|
119 | + } |
|
120 | + // Returns TRUE on success or FALSE on failure. |
|
111 | 121 | } |
112 | 122 | return $ret; |
113 | 123 | } |
114 | 124 | |
115 | 125 | public static function preg_scandir($dir_path, $regex=null) |
116 | 126 | { |
117 | - if(!self::exists($dir_path) || !self::is_dir($dir_path)) |
|
118 | - return null; |
|
127 | + if(!self::exists($dir_path) || !self::is_dir($dir_path)) { |
|
128 | + return null; |
|
129 | + } |
|
119 | 130 | |
120 | - if(($filenames = scandir($dir_path, SCANDIR_SORT_ASCENDING)) !== false) |
|
121 | - return is_null($regex)? $filenames : preg_grep($regex, $filenames); |
|
131 | + if(($filenames = scandir($dir_path, SCANDIR_SORT_ASCENDING)) !== false) { |
|
132 | + return is_null($regex)? $filenames : preg_grep($regex, $filenames); |
|
133 | + } |
|
122 | 134 | |
123 | 135 | throw new \Exception("directory path '$dir_path' cannot be scanned"); |
124 | 136 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | public static function identical($filepath_1, $filepath_2, $read_length = 8192) |
9 | 9 | { |
10 | 10 | //** TEST FOR EXISTENCE |
11 | - if(!file_exists($filepath_1) || !file_exists($filepath_2)) |
|
11 | + if (!file_exists($filepath_1) || !file_exists($filepath_2)) |
|
12 | 12 | throw new \Exception('file_exists false'); |
13 | 13 | |
14 | 14 | //** TEST FOR SYMLINK |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | $filepath_2 = self::resolve_symlink($filepath_2); |
17 | 17 | |
18 | 18 | //** TEST FOR IDENTICAL TYPE AND SIZE |
19 | - if(filetype($filepath_1) !== filetype($filepath_2) || filesize($filepath_1) !== filesize($filepath_2)) |
|
19 | + if (filetype($filepath_1) !== filetype($filepath_2) || filesize($filepath_1) !== filesize($filepath_2)) |
|
20 | 20 | return false; |
21 | 21 | |
22 | 22 | //** TEST FOR IDENTICAL CONTENT |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $identical = true; |
36 | 36 | while (!feof($filepointer_1) && !feof($filepointer_2) && $identical) |
37 | 37 | { |
38 | - if(false === ($buffer_1 = fread($filepointer_1, $read_length)) || false === ($buffer_2 = fread($filepointer_2, $read_length))) |
|
38 | + if (false === ($buffer_1 = fread($filepointer_1, $read_length)) || false === ($buffer_2 = fread($filepointer_2, $read_length))) |
|
39 | 39 | { |
40 | 40 | throw new \Exception('FAILED fread('.$filepath_1.' or '.$filepath_2.')'); |
41 | 41 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $identical = (0 === strcmp($buffer_1, $buffer_2)); |
44 | 44 | } |
45 | 45 | |
46 | - if($identical === true && feof($filepointer_1) !== feof($filepointer_2)) |
|
46 | + if ($identical === true && feof($filepointer_1) !== feof($filepointer_2)) |
|
47 | 47 | $identical = false; |
48 | 48 | |
49 | 49 | } |
@@ -8,16 +8,18 @@ discard block |
||
8 | 8 | public static function identical($filepath_1, $filepath_2, $read_length = 8192) |
9 | 9 | { |
10 | 10 | //** TEST FOR EXISTENCE |
11 | - if(!file_exists($filepath_1) || !file_exists($filepath_2)) |
|
12 | - throw new \Exception('file_exists false'); |
|
11 | + if(!file_exists($filepath_1) || !file_exists($filepath_2)) { |
|
12 | + throw new \Exception('file_exists false'); |
|
13 | + } |
|
13 | 14 | |
14 | 15 | //** TEST FOR SYMLINK |
15 | 16 | $filepath_1 = self::resolve_symlink($filepath_1); |
16 | 17 | $filepath_2 = self::resolve_symlink($filepath_2); |
17 | 18 | |
18 | 19 | //** TEST FOR IDENTICAL TYPE AND SIZE |
19 | - if(filetype($filepath_1) !== filetype($filepath_2) || filesize($filepath_1) !== filesize($filepath_2)) |
|
20 | - return false; |
|
20 | + if(filetype($filepath_1) !== filetype($filepath_2) || filesize($filepath_1) !== filesize($filepath_2)) { |
|
21 | + return false; |
|
22 | + } |
|
21 | 23 | |
22 | 24 | //** TEST FOR IDENTICAL CONTENT |
23 | 25 | return self::compare_content($filepath_1, $filepath_2, $read_length); |
@@ -43,15 +45,14 @@ discard block |
||
43 | 45 | $identical = (0 === strcmp($buffer_1, $buffer_2)); |
44 | 46 | } |
45 | 47 | |
46 | - if($identical === true && feof($filepointer_1) !== feof($filepointer_2)) |
|
47 | - $identical = false; |
|
48 | + if($identical === true && feof($filepointer_1) !== feof($filepointer_2)) { |
|
49 | + $identical = false; |
|
50 | + } |
|
48 | 51 | |
49 | - } |
|
50 | - catch (\Exception $e) |
|
52 | + } catch (\Exception $e) |
|
51 | 53 | { |
52 | 54 | return false; |
53 | - } |
|
54 | - finally |
|
55 | + } finally |
|
55 | 56 | { |
56 | 57 | $file_1->close(); |
57 | 58 | $file_2->close(); |
@@ -10,18 +10,18 @@ discard block |
||
10 | 10 | $ret = json_decode($string, $assoc, $depth, $options); |
11 | 11 | |
12 | 12 | $error = self::has_errors(); |
13 | - if($error !== false) |
|
13 | + if ($error !== false) |
|
14 | 14 | throw new \Exception("ParsingException: $error"); |
15 | 15 | |
16 | 16 | return $ret; |
17 | 17 | } |
18 | 18 | |
19 | - public static function from_php($var, $options= 0, $depth = 512) |
|
19 | + public static function from_php($var, $options = 0, $depth = 512) |
|
20 | 20 | { |
21 | 21 | $ret = json_encode($var, $options, $depth); |
22 | 22 | |
23 | 23 | $error = self::has_errors(); |
24 | - if($error !== false) |
|
24 | + if ($error !== false) |
|
25 | 25 | throw new \Exception("ParsingException: $error"); |
26 | 26 | |
27 | 27 | return $ret; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | private static function has_errors() |
31 | 31 | { |
32 | - if(json_last_error() === JSON_ERROR_NONE) |
|
32 | + if (json_last_error() === JSON_ERROR_NONE) |
|
33 | 33 | return false; |
34 | 34 | |
35 | 35 | return json_last_error_msg(); |
@@ -10,8 +10,9 @@ discard block |
||
10 | 10 | $ret = json_decode($string, $assoc, $depth, $options); |
11 | 11 | |
12 | 12 | $error = self::has_errors(); |
13 | - if($error !== false) |
|
14 | - throw new \Exception("ParsingException: $error"); |
|
13 | + if($error !== false) { |
|
14 | + throw new \Exception("ParsingException: $error"); |
|
15 | + } |
|
15 | 16 | |
16 | 17 | return $ret; |
17 | 18 | } |
@@ -21,16 +22,18 @@ discard block |
||
21 | 22 | $ret = json_encode($var, $options, $depth); |
22 | 23 | |
23 | 24 | $error = self::has_errors(); |
24 | - if($error !== false) |
|
25 | - throw new \Exception("ParsingException: $error"); |
|
25 | + if($error !== false) { |
|
26 | + throw new \Exception("ParsingException: $error"); |
|
27 | + } |
|
26 | 28 | |
27 | 29 | return $ret; |
28 | 30 | } |
29 | 31 | |
30 | 32 | private static function has_errors() |
31 | 33 | { |
32 | - if(json_last_error() === JSON_ERROR_NONE) |
|
33 | - return false; |
|
34 | + if(json_last_error() === JSON_ERROR_NONE) { |
|
35 | + return false; |
|
36 | + } |
|
34 | 37 | |
35 | 38 | return json_last_error_msg(); |
36 | 39 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | class CSV extends TextFile |
6 | 6 | { |
7 | - const LIST_ANORMAL_SEPARATOR_REGEX = '/\r\n|\n|\r/'; |
|
7 | + const LIST_ANORMAL_SEPARATOR_REGEX = '/\r\n|\n|\r/'; |
|
8 | 8 | |
9 | 9 | // T — Gets line from file pointer and parse for CSV fields |
10 | 10 | // fgetcsv ( resource $handle [, int $length = 0 [, string $delimiter = "," [, string $enclosure = '"' [, string $escape = "\\" ]]]] ) : array |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | |
30 | 30 | |
31 | 31 | */ |
32 | - function array() |
|
33 | - { |
|
34 | - return array_map('str_getcsv', parent::array()); |
|
35 | - } |
|
32 | + function array() |
|
33 | + { |
|
34 | + return array_map('str_getcsv', parent::array()); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | //TODO WTF is this doing here ?? |
38 | 38 | public static function collection_of_models_to_csv($collection, $model, $output) |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | //TODO WTF is this doing here ?? |
38 | 38 | public static function collection_of_models_to_csv($collection, $model, $output) |
39 | 39 | { |
40 | - if($output === 'php://output') |
|
40 | + if ($output === 'php://output') |
|
41 | 41 | { |
42 | 42 | $stream = "$output"; |
43 | 43 | header('Content-Description: File Transfer'); |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | fputcsv($stream, array_keys($model->fields())); // CSV headers |
59 | 59 | |
60 | 60 | |
61 | - foreach($collection as $model) |
|
61 | + foreach ($collection as $model) |
|
62 | 62 | { |
63 | 63 | $model = $model->export(); |
64 | - foreach($model as $key => $value){ |
|
64 | + foreach ($model as $key => $value) { |
|
65 | 65 | $model[$key] = preg_replace(Model::LIST_ANORMAL_SEPARATOR_REGEX, '|', $value); |
66 | 66 | } |
67 | 67 | fputcsv($stream, $model); |
@@ -47,8 +47,7 @@ |
||
47 | 47 | header('Expires: 0'); |
48 | 48 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
49 | 49 | header('Pragma: public'); |
50 | - } |
|
51 | - else |
|
50 | + } else |
|
52 | 51 | { |
53 | 52 | $stream = $output; |
54 | 53 | } |
@@ -9,23 +9,23 @@ discard block |
||
9 | 9 | { |
10 | 10 | $ret = '# INI Dump'; |
11 | 11 | |
12 | - if(is_array(current($array))) // with sections |
|
12 | + if (is_array(current($array))) // with sections |
|
13 | 13 | { |
14 | - foreach($array as $section => $data) |
|
14 | + foreach ($array as $section => $data) |
|
15 | 15 | { |
16 | - $ret.= PHP_EOL.PHP_EOL.self::section($section); |
|
17 | - foreach($data as $key => $value) |
|
18 | - $ret.= PHP_EOL.self::line($key, $value); |
|
16 | + $ret .= PHP_EOL.PHP_EOL.self::section($section); |
|
17 | + foreach ($data as $key => $value) |
|
18 | + $ret .= PHP_EOL.self::line($key, $value); |
|
19 | 19 | } |
20 | 20 | } |
21 | 21 | else // no section |
22 | - foreach($array as $key => $value) |
|
23 | - $ret.= self::line($key, $value); |
|
22 | + foreach ($array as $key => $value) |
|
23 | + $ret .= self::line($key, $value); |
|
24 | 24 | |
25 | 25 | return $ret; |
26 | 26 | } |
27 | 27 | |
28 | - public static function to_array($filepath, $with_sections=true, $mode=INI_SCANNER_RAW) |
|
28 | + public static function to_array($filepath, $with_sections = true, $mode = INI_SCANNER_RAW) |
|
29 | 29 | { |
30 | 30 | return parse_ini_file($filepath, $with_sections, $mode); |
31 | 31 | //https://secure.php.net/manual/en/function.parse-ini-file.php |
@@ -53,6 +53,6 @@ discard block |
||
53 | 53 | |
54 | 54 | private static function format_key($key) |
55 | 55 | { |
56 | - return str_replace(' ', '_',$key); |
|
56 | + return str_replace(' ', '_', $key); |
|
57 | 57 | } |
58 | 58 | } |
@@ -9,18 +9,22 @@ |
||
9 | 9 | { |
10 | 10 | $ret = '# INI Dump'; |
11 | 11 | |
12 | - if(is_array(current($array))) // with sections |
|
12 | + if(is_array(current($array))) { |
|
13 | + // with sections |
|
13 | 14 | { |
14 | 15 | foreach($array as $section => $data) |
15 | 16 | { |
16 | 17 | $ret.= PHP_EOL.PHP_EOL.self::section($section); |
17 | - foreach($data as $key => $value) |
|
18 | - $ret.= PHP_EOL.self::line($key, $value); |
|
19 | - } |
|
20 | 18 | } |
21 | - else // no section |
|
19 | + foreach($data as $key => $value) { |
|
20 | + $ret.= PHP_EOL.self::line($key, $value); |
|
21 | + } |
|
22 | + } |
|
23 | + } else { |
|
24 | + // no section |
|
22 | 25 | foreach($array as $key => $value) |
23 | 26 | $ret.= self::line($key, $value); |
27 | + } |
|
24 | 28 | |
25 | 29 | return $ret; |
26 | 30 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | $this->filepath = $filepath; |
18 | 18 | } |
19 | 19 | |
20 | - public function __toString(){ return ''.$this->filepath;} |
|
20 | + public function __toString() { return ''.$this->filepath; } |
|
21 | 21 | |
22 | 22 | public function dir() : string |
23 | 23 | { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | private function parse() |
38 | 38 | { |
39 | - if($this->already_parsed === false) |
|
39 | + if ($this->already_parsed === false) |
|
40 | 40 | { |
41 | 41 | $res = pathinfo($this->filepath); |
42 | 42 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $this->file = $res['basename']; |
45 | 45 | $this->file_extension = $res['extension']; |
46 | 46 | |
47 | - $this->already_parsed=true; |
|
47 | + $this->already_parsed = true; |
|
48 | 48 | } |
49 | 49 | return $this; |
50 | 50 | } |