@@ -26,18 +26,18 @@ discard block |
||
26 | 26 | */ |
27 | 27 | trait Traits_Optionable |
28 | 28 | { |
29 | - /** |
|
30 | - * @var array |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var array |
|
31 | + */ |
|
32 | 32 | protected $options; |
33 | 33 | |
34 | - /** |
|
35 | - * Sets an option to the specified value. This can be any |
|
36 | - * kind of variable type, including objects, as needed. |
|
37 | - * |
|
38 | - * @param string $name |
|
39 | - * @param mixed $default |
|
40 | - */ |
|
34 | + /** |
|
35 | + * Sets an option to the specified value. This can be any |
|
36 | + * kind of variable type, including objects, as needed. |
|
37 | + * |
|
38 | + * @param string $name |
|
39 | + * @param mixed $default |
|
40 | + */ |
|
41 | 41 | public function setOption(string $name, $value) |
42 | 42 | { |
43 | 43 | if(!isset($this->options)) { |
@@ -48,12 +48,12 @@ discard block |
||
48 | 48 | return $this; |
49 | 49 | } |
50 | 50 | |
51 | - /** |
|
52 | - * Sets a collection of options at once, from an |
|
53 | - * associative array. |
|
54 | - * |
|
55 | - * @param array $options |
|
56 | - */ |
|
51 | + /** |
|
52 | + * Sets a collection of options at once, from an |
|
53 | + * associative array. |
|
54 | + * |
|
55 | + * @param array $options |
|
56 | + */ |
|
57 | 57 | public function setOptions(array $options) |
58 | 58 | { |
59 | 59 | foreach($options as $name => $value) { |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | return $this; |
64 | 64 | } |
65 | 65 | |
66 | - /** |
|
67 | - * Retrieves an option's value. |
|
68 | - * |
|
69 | - * NOTE: Use the specialized type getters to ensure an option |
|
70 | - * contains the expected type (for ex. getArrayOption()). |
|
71 | - * |
|
72 | - * @param string $name |
|
73 | - * @param mixed $default The default value to return if the option does not exist. |
|
74 | - * @return mixed |
|
75 | - */ |
|
66 | + /** |
|
67 | + * Retrieves an option's value. |
|
68 | + * |
|
69 | + * NOTE: Use the specialized type getters to ensure an option |
|
70 | + * contains the expected type (for ex. getArrayOption()). |
|
71 | + * |
|
72 | + * @param string $name |
|
73 | + * @param mixed $default The default value to return if the option does not exist. |
|
74 | + * @return mixed |
|
75 | + */ |
|
76 | 76 | public function getOption(string $name, $default=null) |
77 | 77 | { |
78 | 78 | if(!isset($this->options)) { |
@@ -86,16 +86,16 @@ discard block |
||
86 | 86 | return $default; |
87 | 87 | } |
88 | 88 | |
89 | - /** |
|
90 | - * Enforces that the option value is a string. Numbers are converted |
|
91 | - * to string, strings are passed through, and all other types will |
|
92 | - * return the default value. The default value is also returned if |
|
93 | - * the string is empty. |
|
94 | - * |
|
95 | - * @param string $name |
|
96 | - * @param string $default Used if the option does not exist, is invalid, or empty. |
|
97 | - * @return string |
|
98 | - */ |
|
89 | + /** |
|
90 | + * Enforces that the option value is a string. Numbers are converted |
|
91 | + * to string, strings are passed through, and all other types will |
|
92 | + * return the default value. The default value is also returned if |
|
93 | + * the string is empty. |
|
94 | + * |
|
95 | + * @param string $name |
|
96 | + * @param string $default Used if the option does not exist, is invalid, or empty. |
|
97 | + * @return string |
|
98 | + */ |
|
99 | 99 | public function getStringOption(string $name, string $default='') : string |
100 | 100 | { |
101 | 101 | $value = $this->getOption($name, false); |
@@ -107,15 +107,15 @@ discard block |
||
107 | 107 | return $default; |
108 | 108 | } |
109 | 109 | |
110 | - /** |
|
111 | - * Treats the option value as a boolean value: will return |
|
112 | - * true if the value actually is a boolean true. |
|
113 | - * |
|
114 | - * NOTE: boolean string representations are not accepted. |
|
115 | - * |
|
116 | - * @param string $name |
|
117 | - * @return bool |
|
118 | - */ |
|
110 | + /** |
|
111 | + * Treats the option value as a boolean value: will return |
|
112 | + * true if the value actually is a boolean true. |
|
113 | + * |
|
114 | + * NOTE: boolean string representations are not accepted. |
|
115 | + * |
|
116 | + * @param string $name |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | 119 | public function getBoolOption(string $name, bool $default=false) : bool |
120 | 120 | { |
121 | 121 | if($this->getOption($name) === true) { |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | return $default; |
126 | 126 | } |
127 | 127 | |
128 | - /** |
|
129 | - * Treats the option value as an integer value: will return |
|
130 | - * valid integer values (also from integer strings), or the |
|
131 | - * default value otherwise. |
|
132 | - * |
|
133 | - * @param string $name |
|
134 | - * @param int $default |
|
135 | - * @return int |
|
136 | - */ |
|
128 | + /** |
|
129 | + * Treats the option value as an integer value: will return |
|
130 | + * valid integer values (also from integer strings), or the |
|
131 | + * default value otherwise. |
|
132 | + * |
|
133 | + * @param string $name |
|
134 | + * @param int $default |
|
135 | + * @return int |
|
136 | + */ |
|
137 | 137 | public function getIntOption(string $name, int $default=0) : int |
138 | 138 | { |
139 | 139 | $value = $this->getOption($name); |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | return $default; |
145 | 145 | } |
146 | 146 | |
147 | - /** |
|
148 | - * Treats an option as an array, and returns its value |
|
149 | - * only if it contains an array - otherwise, an empty |
|
150 | - * array is returned. |
|
151 | - * |
|
152 | - * @param string $name |
|
153 | - * @return array |
|
154 | - */ |
|
147 | + /** |
|
148 | + * Treats an option as an array, and returns its value |
|
149 | + * only if it contains an array - otherwise, an empty |
|
150 | + * array is returned. |
|
151 | + * |
|
152 | + * @param string $name |
|
153 | + * @return array |
|
154 | + */ |
|
155 | 155 | public function getArrayOption(string $name) : array |
156 | 156 | { |
157 | 157 | $val = $this->getOption($name); |
@@ -162,13 +162,13 @@ discard block |
||
162 | 162 | return array(); |
163 | 163 | } |
164 | 164 | |
165 | - /** |
|
166 | - * Checks whether the specified option exists - even |
|
167 | - * if it has a NULL value. |
|
168 | - * |
|
169 | - * @param string $name |
|
170 | - * @return bool |
|
171 | - */ |
|
165 | + /** |
|
166 | + * Checks whether the specified option exists - even |
|
167 | + * if it has a NULL value. |
|
168 | + * |
|
169 | + * @param string $name |
|
170 | + * @return bool |
|
171 | + */ |
|
172 | 172 | public function hasOption(string $name) : bool |
173 | 173 | { |
174 | 174 | if(!isset($this->options)) { |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | return array_key_exists($name, $this->options); |
179 | 179 | } |
180 | 180 | |
181 | - /** |
|
182 | - * Returns all options in one associative array. |
|
183 | - * @return array |
|
184 | - */ |
|
181 | + /** |
|
182 | + * Returns all options in one associative array. |
|
183 | + * @return array |
|
184 | + */ |
|
185 | 185 | public function getOptions() : array |
186 | 186 | { |
187 | 187 | if(!isset($this->options)) { |
@@ -191,24 +191,24 @@ discard block |
||
191 | 191 | return $this->options; |
192 | 192 | } |
193 | 193 | |
194 | - /** |
|
195 | - * Checks whether the option's value is the one specified. |
|
196 | - * |
|
197 | - * @param string $name |
|
198 | - * @param mixed $value |
|
199 | - * @return bool |
|
200 | - */ |
|
194 | + /** |
|
195 | + * Checks whether the option's value is the one specified. |
|
196 | + * |
|
197 | + * @param string $name |
|
198 | + * @param mixed $value |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | 201 | public function isOption(string $name, $value) : bool |
202 | 202 | { |
203 | 203 | return $this->getOption($name) === $value; |
204 | 204 | } |
205 | 205 | |
206 | - /** |
|
207 | - * Retrieves the default available options as an |
|
208 | - * associative array with option name => value pairs. |
|
209 | - * |
|
210 | - * @return array |
|
211 | - */ |
|
206 | + /** |
|
207 | + * Retrieves the default available options as an |
|
208 | + * associative array with option name => value pairs. |
|
209 | + * |
|
210 | + * @return array |
|
211 | + */ |
|
212 | 212 | abstract public function getDefaultOptions() : array; |
213 | 213 | } |
214 | 214 | |
@@ -226,24 +226,24 @@ discard block |
||
226 | 226 | */ |
227 | 227 | interface Interface_Optionable |
228 | 228 | { |
229 | - /** |
|
230 | - * @param string $name |
|
231 | - * @param mixed $value |
|
232 | - * @return Interface_Optionable |
|
233 | - */ |
|
229 | + /** |
|
230 | + * @param string $name |
|
231 | + * @param mixed $value |
|
232 | + * @return Interface_Optionable |
|
233 | + */ |
|
234 | 234 | function setOption(string $name, $value); |
235 | 235 | |
236 | - /** |
|
237 | - * @param string $name |
|
238 | - * @param mixed $default |
|
239 | - * @return Interface_Optionable |
|
240 | - */ |
|
236 | + /** |
|
237 | + * @param string $name |
|
238 | + * @param mixed $default |
|
239 | + * @return Interface_Optionable |
|
240 | + */ |
|
241 | 241 | function getOption(string $name, $default=null); |
242 | 242 | |
243 | - /** |
|
244 | - * @param array $options |
|
245 | - * @return Interface_Optionable |
|
246 | - */ |
|
243 | + /** |
|
244 | + * @param array $options |
|
245 | + * @return Interface_Optionable |
|
246 | + */ |
|
247 | 247 | function setOptions(array $options); |
248 | 248 | function getOptions() : array; |
249 | 249 | function isOption(string $name, $value) : bool; |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | |
39 | 39 | protected $file; |
40 | 40 | |
41 | - /** |
|
42 | - * @var \ZipArchive |
|
43 | - */ |
|
41 | + /** |
|
42 | + * @var \ZipArchive |
|
43 | + */ |
|
44 | 44 | protected $zip; |
45 | 45 | |
46 | 46 | public function __construct($targetFile) |
@@ -48,33 +48,33 @@ discard block |
||
48 | 48 | $this->file = $targetFile; |
49 | 49 | } |
50 | 50 | |
51 | - /** |
|
52 | - * Sets an option, among the available options: |
|
53 | - * |
|
54 | - * <ul> |
|
55 | - * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
56 | - * </ul> |
|
57 | - * |
|
58 | - * @param string $name |
|
59 | - * @param mixed $value |
|
60 | - * @return ZIPHelper |
|
61 | - */ |
|
51 | + /** |
|
52 | + * Sets an option, among the available options: |
|
53 | + * |
|
54 | + * <ul> |
|
55 | + * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
56 | + * </ul> |
|
57 | + * |
|
58 | + * @param string $name |
|
59 | + * @param mixed $value |
|
60 | + * @return ZIPHelper |
|
61 | + */ |
|
62 | 62 | public function setOption($name, $value) |
63 | 63 | { |
64 | 64 | $this->options[$name] = $value; |
65 | 65 | return $this; |
66 | 66 | } |
67 | 67 | |
68 | - /** |
|
69 | - * Adds a file to the zip. By default, the file is stored |
|
70 | - * with the same name in the root of the zip. Use the optional |
|
71 | - * parameter to change the location in the zip. |
|
72 | - * |
|
73 | - * @param string $filePath |
|
74 | - * @param string $zipPath |
|
75 | - * @throws ZIPHelper_Exception |
|
76 | - * @return bool |
|
77 | - */ |
|
68 | + /** |
|
69 | + * Adds a file to the zip. By default, the file is stored |
|
70 | + * with the same name in the root of the zip. Use the optional |
|
71 | + * parameter to change the location in the zip. |
|
72 | + * |
|
73 | + * @param string $filePath |
|
74 | + * @param string $zipPath |
|
75 | + * @throws ZIPHelper_Exception |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | 78 | public function addFile($filePath, $zipPath=null) |
79 | 79 | { |
80 | 80 | $this->open(); |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | readfile($this->file); |
245 | 245 | } |
246 | 246 | |
247 | - /** |
|
248 | - * Like {@link ZIPHelper::download()}, but deletes the |
|
249 | - * file after sending it to the browser. |
|
250 | - * |
|
251 | - * @param string|NULL $fileName Override the ZIP's file name for the download |
|
252 | - * @see ZIPHelper::download() |
|
253 | - */ |
|
247 | + /** |
|
248 | + * Like {@link ZIPHelper::download()}, but deletes the |
|
249 | + * file after sending it to the browser. |
|
250 | + * |
|
251 | + * @param string|NULL $fileName Override the ZIP's file name for the download |
|
252 | + * @see ZIPHelper::download() |
|
253 | + */ |
|
254 | 254 | public function downloadAndDelete($fileName=null) |
255 | 255 | { |
256 | 256 | $this->download($fileName); |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | FileHelper::deleteFile($fileName); |
259 | 259 | } |
260 | 260 | |
261 | - /** |
|
262 | - * Extracts all files and folders from the zip to the |
|
263 | - * target folder. If no folder is specified, the files |
|
264 | - * are extracted into the same folder as the zip itself. |
|
265 | - * |
|
266 | - * @param string $outputFolder |
|
267 | - * @return boolean |
|
268 | - */ |
|
261 | + /** |
|
262 | + * Extracts all files and folders from the zip to the |
|
263 | + * target folder. If no folder is specified, the files |
|
264 | + * are extracted into the same folder as the zip itself. |
|
265 | + * |
|
266 | + * @param string $outputFolder |
|
267 | + * @return boolean |
|
268 | + */ |
|
269 | 269 | public function extractAll($outputFolder=null) |
270 | 270 | { |
271 | 271 | if(empty($outputFolder)) { |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | } |
279 | 279 | |
280 | 280 | |
281 | - /** |
|
282 | - * @return \ZipArchive |
|
283 | - */ |
|
281 | + /** |
|
282 | + * @return \ZipArchive |
|
283 | + */ |
|
284 | 284 | public function getArchive() |
285 | 285 | { |
286 | 286 | $this->open(); |
@@ -288,14 +288,14 @@ discard block |
||
288 | 288 | return $this->zip; |
289 | 289 | } |
290 | 290 | |
291 | - /** |
|
292 | - * JSON encodes the specified data and adds the json as |
|
293 | - * a file in the ZIP archive. |
|
294 | - * |
|
295 | - * @param mixed $data |
|
296 | - * @param string $zipPath |
|
297 | - * @return boolean |
|
298 | - */ |
|
291 | + /** |
|
292 | + * JSON encodes the specified data and adds the json as |
|
293 | + * a file in the ZIP archive. |
|
294 | + * |
|
295 | + * @param mixed $data |
|
296 | + * @param string $zipPath |
|
297 | + * @return boolean |
|
298 | + */ |
|
299 | 299 | public function addJSON($data, $zipPath) |
300 | 300 | { |
301 | 301 | return $this->addString( |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | const ERROR_OPENING_ZIP_FILE = 338003; |
32 | 32 | |
33 | - const ERROR_CANNOT_SAVE_FILE_TO_DISK =338004; |
|
33 | + const ERROR_CANNOT_SAVE_FILE_TO_DISK = 338004; |
|
34 | 34 | |
35 | 35 | protected $options = array( |
36 | 36 | 'WriteThreshold' => 100 |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @throws ZIPHelper_Exception |
76 | 76 | * @return bool |
77 | 77 | */ |
78 | - public function addFile($filePath, $zipPath=null) |
|
78 | + public function addFile($filePath, $zipPath = null) |
|
79 | 79 | { |
80 | 80 | $this->open(); |
81 | 81 | |
@@ -120,16 +120,16 @@ discard block |
||
120 | 120 | |
121 | 121 | protected function open() |
122 | 122 | { |
123 | - if($this->open) { |
|
123 | + if ($this->open) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - if(!isset($this->zip)) { |
|
127 | + if (!isset($this->zip)) { |
|
128 | 128 | $this->zip = new \ZipArchive(); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $flag = null; |
132 | - if(!file_exists($this->file)) { |
|
132 | + if (!file_exists($this->file)) { |
|
133 | 133 | $flag = \ZipArchive::CREATE; |
134 | 134 | } |
135 | 135 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | { |
170 | 170 | $this->fileTracker++; |
171 | 171 | |
172 | - if($this->options['WriteThreshold'] < 1) { |
|
172 | + if ($this->options['WriteThreshold'] < 1) { |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | protected function close() |
184 | 184 | { |
185 | - if(!$this->open) { |
|
185 | + if (!$this->open) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | throw new ZIPHelper_Exception( |
191 | 191 | 'Could not save ZIP file to disk', |
192 | 192 | sprintf( |
193 | - 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, ' . |
|
194 | - 'including adding files that do not exist on disk, trying to create an empty zip, ' . |
|
193 | + 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, '. |
|
194 | + 'including adding files that do not exist on disk, trying to create an empty zip, '. |
|
195 | 195 | 'or trying to save to a directory that does not exist.', |
196 | 196 | $this->file |
197 | 197 | ), |
@@ -228,17 +228,17 @@ discard block |
||
228 | 228 | * @see ZIPHelper::downloadAndDelete() |
229 | 229 | * @throws ZIPHelper_Exception |
230 | 230 | */ |
231 | - public function download($fileName=null) |
|
231 | + public function download($fileName = null) |
|
232 | 232 | { |
233 | 233 | $this->save(); |
234 | 234 | |
235 | - if(empty($fileName)) { |
|
235 | + if (empty($fileName)) { |
|
236 | 236 | $fileName = basename($this->file); |
237 | 237 | } |
238 | 238 | |
239 | 239 | header('Content-type: application/zip'); |
240 | - header('Content-Disposition: attachment; filename=' . $fileName); |
|
241 | - header('Content-length: ' . filesize($this->file)); |
|
240 | + header('Content-Disposition: attachment; filename='.$fileName); |
|
241 | + header('Content-length: '.filesize($this->file)); |
|
242 | 242 | header('Pragma: no-cache'); |
243 | 243 | header('Expires: 0'); |
244 | 244 | readfile($this->file); |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @param string|NULL $fileName Override the ZIP's file name for the download |
252 | 252 | * @see ZIPHelper::download() |
253 | 253 | */ |
254 | - public function downloadAndDelete($fileName=null) |
|
254 | + public function downloadAndDelete($fileName = null) |
|
255 | 255 | { |
256 | 256 | $this->download($fileName); |
257 | 257 | |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | * @param string $outputFolder |
267 | 267 | * @return boolean |
268 | 268 | */ |
269 | - public function extractAll($outputFolder=null) |
|
269 | + public function extractAll($outputFolder = null) |
|
270 | 270 | { |
271 | - if(empty($outputFolder)) { |
|
271 | + if (empty($outputFolder)) { |
|
272 | 272 | $outputFolder = dirname($this->file); |
273 | 273 | } |
274 | 274 |