@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | public function __construct() |
65 | 65 | { |
66 | - if(class_exists('\AppLocalize\Localization')) { |
|
66 | + if (class_exists('\AppLocalize\Localization')) { |
|
67 | 67 | \AppLocalize\Localization::onLocaleChanged(array($this, 'handle_localeChanged')); |
68 | 68 | } |
69 | 69 | } |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | |
126 | 126 | $epoch = 'past'; |
127 | 127 | $key = 'singular'; |
128 | - if($this->dateDiff > 1) { |
|
128 | + if ($this->dateDiff > 1) { |
|
129 | 129 | $key = 'plural'; |
130 | 130 | } |
131 | 131 | |
132 | - if($this->future) { |
|
132 | + if ($this->future) { |
|
133 | 133 | $epoch = 'future'; |
134 | 134 | } |
135 | 135 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | |
143 | 143 | protected function initTexts() |
144 | 144 | { |
145 | - if(isset(self::$texts)) { |
|
145 | + if (isset(self::$texts)) { |
|
146 | 146 | return; |
147 | 147 | } |
148 | 148 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $day = (int)date("j", $this->dateTo); |
229 | 229 | $year = (int)date("Y", $this->dateFrom); |
230 | 230 | |
231 | - while(mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $this->dateTo) |
|
231 | + while (mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $this->dateTo) |
|
232 | 232 | { |
233 | 233 | $months_difference++; |
234 | 234 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | |
249 | 249 | protected function resolveCalculations() : void |
250 | 250 | { |
251 | - if(!isset($this->dateFrom)) |
|
251 | + if (!isset($this->dateFrom)) |
|
252 | 252 | { |
253 | 253 | throw new ConvertHelper_Exception( |
254 | 254 | 'No date from has been specified.', |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | } |
259 | 259 | |
260 | 260 | // no date to set? Assume we want to use today. |
261 | - if(!isset($this->dateTo)) |
|
261 | + if (!isset($this->dateTo)) |
|
262 | 262 | { |
263 | 263 | $this->dateTo = time(); |
264 | 264 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | |
338 | 338 | $difference = $this->dateTo - $this->dateFrom; |
339 | 339 | |
340 | - if($difference < 0) |
|
340 | + if ($difference < 0) |
|
341 | 341 | { |
342 | 342 | $difference = $difference * -1; |
343 | 343 | $this->future = true; |
@@ -26,39 +26,39 @@ discard block |
||
26 | 26 | const ERROR_NO_DATE_FROM_SET = 43401; |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @var int |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var int |
|
31 | + */ |
|
32 | 32 | protected $dateFrom; |
33 | 33 | |
34 | - /** |
|
35 | - * @var int |
|
36 | - */ |
|
34 | + /** |
|
35 | + * @var int |
|
36 | + */ |
|
37 | 37 | protected $dateTo; |
38 | 38 | |
39 | - /** |
|
40 | - * @var bool |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | 42 | protected $future = false; |
43 | 43 | |
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | 47 | protected $interval = ''; |
48 | 48 | |
49 | - /** |
|
50 | - * @var int |
|
51 | - */ |
|
49 | + /** |
|
50 | + * @var int |
|
51 | + */ |
|
52 | 52 | protected $difference = 0; |
53 | 53 | |
54 | - /** |
|
55 | - * @var int |
|
56 | - */ |
|
54 | + /** |
|
55 | + * @var int |
|
56 | + */ |
|
57 | 57 | protected $dateDiff = 0; |
58 | 58 | |
59 | - /** |
|
60 | - * @var array|NULL |
|
61 | - */ |
|
59 | + /** |
|
60 | + * @var array|NULL |
|
61 | + */ |
|
62 | 62 | protected static $texts = null; |
63 | 63 | |
64 | 64 | public function __construct() |
@@ -78,17 +78,17 @@ discard block |
||
78 | 78 | self::$texts = null; |
79 | 79 | } |
80 | 80 | |
81 | - /** |
|
82 | - * Sets the origin date to calculate from. |
|
83 | - * |
|
84 | - * NOTE: if this is further in the future than |
|
85 | - * the to: date, it will be considered as a |
|
86 | - * calculation for something to come, i.e. |
|
87 | - * "In two days". |
|
88 | - * |
|
89 | - * @param \DateTime $date |
|
90 | - * @return ConvertHelper_DurationConverter |
|
91 | - */ |
|
81 | + /** |
|
82 | + * Sets the origin date to calculate from. |
|
83 | + * |
|
84 | + * NOTE: if this is further in the future than |
|
85 | + * the to: date, it will be considered as a |
|
86 | + * calculation for something to come, i.e. |
|
87 | + * "In two days". |
|
88 | + * |
|
89 | + * @param \DateTime $date |
|
90 | + * @return ConvertHelper_DurationConverter |
|
91 | + */ |
|
92 | 92 | public function setDateFrom(\DateTime $date) : ConvertHelper_DurationConverter |
93 | 93 | { |
94 | 94 | $this->dateFrom = ConvertHelper::date2timestamp($date); |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | return $this; |
97 | 97 | } |
98 | 98 | |
99 | - /** |
|
100 | - * Sets the date to calculate to. Defaults to |
|
101 | - * the current time if not set. |
|
102 | - * |
|
103 | - * @param \DateTime $date |
|
104 | - * @return ConvertHelper_DurationConverter |
|
105 | - */ |
|
99 | + /** |
|
100 | + * Sets the date to calculate to. Defaults to |
|
101 | + * the current time if not set. |
|
102 | + * |
|
103 | + * @param \DateTime $date |
|
104 | + * @return ConvertHelper_DurationConverter |
|
105 | + */ |
|
106 | 106 | public function setDateTo(\DateTime $date) : ConvertHelper_DurationConverter |
107 | 107 | { |
108 | 108 | $this->dateTo = ConvertHelper::date2timestamp($date); |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | return $this; |
111 | 111 | } |
112 | 112 | |
113 | - /** |
|
114 | - * Converts the specified dates to a human readable string. |
|
115 | - * |
|
116 | - * @throws ConvertHelper_Exception |
|
117 | - * @return string |
|
118 | - * |
|
119 | - * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
120 | - */ |
|
113 | + /** |
|
114 | + * Converts the specified dates to a human readable string. |
|
115 | + * |
|
116 | + * @throws ConvertHelper_Exception |
|
117 | + * @return string |
|
118 | + * |
|
119 | + * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
120 | + */ |
|
121 | 121 | public function convert() : string |
122 | 122 | { |
123 | 123 | $this->initTexts(); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | public function __construct() |
38 | 38 | { |
39 | - if(class_exists('\AppLocalize\Localization')) { |
|
39 | + if (class_exists('\AppLocalize\Localization')) { |
|
40 | 40 | \AppLocalize\Localization::onLocaleChanged(array($this, 'handle_localeChanged')); |
41 | 41 | } |
42 | 42 | } |
@@ -69,17 +69,17 @@ discard block |
||
69 | 69 | $keep = $this->resolveTokens($interval); |
70 | 70 | |
71 | 71 | $parts = array(); |
72 | - foreach($keep as $token) |
|
72 | + foreach ($keep as $token) |
|
73 | 73 | { |
74 | 74 | $value = $interval->getToken($token); |
75 | - if($value === 0) { |
|
75 | + if ($value === 0) { |
|
76 | 76 | continue; |
77 | 77 | } |
78 | 78 | |
79 | 79 | $parts[] = $this->translateToken($token, $interval); |
80 | 80 | } |
81 | 81 | |
82 | - if(count($parts) == 1) { |
|
82 | + if (count($parts) == 1) { |
|
83 | 83 | return $parts[0]; |
84 | 84 | } |
85 | 85 | |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | $value = $interval->getToken($token); |
102 | 102 | |
103 | 103 | $suffix = 'p'; |
104 | - if($value == 1) { $suffix = 's'; } |
|
104 | + if ($value == 1) { $suffix = 's'; } |
|
105 | 105 | $token .= $suffix; |
106 | 106 | |
107 | - if(!isset(self::$texts[$token])) |
|
107 | + if (!isset(self::$texts[$token])) |
|
108 | 108 | { |
109 | 109 | throw new ConvertHelper_Exception( |
110 | 110 | 'Missing interval translation', |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | { |
135 | 135 | $offset = 0; |
136 | 136 | |
137 | - foreach($this->tokens as $token) |
|
137 | + foreach ($this->tokens as $token) |
|
138 | 138 | { |
139 | - if($interval->getToken($token) > 0) |
|
139 | + if ($interval->getToken($token) > 0) |
|
140 | 140 | { |
141 | 141 | return array_slice($this->tokens, $offset); |
142 | 142 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | protected function initTexts() : void |
154 | 154 | { |
155 | - if(isset(self::$texts)) { |
|
155 | + if (isset(self::$texts)) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 |
@@ -17,21 +17,20 @@ discard block |
||
17 | 17 | * @package Application Utils |
18 | 18 | * @subpackage ConvertHelper |
19 | 19 | * @author Sebastian Mordziol <[email protected]> |
20 | - |
|
21 | 20 | * @see ConvertHelper::interval2string() |
22 | 21 | */ |
23 | 22 | class ConvertHelper_IntervalConverter |
24 | 23 | { |
25 | 24 | const ERROR_MISSING_TRANSLATION = 43501; |
26 | 25 | |
27 | - /** |
|
28 | - * @var array|NULL |
|
29 | - */ |
|
26 | + /** |
|
27 | + * @var array|NULL |
|
28 | + */ |
|
30 | 29 | protected static $texts = null; |
31 | 30 | |
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
35 | 34 | protected $tokens = array('y', 'm', 'd', 'h', 'i', 's'); |
36 | 35 | |
37 | 36 | public function __construct() |
@@ -41,25 +40,25 @@ discard block |
||
41 | 40 | } |
42 | 41 | } |
43 | 42 | |
44 | - /** |
|
45 | - * Called whenever the application locale has changed, |
|
46 | - * to reset the internal translation cache. |
|
47 | - */ |
|
43 | + /** |
|
44 | + * Called whenever the application locale has changed, |
|
45 | + * to reset the internal translation cache. |
|
46 | + */ |
|
48 | 47 | public function handle_localeChanged() |
49 | 48 | { |
50 | 49 | self::$texts = null; |
51 | 50 | } |
52 | 51 | |
53 | - /** |
|
54 | - * Converts the specified interval to a human readable |
|
55 | - * string, e.g. "2 hours and 4 minutes". |
|
56 | - * |
|
57 | - * @param \DateInterval $interval |
|
58 | - * @return string |
|
59 | - * @throws ConvertHelper_Exception |
|
60 | - * |
|
61 | - * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
62 | - */ |
|
52 | + /** |
|
53 | + * Converts the specified interval to a human readable |
|
54 | + * string, e.g. "2 hours and 4 minutes". |
|
55 | + * |
|
56 | + * @param \DateInterval $interval |
|
57 | + * @return string |
|
58 | + * @throws ConvertHelper_Exception |
|
59 | + * |
|
60 | + * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
61 | + */ |
|
63 | 62 | public function toString(\DateInterval $interval) : string |
64 | 63 | { |
65 | 64 | $this->initTexts(); |
@@ -88,14 +87,14 @@ discard block |
||
88 | 87 | return t('%1$s and %2$s', implode(', ', $parts), $last); |
89 | 88 | } |
90 | 89 | |
91 | - /** |
|
92 | - * Translates the selected time token, e.g. "y" (for year). |
|
93 | - * |
|
94 | - * @param string $token |
|
95 | - * @param ConvertHelper_DateInterval $interval |
|
96 | - * @throws ConvertHelper_Exception |
|
97 | - * @return string |
|
98 | - */ |
|
90 | + /** |
|
91 | + * Translates the selected time token, e.g. "y" (for year). |
|
92 | + * |
|
93 | + * @param string $token |
|
94 | + * @param ConvertHelper_DateInterval $interval |
|
95 | + * @throws ConvertHelper_Exception |
|
96 | + * @return string |
|
97 | + */ |
|
99 | 98 | protected function translateToken(string $token, ConvertHelper_DateInterval $interval) : string |
100 | 99 | { |
101 | 100 | $value = $interval->getToken($token); |
@@ -123,13 +122,13 @@ discard block |
||
123 | 122 | ); |
124 | 123 | } |
125 | 124 | |
126 | - /** |
|
127 | - * Resolves all time tokens that need to be translated in |
|
128 | - * the subject interval, depending on its length. |
|
129 | - * |
|
130 | - * @param ConvertHelper_DateInterval $interval |
|
131 | - * @return array |
|
132 | - */ |
|
125 | + /** |
|
126 | + * Resolves all time tokens that need to be translated in |
|
127 | + * the subject interval, depending on its length. |
|
128 | + * |
|
129 | + * @param ConvertHelper_DateInterval $interval |
|
130 | + * @return array |
|
131 | + */ |
|
133 | 132 | protected function resolveTokens(ConvertHelper_DateInterval $interval) : array |
134 | 133 | { |
135 | 134 | $offset = 0; |
@@ -147,9 +146,9 @@ discard block |
||
147 | 146 | return array(); |
148 | 147 | } |
149 | 148 | |
150 | - /** |
|
151 | - * Initializes the translateable strings. |
|
152 | - */ |
|
149 | + /** |
|
150 | + * Initializes the translateable strings. |
|
151 | + */ |
|
153 | 152 | protected function initTexts() : void |
154 | 153 | { |
155 | 154 | if(isset(self::$texts)) { |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | 'WriteThreshold' => 100 |
37 | 37 | ); |
38 | 38 | |
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | 42 | protected $file; |
43 | 43 | |
44 | - /** |
|
45 | - * @var \ZipArchive |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var \ZipArchive |
|
46 | + */ |
|
47 | 47 | protected $zip; |
48 | 48 | |
49 | 49 | public function __construct(string $targetFile) |
@@ -51,35 +51,35 @@ discard block |
||
51 | 51 | $this->file = $targetFile; |
52 | 52 | } |
53 | 53 | |
54 | - /** |
|
55 | - * Sets an option, among the available options: |
|
56 | - * |
|
57 | - * <ul> |
|
58 | - * <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> |
|
59 | - * </ul> |
|
60 | - * |
|
61 | - * @param string $name |
|
62 | - * @param mixed $value |
|
63 | - * @return ZIPHelper |
|
64 | - */ |
|
54 | + /** |
|
55 | + * Sets an option, among the available options: |
|
56 | + * |
|
57 | + * <ul> |
|
58 | + * <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> |
|
59 | + * </ul> |
|
60 | + * |
|
61 | + * @param string $name |
|
62 | + * @param mixed $value |
|
63 | + * @return ZIPHelper |
|
64 | + */ |
|
65 | 65 | public function setOption(string $name, $value) : ZIPHelper |
66 | 66 | { |
67 | 67 | $this->options[$name] = $value; |
68 | 68 | return $this; |
69 | 69 | } |
70 | 70 | |
71 | - /** |
|
72 | - * Adds a file to the zip. By default, the file is stored |
|
73 | - * with the same name in the root of the zip. Use the optional |
|
74 | - * parameter to change the location in the zip. |
|
75 | - * |
|
76 | - * @param string $filePath |
|
77 | - * @param string|null $zipPath If no path is specified, file will be added with the same name in the ZIP's root. |
|
78 | - * @throws ZIPHelper_Exception |
|
79 | - * @return bool |
|
80 | - * |
|
81 | - * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
|
82 | - */ |
|
71 | + /** |
|
72 | + * Adds a file to the zip. By default, the file is stored |
|
73 | + * with the same name in the root of the zip. Use the optional |
|
74 | + * parameter to change the location in the zip. |
|
75 | + * |
|
76 | + * @param string $filePath |
|
77 | + * @param string|null $zipPath If no path is specified, file will be added with the same name in the ZIP's root. |
|
78 | + * @throws ZIPHelper_Exception |
|
79 | + * @return bool |
|
80 | + * |
|
81 | + * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
|
82 | + */ |
|
83 | 83 | public function addFile(string $filePath, ?string $zipPath=null) : bool |
84 | 84 | { |
85 | 85 | $this->open(); |
@@ -255,13 +255,13 @@ discard block |
||
255 | 255 | return $fileName; |
256 | 256 | } |
257 | 257 | |
258 | - /** |
|
259 | - * Like {@link ZIPHelper::download()}, but deletes the |
|
260 | - * file after sending it to the browser. |
|
261 | - * |
|
262 | - * @param string|NULL $fileName Override the ZIP's file name for the download |
|
263 | - * @see ZIPHelper::download() |
|
264 | - */ |
|
258 | + /** |
|
259 | + * Like {@link ZIPHelper::download()}, but deletes the |
|
260 | + * file after sending it to the browser. |
|
261 | + * |
|
262 | + * @param string|NULL $fileName Override the ZIP's file name for the download |
|
263 | + * @see ZIPHelper::download() |
|
264 | + */ |
|
265 | 265 | public function downloadAndDelete(?string $fileName=null) |
266 | 266 | { |
267 | 267 | $this->download($fileName); |
@@ -269,14 +269,14 @@ discard block |
||
269 | 269 | FileHelper::deleteFile($this->file); |
270 | 270 | } |
271 | 271 | |
272 | - /** |
|
273 | - * Extracts all files and folders from the zip to the |
|
274 | - * target folder. If no folder is specified, the files |
|
275 | - * are extracted into the same folder as the zip itself. |
|
276 | - * |
|
277 | - * @param string|NULL $outputFolder If no folder is specified, uses the target file's folder. |
|
278 | - * @return boolean |
|
279 | - */ |
|
272 | + /** |
|
273 | + * Extracts all files and folders from the zip to the |
|
274 | + * target folder. If no folder is specified, the files |
|
275 | + * are extracted into the same folder as the zip itself. |
|
276 | + * |
|
277 | + * @param string|NULL $outputFolder If no folder is specified, uses the target file's folder. |
|
278 | + * @return boolean |
|
279 | + */ |
|
280 | 280 | public function extractAll(?string $outputFolder=null) : bool |
281 | 281 | { |
282 | 282 | if(empty($outputFolder)) { |
@@ -289,9 +289,9 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | |
292 | - /** |
|
293 | - * @return \ZipArchive |
|
294 | - */ |
|
292 | + /** |
|
293 | + * @return \ZipArchive |
|
294 | + */ |
|
295 | 295 | public function getArchive() : \ZipArchive |
296 | 296 | { |
297 | 297 | $this->open(); |
@@ -299,14 +299,14 @@ discard block |
||
299 | 299 | return $this->zip; |
300 | 300 | } |
301 | 301 | |
302 | - /** |
|
303 | - * JSON encodes the specified data and adds the json as |
|
304 | - * a file in the ZIP archive. |
|
305 | - * |
|
306 | - * @param mixed $data |
|
307 | - * @param string $zipPath |
|
308 | - * @return boolean |
|
309 | - */ |
|
302 | + /** |
|
303 | + * JSON encodes the specified data and adds the json as |
|
304 | + * a file in the ZIP archive. |
|
305 | + * |
|
306 | + * @param mixed $data |
|
307 | + * @param string $zipPath |
|
308 | + * @return boolean |
|
309 | + */ |
|
310 | 310 | public function addJSON($data, $zipPath) |
311 | 311 | { |
312 | 312 | 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 |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
82 | 82 | */ |
83 | - public function addFile(string $filePath, ?string $zipPath=null) : bool |
|
83 | + public function addFile(string $filePath, ?string $zipPath = null) : bool |
|
84 | 84 | { |
85 | 85 | $this->open(); |
86 | 86 | |
@@ -126,16 +126,16 @@ discard block |
||
126 | 126 | |
127 | 127 | protected function open() |
128 | 128 | { |
129 | - if($this->open) { |
|
129 | + if ($this->open) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | - if(!isset($this->zip)) { |
|
133 | + if (!isset($this->zip)) { |
|
134 | 134 | $this->zip = new \ZipArchive(); |
135 | 135 | } |
136 | 136 | |
137 | 137 | $flag = null; |
138 | - if(!file_exists($this->file)) { |
|
138 | + if (!file_exists($this->file)) { |
|
139 | 139 | $flag = \ZipArchive::CREATE; |
140 | 140 | } |
141 | 141 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | { |
176 | 176 | $this->fileTracker++; |
177 | 177 | |
178 | - if($this->options['WriteThreshold'] < 1) { |
|
178 | + if ($this->options['WriteThreshold'] < 1) { |
|
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | protected function close() |
190 | 190 | { |
191 | - if(!$this->open) { |
|
191 | + if (!$this->open) { |
|
192 | 192 | return; |
193 | 193 | } |
194 | 194 | |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | throw new ZIPHelper_Exception( |
198 | 198 | 'Could not save ZIP file to disk', |
199 | 199 | sprintf( |
200 | - 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, ' . |
|
201 | - 'including adding files that do not exist on disk, trying to create an empty zip, ' . |
|
200 | + 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, '. |
|
201 | + 'including adding files that do not exist on disk, trying to create an empty zip, '. |
|
202 | 202 | 'or trying to save to a directory that does not exist.', |
203 | 203 | $this->file |
204 | 204 | ), |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | { |
214 | 214 | $this->open(); |
215 | 215 | |
216 | - if($this->countFiles() < 1) |
|
216 | + if ($this->countFiles() < 1) |
|
217 | 217 | { |
218 | 218 | throw new ZIPHelper_Exception( |
219 | 219 | 'No files in the zip file', |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | * @throws ZIPHelper_Exception |
238 | 238 | * @return string The file name that was sent (useful in case none was specified). |
239 | 239 | */ |
240 | - public function download(?string $fileName=null) : string |
|
240 | + public function download(?string $fileName = null) : string |
|
241 | 241 | { |
242 | 242 | $this->save(); |
243 | 243 | |
244 | - if(empty($fileName)) { |
|
244 | + if (empty($fileName)) { |
|
245 | 245 | $fileName = basename($this->file); |
246 | 246 | } |
247 | 247 | |
248 | 248 | header('Content-type: application/zip'); |
249 | - header('Content-Disposition: attachment; filename=' . $fileName); |
|
250 | - header('Content-length: ' . filesize($this->file)); |
|
249 | + header('Content-Disposition: attachment; filename='.$fileName); |
|
250 | + header('Content-length: '.filesize($this->file)); |
|
251 | 251 | header('Pragma: no-cache'); |
252 | 252 | header('Expires: 0'); |
253 | 253 | readfile($this->file); |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param string|NULL $fileName Override the ZIP's file name for the download |
263 | 263 | * @see ZIPHelper::download() |
264 | 264 | */ |
265 | - public function downloadAndDelete(?string $fileName=null) |
|
265 | + public function downloadAndDelete(?string $fileName = null) |
|
266 | 266 | { |
267 | 267 | $this->download($fileName); |
268 | 268 | |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | * @param string|NULL $outputFolder If no folder is specified, uses the target file's folder. |
278 | 278 | * @return boolean |
279 | 279 | */ |
280 | - public function extractAll(?string $outputFolder=null) : bool |
|
280 | + public function extractAll(?string $outputFolder = null) : bool |
|
281 | 281 | { |
282 | - if(empty($outputFolder)) { |
|
282 | + if (empty($outputFolder)) { |
|
283 | 283 | $outputFolder = dirname($this->file); |
284 | 284 | } |
285 | 285 |
@@ -4,37 +4,37 @@ discard block |
||
4 | 4 | |
5 | 5 | class SVNHelper_CommandResult |
6 | 6 | { |
7 | - /** |
|
8 | - * @var SVNHelper_Command |
|
9 | - */ |
|
7 | + /** |
|
8 | + * @var SVNHelper_Command |
|
9 | + */ |
|
10 | 10 | protected $command; |
11 | 11 | |
12 | - /** |
|
13 | - * @var string[] |
|
14 | - */ |
|
12 | + /** |
|
13 | + * @var string[] |
|
14 | + */ |
|
15 | 15 | protected $output; |
16 | 16 | |
17 | - /** |
|
18 | - * @var SVNHelper_CommandError[] |
|
19 | - */ |
|
17 | + /** |
|
18 | + * @var SVNHelper_CommandError[] |
|
19 | + */ |
|
20 | 20 | protected $errors = array(); |
21 | 21 | |
22 | - /** |
|
23 | - * @var SVNHelper_CommandError[] |
|
24 | - */ |
|
22 | + /** |
|
23 | + * @var SVNHelper_CommandError[] |
|
24 | + */ |
|
25 | 25 | protected $warnings = array(); |
26 | 26 | |
27 | - /** |
|
28 | - * The actual command that has been executed |
|
29 | - * @var string |
|
30 | - */ |
|
27 | + /** |
|
28 | + * The actual command that has been executed |
|
29 | + * @var string |
|
30 | + */ |
|
31 | 31 | protected $commandLine; |
32 | 32 | |
33 | - /** |
|
34 | - * @param SVNHelper_Command $command |
|
35 | - * @param string[] $output |
|
36 | - * @param SVNHelper_CommandError[] $errors |
|
37 | - */ |
|
33 | + /** |
|
34 | + * @param SVNHelper_Command $command |
|
35 | + * @param string[] $output |
|
36 | + * @param SVNHelper_CommandError[] $errors |
|
37 | + */ |
|
38 | 38 | public function __construct(SVNHelper_Command $command, $commandLine, $output, $errors) |
39 | 39 | { |
40 | 40 | $this->command = $command; |
@@ -86,12 +86,12 @@ discard block |
||
86 | 86 | return $this->command; |
87 | 87 | } |
88 | 88 | |
89 | - /** |
|
90 | - * Retrieves all error messages. |
|
91 | - * |
|
92 | - * @param bool $asString |
|
93 | - * @return string|string[] |
|
94 | - */ |
|
89 | + /** |
|
90 | + * Retrieves all error messages. |
|
91 | + * |
|
92 | + * @param bool $asString |
|
93 | + * @return string|string[] |
|
94 | + */ |
|
95 | 95 | public function getErrorMessages(bool $asString=false) |
96 | 96 | { |
97 | 97 | if($asString) { |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | $this->commandLine = $commandLine; |
42 | 42 | $this->output = $output; |
43 | 43 | |
44 | - foreach($errors as $error) { |
|
45 | - if($error->isError()) { |
|
44 | + foreach ($errors as $error) { |
|
45 | + if ($error->isError()) { |
|
46 | 46 | $this->errors[] = $error; |
47 | 47 | } else { |
48 | 48 | $this->warnings[] = $error; |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | |
63 | 63 | public function hasErrorCode($code) |
64 | 64 | { |
65 | - foreach($this->errors as $error) { |
|
66 | - if($error->getCode() == $code) { |
|
65 | + foreach ($this->errors as $error) { |
|
66 | + if ($error->getCode() == $code) { |
|
67 | 67 | return true; |
68 | 68 | } |
69 | 69 | } |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | * @param bool $asString |
93 | 93 | * @return string|string[] |
94 | 94 | */ |
95 | - public function getErrorMessages(bool $asString=false) |
|
95 | + public function getErrorMessages(bool $asString = false) |
|
96 | 96 | { |
97 | - if($asString) { |
|
97 | + if ($asString) { |
|
98 | 98 | $lines = array(); |
99 | - foreach($this->errors as $error) { |
|
99 | + foreach ($this->errors as $error) { |
|
100 | 100 | $lines[] = (string)$error; |
101 | 101 | } |
102 | 102 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | $messages = array(); |
107 | - foreach($this->errors as $error) { |
|
107 | + foreach ($this->errors as $error) { |
|
108 | 108 | $messages[] = (string)$error; |
109 | 109 | } |
110 | 110 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | |
124 | 124 | public function getLastLine() |
125 | 125 | { |
126 | - return $this->output[count($this->output)-1]; |
|
126 | + return $this->output[count($this->output) - 1]; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | public function getFirstLine() |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | |
139 | 139 | public function isConnectionFailed() |
140 | 140 | { |
141 | - foreach($this->errors as $error) { |
|
142 | - if($error->isConnectionFailed()) { |
|
141 | + foreach ($this->errors as $error) { |
|
142 | + if ($error->isConnectionFailed()) { |
|
143 | 143 | return true; |
144 | 144 | } |
145 | 145 | } |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | |
150 | 150 | public function hasConflicts() |
151 | 151 | { |
152 | - foreach($this->errors as $error) { |
|
153 | - if($error->isConflict()) { |
|
152 | + foreach ($this->errors as $error) { |
|
153 | + if ($error->isConflict()) { |
|
154 | 154 | return true; |
155 | 155 | } |
156 | 156 | } |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | |
161 | 161 | public function hasLocks() |
162 | 162 | { |
163 | - foreach($this->errors as $error) { |
|
164 | - if($error->isLock()) { |
|
163 | + foreach ($this->errors as $error) { |
|
164 | + if ($error->isLock()) { |
|
165 | 165 | return true; |
166 | 166 | } |
167 | 167 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * The converted string will be all lowercase. |
61 | 61 | * @return Transliteration |
62 | 62 | */ |
63 | - public function setLowercase(bool $lowercase=true) : Transliteration |
|
63 | + public function setLowercase(bool $lowercase = true) : Transliteration |
|
64 | 64 | { |
65 | 65 | $this->setOption('lowercase', $lowercase); |
66 | 66 | |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | |
98 | 98 | $result = implode('', $keep); |
99 | 99 | |
100 | - while (strstr($result, $space . $space)) { |
|
101 | - $result = str_replace($space . $space, $space, $result); |
|
100 | + while (strstr($result, $space.$space)) { |
|
101 | + $result = str_replace($space.$space, $space, $result); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $result = trim($result, $space); |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class ConvertHelper_ByteConverter |
25 | 25 | { |
26 | - /** |
|
27 | - * @var int |
|
28 | - */ |
|
26 | + /** |
|
27 | + * @var int |
|
28 | + */ |
|
29 | 29 | protected $bytes; |
30 | 30 | |
31 | 31 | public function __construct(int $bytes) |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
42 | - /** |
|
43 | - * Detects the size matching the byte value for the specified base. |
|
44 | - * |
|
45 | - * @param int $base |
|
46 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
47 | - */ |
|
42 | + /** |
|
43 | + * Detects the size matching the byte value for the specified base. |
|
44 | + * |
|
45 | + * @param int $base |
|
46 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
47 | + */ |
|
48 | 48 | protected function detectSize(int $base) : ConvertHelper_StorageSizeEnum_Size |
49 | 49 | { |
50 | 50 | $sizes = $this->getSizesSorted($base); |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | return ConvertHelper_StorageSizeEnum::getSizeByName('b'); |
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * Retrieves all storage sizes for the specified base, |
|
75 | - * sorted from smallest byte size to highest. |
|
76 | - * |
|
77 | - * @param int $base |
|
78 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
79 | - */ |
|
73 | + /** |
|
74 | + * Retrieves all storage sizes for the specified base, |
|
75 | + * sorted from smallest byte size to highest. |
|
76 | + * |
|
77 | + * @param int $base |
|
78 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
79 | + */ |
|
80 | 80 | protected function getSizesSorted(int $base) |
81 | 81 | { |
82 | 82 | $sizes = ConvertHelper_StorageSizeEnum::getSizesByBase($base); |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | return $sizes; |
90 | 90 | } |
91 | 91 | |
92 | - /** |
|
93 | - * Converts the byte value to a human readable string, e.g. "5 KB", "140 MB". |
|
94 | - * |
|
95 | - * @param int $precision The amount of decimals (rounded up) |
|
96 | - * @param int $base The base to calculate bytes with. |
|
97 | - * @return string |
|
98 | - * |
|
99 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
100 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
101 | - */ |
|
92 | + /** |
|
93 | + * Converts the byte value to a human readable string, e.g. "5 KB", "140 MB". |
|
94 | + * |
|
95 | + * @param int $precision The amount of decimals (rounded up) |
|
96 | + * @param int $base The base to calculate bytes with. |
|
97 | + * @return string |
|
98 | + * |
|
99 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
100 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
101 | + */ |
|
102 | 102 | public function toString(int $precision, int $base=ConvertHelper_StorageSizeEnum::BASE_10) : string |
103 | 103 | { |
104 | 104 | $size = $this->detectSize($base); |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | return round($this->bytes / $size->getBytes(), $precision) . ' ' . $size->getSuffix(); |
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * Converts the byte value to the amount of the corresponding units (KB, MB...). |
|
111 | - * |
|
112 | - * @param int $precision The amount of decimals (rounded up) |
|
113 | - * @param string $sizeName The lowercase storage size name (e.g. "kb", "kib") |
|
114 | - * @return float |
|
115 | - */ |
|
109 | + /** |
|
110 | + * Converts the byte value to the amount of the corresponding units (KB, MB...). |
|
111 | + * |
|
112 | + * @param int $precision The amount of decimals (rounded up) |
|
113 | + * @param string $sizeName The lowercase storage size name (e.g. "kb", "kib") |
|
114 | + * @return float |
|
115 | + */ |
|
116 | 116 | public function toNumber(int $precision, string $sizeName) : float |
117 | 117 | { |
118 | 118 | $size = ConvertHelper_StorageSizeEnum::getSizeByName($sizeName); |
@@ -120,56 +120,56 @@ discard block |
||
120 | 120 | return round($this->bytes / $size->getBytes(), $precision); |
121 | 121 | } |
122 | 122 | |
123 | - /** |
|
124 | - * Converts the bytes to Kilobytes. |
|
125 | - * |
|
126 | - * @param int $precision Amount of decimals (rounded up) |
|
127 | - * @return float |
|
128 | - */ |
|
123 | + /** |
|
124 | + * Converts the bytes to Kilobytes. |
|
125 | + * |
|
126 | + * @param int $precision Amount of decimals (rounded up) |
|
127 | + * @return float |
|
128 | + */ |
|
129 | 129 | public function toKilobytes(int $precision=1) : float |
130 | 130 | { |
131 | 131 | return $this->toNumber($precision, 'kb'); |
132 | 132 | } |
133 | 133 | |
134 | - /** |
|
135 | - * Converts the bytes to Megabytes. |
|
136 | - * |
|
137 | - * @param int $precision Amount of decimals (rounded up) |
|
138 | - * @return float |
|
139 | - */ |
|
134 | + /** |
|
135 | + * Converts the bytes to Megabytes. |
|
136 | + * |
|
137 | + * @param int $precision Amount of decimals (rounded up) |
|
138 | + * @return float |
|
139 | + */ |
|
140 | 140 | public function toMegabytes(int $precision=1) : float |
141 | 141 | { |
142 | 142 | return $this->toNumber($precision, 'mb'); |
143 | 143 | } |
144 | 144 | |
145 | - /** |
|
146 | - * Converts the bytes to Gigabytes. |
|
147 | - * |
|
148 | - * @param int $precision Amount of decimals (rounded up) |
|
149 | - * @return float |
|
150 | - */ |
|
145 | + /** |
|
146 | + * Converts the bytes to Gigabytes. |
|
147 | + * |
|
148 | + * @param int $precision Amount of decimals (rounded up) |
|
149 | + * @return float |
|
150 | + */ |
|
151 | 151 | public function toGigabytes(int $precision=1) : float |
152 | 152 | { |
153 | 153 | return $this->toNumber($precision, 'gb'); |
154 | 154 | } |
155 | 155 | |
156 | - /** |
|
157 | - * Converts the bytes to Terabytes. |
|
158 | - * |
|
159 | - * @param int $precision Amount of decimals (rounded up) |
|
160 | - * @return float |
|
161 | - */ |
|
156 | + /** |
|
157 | + * Converts the bytes to Terabytes. |
|
158 | + * |
|
159 | + * @param int $precision Amount of decimals (rounded up) |
|
160 | + * @return float |
|
161 | + */ |
|
162 | 162 | public function toTerabytes(int $precision=1) : float |
163 | 163 | { |
164 | 164 | return $this->toNumber($precision, 'tb'); |
165 | 165 | } |
166 | 166 | |
167 | - /** |
|
168 | - * Converts the bytes to Petabytes. |
|
169 | - * |
|
170 | - * @param int $precision Amount of decimals (rounded up) |
|
171 | - * @return float |
|
172 | - */ |
|
167 | + /** |
|
168 | + * Converts the bytes to Petabytes. |
|
169 | + * |
|
170 | + * @param int $precision Amount of decimals (rounded up) |
|
171 | + * @return float |
|
172 | + */ |
|
173 | 173 | public function toPetabytes(int $precision=1) : float |
174 | 174 | { |
175 | 175 | return $this->toNumber($precision, 'pb'); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $this->bytes = $bytes; |
34 | 34 | |
35 | 35 | // correct negative values |
36 | - if($this->bytes < 0) |
|
36 | + if ($this->bytes < 0) |
|
37 | 37 | { |
38 | 38 | $this->bytes = 0; |
39 | 39 | } |
@@ -49,19 +49,19 @@ discard block |
||
49 | 49 | { |
50 | 50 | $sizes = $this->getSizesSorted($base); |
51 | 51 | |
52 | - if($this->bytes >= $sizes[0]->getBytes()) |
|
52 | + if ($this->bytes >= $sizes[0]->getBytes()) |
|
53 | 53 | { |
54 | 54 | $total = count($sizes); |
55 | 55 | |
56 | - for($i=0; $i < $total; $i++) |
|
56 | + for ($i = 0; $i < $total; $i++) |
|
57 | 57 | { |
58 | 58 | $size = $sizes[$i]; |
59 | 59 | |
60 | - if(!isset($sizes[($i+1)])) { |
|
60 | + if (!isset($sizes[($i + 1)])) { |
|
61 | 61 | return $size; |
62 | 62 | } |
63 | 63 | |
64 | - if($this->bytes >= $size->getBytes() && $this->bytes < $sizes[($i+1)]->getBytes()) { |
|
64 | + if ($this->bytes >= $size->getBytes() && $this->bytes < $sizes[($i + 1)]->getBytes()) { |
|
65 | 65 | return $size; |
66 | 66 | } |
67 | 67 | } |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | * @see ConvertHelper_StorageSizeEnum::BASE_10 |
100 | 100 | * @see ConvertHelper_StorageSizeEnum::BASE_2 |
101 | 101 | */ |
102 | - public function toString(int $precision, int $base=ConvertHelper_StorageSizeEnum::BASE_10) : string |
|
102 | + public function toString(int $precision, int $base = ConvertHelper_StorageSizeEnum::BASE_10) : string |
|
103 | 103 | { |
104 | 104 | $size = $this->detectSize($base); |
105 | 105 | |
106 | - return round($this->bytes / $size->getBytes(), $precision) . ' ' . $size->getSuffix(); |
|
106 | + return round($this->bytes / $size->getBytes(), $precision).' '.$size->getSuffix(); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param int $precision Amount of decimals (rounded up) |
127 | 127 | * @return float |
128 | 128 | */ |
129 | - public function toKilobytes(int $precision=1) : float |
|
129 | + public function toKilobytes(int $precision = 1) : float |
|
130 | 130 | { |
131 | 131 | return $this->toNumber($precision, 'kb'); |
132 | 132 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param int $precision Amount of decimals (rounded up) |
138 | 138 | * @return float |
139 | 139 | */ |
140 | - public function toMegabytes(int $precision=1) : float |
|
140 | + public function toMegabytes(int $precision = 1) : float |
|
141 | 141 | { |
142 | 142 | return $this->toNumber($precision, 'mb'); |
143 | 143 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @param int $precision Amount of decimals (rounded up) |
149 | 149 | * @return float |
150 | 150 | */ |
151 | - public function toGigabytes(int $precision=1) : float |
|
151 | + public function toGigabytes(int $precision = 1) : float |
|
152 | 152 | { |
153 | 153 | return $this->toNumber($precision, 'gb'); |
154 | 154 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param int $precision Amount of decimals (rounded up) |
160 | 160 | * @return float |
161 | 161 | */ |
162 | - public function toTerabytes(int $precision=1) : float |
|
162 | + public function toTerabytes(int $precision = 1) : float |
|
163 | 163 | { |
164 | 164 | return $this->toNumber($precision, 'tb'); |
165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @param int $precision Amount of decimals (rounded up) |
171 | 171 | * @return float |
172 | 172 | */ |
173 | - public function toPetabytes(int $precision=1) : float |
|
173 | + public function toPetabytes(int $precision = 1) : float |
|
174 | 174 | { |
175 | 175 | return $this->toNumber($precision, 'pb'); |
176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param int $precision Amount of decimals (rounded up) |
182 | 182 | * @return float |
183 | 183 | */ |
184 | - public function toKibibytes(int $precision=1) : float |
|
184 | + public function toKibibytes(int $precision = 1) : float |
|
185 | 185 | { |
186 | 186 | return $this->toNumber($precision, 'kib'); |
187 | 187 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @param int $precision Amount of decimals (rounded up) |
193 | 193 | * @return float |
194 | 194 | */ |
195 | - public function toMebibytes(int $precision=1) : float |
|
195 | + public function toMebibytes(int $precision = 1) : float |
|
196 | 196 | { |
197 | 197 | return $this->toNumber($precision, 'mib'); |
198 | 198 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @param int $precision Amount of decimals (rounded up) |
204 | 204 | * @return float |
205 | 205 | */ |
206 | - public function toGibibytes(int $precision=1) : float |
|
206 | + public function toGibibytes(int $precision = 1) : float |
|
207 | 207 | { |
208 | 208 | return $this->toNumber($precision, 'gib'); |
209 | 209 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param int $precision Amount of decimals (rounded up) |
215 | 215 | * @return float |
216 | 216 | */ |
217 | - public function toTebibytes(int $precision=1) : float |
|
217 | + public function toTebibytes(int $precision = 1) : float |
|
218 | 218 | { |
219 | 219 | return $this->toNumber($precision, 'tib'); |
220 | 220 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param int $precision Amount of decimals (rounded up) |
226 | 226 | * @return float |
227 | 227 | */ |
228 | - public function toPebibytes(int $precision=1) : float |
|
228 | + public function toPebibytes(int $precision = 1) : float |
|
229 | 229 | { |
230 | 230 | return $this->toNumber($precision, 'pib'); |
231 | 231 | } |
@@ -25,34 +25,34 @@ |
||
25 | 25 | */ |
26 | 26 | class ConvertHelper_StorageSizeEnum_Size |
27 | 27 | { |
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | 31 | protected $name; |
32 | 32 | |
33 | - /** |
|
34 | - * @var int |
|
35 | - */ |
|
33 | + /** |
|
34 | + * @var int |
|
35 | + */ |
|
36 | 36 | protected $base; |
37 | 37 | |
38 | - /** |
|
39 | - * @var int |
|
40 | - */ |
|
38 | + /** |
|
39 | + * @var int |
|
40 | + */ |
|
41 | 41 | protected $exponent; |
42 | 42 | |
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | 46 | protected $singular; |
47 | 47 | |
48 | - /** |
|
49 | - * @var string |
|
50 | - */ |
|
48 | + /** |
|
49 | + * @var string |
|
50 | + */ |
|
51 | 51 | protected $plural; |
52 | 52 | |
53 | - /** |
|
54 | - * @var string |
|
55 | - */ |
|
53 | + /** |
|
54 | + * @var string |
|
55 | + */ |
|
56 | 56 | protected $suffix; |
57 | 57 | |
58 | 58 | public function __construct(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | |
32 | 32 | const VALIDATION_ERROR_NEGATIVE_VALUE = 43803; |
33 | 33 | |
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | 37 | protected $sizeString; |
38 | 38 | |
39 | 39 | /** |
@@ -41,41 +41,41 @@ discard block |
||
41 | 41 | */ |
42 | 42 | protected $sizeDefinition; |
43 | 43 | |
44 | - /** |
|
45 | - * @var integer |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var integer |
|
46 | + */ |
|
47 | 47 | protected $bytes = 0; |
48 | 48 | |
49 | - /** |
|
50 | - * @var bool |
|
51 | - */ |
|
49 | + /** |
|
50 | + * @var bool |
|
51 | + */ |
|
52 | 52 | protected $valid = true; |
53 | 53 | |
54 | - /** |
|
55 | - * @var string |
|
56 | - */ |
|
54 | + /** |
|
55 | + * @var string |
|
56 | + */ |
|
57 | 57 | protected $units = null; |
58 | 58 | |
59 | - /** |
|
60 | - * @var string |
|
61 | - */ |
|
59 | + /** |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | protected $number = ''; |
63 | 63 | |
64 | - /** |
|
65 | - * @var string |
|
66 | - */ |
|
64 | + /** |
|
65 | + * @var string |
|
66 | + */ |
|
67 | 67 | protected $errorMessage = ''; |
68 | 68 | |
69 | - /** |
|
70 | - * @var int |
|
71 | - */ |
|
69 | + /** |
|
70 | + * @var int |
|
71 | + */ |
|
72 | 72 | protected $errorCode = 0; |
73 | 73 | |
74 | - /** |
|
75 | - * Create a new instance for the specified size string. |
|
76 | - * |
|
77 | - * @param string $sizeString A size notation in the format "50 MB", or a number of bytes without units. Spaces are ignored, so "50MB" = "50 MB" = " 50 MB ". Floating point values are accepted, both with dot and comma notation ("50.5" = "50,5"). To use Base 2 values, ose appropriate units, e.g. "50 MiB", "1.5 GiB". The units are case insensitive, so "50 MB" = "50 mb". |
|
78 | - */ |
|
74 | + /** |
|
75 | + * Create a new instance for the specified size string. |
|
76 | + * |
|
77 | + * @param string $sizeString A size notation in the format "50 MB", or a number of bytes without units. Spaces are ignored, so "50MB" = "50 MB" = " 50 MB ". Floating point values are accepted, both with dot and comma notation ("50.5" = "50,5"). To use Base 2 values, ose appropriate units, e.g. "50 MiB", "1.5 GiB". The units are case insensitive, so "50 MB" = "50 mb". |
|
78 | + */ |
|
79 | 79 | public function __construct(string $sizeString) |
80 | 80 | { |
81 | 81 | $this->sizeString = $this->cleanString($sizeString); |
@@ -83,31 +83,31 @@ discard block |
||
83 | 83 | $this->convert(); |
84 | 84 | } |
85 | 85 | |
86 | - /** |
|
87 | - * Gets the amount of bytes contained in the size notation. |
|
88 | - * @return int |
|
89 | - */ |
|
86 | + /** |
|
87 | + * Gets the amount of bytes contained in the size notation. |
|
88 | + * @return int |
|
89 | + */ |
|
90 | 90 | public function toBytes() : int |
91 | 91 | { |
92 | 92 | return $this->bytes; |
93 | 93 | } |
94 | 94 | |
95 | - /** |
|
96 | - * Converts the size notation to a human readable string, e.g. "50 MB". |
|
97 | - * |
|
98 | - * @param int $precision |
|
99 | - * @return string |
|
100 | - * @see ConvertHelper::bytes2readable() |
|
101 | - */ |
|
95 | + /** |
|
96 | + * Converts the size notation to a human readable string, e.g. "50 MB". |
|
97 | + * |
|
98 | + * @param int $precision |
|
99 | + * @return string |
|
100 | + * @see ConvertHelper::bytes2readable() |
|
101 | + */ |
|
102 | 102 | public function toString(int $precision=1) : string |
103 | 103 | { |
104 | 104 | return ConvertHelper::bytes2readable($this->bytes, $precision, $this->getBase()); |
105 | 105 | } |
106 | 106 | |
107 | - /** |
|
108 | - * Retrieves the detected number's base. |
|
109 | - * @return int The base number (1000 for Base 10, or 1024 for Base 2), or 0 if it is not valid. |
|
110 | - */ |
|
107 | + /** |
|
108 | + * Retrieves the detected number's base. |
|
109 | + * @return int The base number (1000 for Base 10, or 1024 for Base 2), or 0 if it is not valid. |
|
110 | + */ |
|
111 | 111 | public function getBase() : int |
112 | 112 | { |
113 | 113 | if($this->isValid()) { |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | return 0; |
118 | 118 | } |
119 | 119 | |
120 | - /** |
|
121 | - * Retrieves the detected storage size instance, if |
|
122 | - * the size string is valid. |
|
123 | - * |
|
124 | - * @return ConvertHelper_StorageSizeEnum_Size|NULL |
|
125 | - * @see ConvertHelper_StorageSizeEnum_Size |
|
126 | - */ |
|
120 | + /** |
|
121 | + * Retrieves the detected storage size instance, if |
|
122 | + * the size string is valid. |
|
123 | + * |
|
124 | + * @return ConvertHelper_StorageSizeEnum_Size|NULL |
|
125 | + * @see ConvertHelper_StorageSizeEnum_Size |
|
126 | + */ |
|
127 | 127 | public function getSizeDefinition() : ?ConvertHelper_StorageSizeEnum_Size |
128 | 128 | { |
129 | 129 | if($this->isValid()) { |
@@ -133,27 +133,27 @@ discard block |
||
133 | 133 | return null; |
134 | 134 | } |
135 | 135 | |
136 | - /** |
|
137 | - * Checks whether the size notation was valid and could be parsed |
|
138 | - * into a meaningful byte value. If this returns `false`, it is |
|
139 | - * possible to use the `getErrorXXX` methods to retrieve information |
|
140 | - * on what went wrong. |
|
141 | - * |
|
142 | - * @return bool |
|
143 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
144 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
145 | - */ |
|
136 | + /** |
|
137 | + * Checks whether the size notation was valid and could be parsed |
|
138 | + * into a meaningful byte value. If this returns `false`, it is |
|
139 | + * possible to use the `getErrorXXX` methods to retrieve information |
|
140 | + * on what went wrong. |
|
141 | + * |
|
142 | + * @return bool |
|
143 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
144 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
145 | + */ |
|
146 | 146 | public function isValid() : bool |
147 | 147 | { |
148 | 148 | return $this->valid; |
149 | 149 | } |
150 | 150 | |
151 | - /** |
|
152 | - * Retrieves the error message if the size notation validation failed. |
|
153 | - * |
|
154 | - * @return string |
|
155 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
156 | - */ |
|
151 | + /** |
|
152 | + * Retrieves the error message if the size notation validation failed. |
|
153 | + * |
|
154 | + * @return string |
|
155 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
156 | + */ |
|
157 | 157 | public function getErrorMessage() : string |
158 | 158 | { |
159 | 159 | return $this->errorMessage; |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | ); |
201 | 201 | } |
202 | 202 | |
203 | - /** |
|
204 | - * Detects the units and the number in the size notation string. |
|
205 | - * Populates the `units` and `number` properties. |
|
206 | - * |
|
207 | - * @return bool Whether the string could be parsed successfully. |
|
208 | - */ |
|
203 | + /** |
|
204 | + * Detects the units and the number in the size notation string. |
|
205 | + * Populates the `units` and `number` properties. |
|
206 | + * |
|
207 | + * @return bool Whether the string could be parsed successfully. |
|
208 | + */ |
|
209 | 209 | protected function detectParts() : bool |
210 | 210 | { |
211 | 211 | $units = ConvertHelper_StorageSizeEnum::getSizeNames(); |
@@ -241,16 +241,16 @@ discard block |
||
241 | 241 | return true; |
242 | 242 | } |
243 | 243 | |
244 | - /** |
|
245 | - * If the validation fails, this is used to store the reason for retrieval later. |
|
246 | - * |
|
247 | - * @param string $message |
|
248 | - * @param int $code |
|
249 | - * |
|
250 | - * @see ConvertHelper_SizeNotation::isValid() |
|
251 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
252 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
253 | - */ |
|
244 | + /** |
|
245 | + * If the validation fails, this is used to store the reason for retrieval later. |
|
246 | + * |
|
247 | + * @param string $message |
|
248 | + * @param int $code |
|
249 | + * |
|
250 | + * @see ConvertHelper_SizeNotation::isValid() |
|
251 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
252 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
253 | + */ |
|
254 | 254 | protected function setError(string $message, int $code) : void |
255 | 255 | { |
256 | 256 | $this->valid = false; |
@@ -258,12 +258,12 @@ discard block |
||
258 | 258 | $this->errorCode = $code; |
259 | 259 | } |
260 | 260 | |
261 | - /** |
|
262 | - * Retrieves the error code, if the size notation validation failed. |
|
263 | - * |
|
264 | - * @return int |
|
265 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
266 | - */ |
|
261 | + /** |
|
262 | + * Retrieves the error code, if the size notation validation failed. |
|
263 | + * |
|
264 | + * @return int |
|
265 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
266 | + */ |
|
267 | 267 | public function getErrorCode() : int |
268 | 268 | { |
269 | 269 | return $this->errorCode; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @return string |
100 | 100 | * @see ConvertHelper::bytes2readable() |
101 | 101 | */ |
102 | - public function toString(int $precision=1) : string |
|
102 | + public function toString(int $precision = 1) : string |
|
103 | 103 | { |
104 | 104 | return ConvertHelper::bytes2readable($this->bytes, $precision, $this->getBase()); |
105 | 105 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function getBase() : int |
112 | 112 | { |
113 | - if($this->isValid()) { |
|
113 | + if ($this->isValid()) { |
|
114 | 114 | return $this->sizeDefinition->getBase(); |
115 | 115 | } |
116 | 116 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function getSizeDefinition() : ?ConvertHelper_StorageSizeEnum_Size |
128 | 128 | { |
129 | - if($this->isValid()) { |
|
129 | + if ($this->isValid()) { |
|
130 | 130 | return $this->sizeDefinition; |
131 | 131 | } |
132 | 132 | |
@@ -175,18 +175,18 @@ discard block |
||
175 | 175 | |
176 | 176 | protected function parseSize() : void |
177 | 177 | { |
178 | - if(!$this->detectParts()) { |
|
178 | + if (!$this->detectParts()) { |
|
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
182 | 182 | // we detected units in the string: all good. |
183 | - if($this->units !== null) |
|
183 | + if ($this->units !== null) |
|
184 | 184 | { |
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | 188 | // just a numeric value: we assume this means we're dealing with bytes. |
189 | - if(is_numeric($this->number)) |
|
189 | + if (is_numeric($this->number)) |
|
190 | 190 | { |
191 | 191 | $this->units = 'b'; |
192 | 192 | return; |
@@ -212,12 +212,12 @@ discard block |
||
212 | 212 | |
213 | 213 | $number = $this->sizeString; |
214 | 214 | |
215 | - foreach($units as $unit) |
|
215 | + foreach ($units as $unit) |
|
216 | 216 | { |
217 | - if(stristr($number, $unit)) |
|
217 | + if (stristr($number, $unit)) |
|
218 | 218 | { |
219 | 219 | // there are more than 1 unit defined in the string |
220 | - if($this->units !== null) |
|
220 | + if ($this->units !== null) |
|
221 | 221 | { |
222 | 222 | $this->setError( |
223 | 223 | t( |
@@ -273,14 +273,14 @@ discard block |
||
273 | 273 | { |
274 | 274 | $this->parseSize(); |
275 | 275 | |
276 | - if(!$this->valid) { |
|
276 | + if (!$this->valid) { |
|
277 | 277 | return; |
278 | 278 | } |
279 | 279 | |
280 | 280 | $int = intval($this->number); |
281 | 281 | |
282 | 282 | // negative values |
283 | - if($int < 0) |
|
283 | + if ($int < 0) |
|
284 | 284 | { |
285 | 285 | $this->setError( |
286 | 286 | t('Negative values cannot be used as size.'), |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | */ |
40 | 40 | protected static $instance; |
41 | 41 | |
42 | - /** |
|
43 | - * @var string |
|
44 | - */ |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + */ |
|
45 | 45 | protected $baseURL = ''; |
46 | 46 | |
47 | 47 | public function __construct() |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | $this->init(); |
52 | 52 | } |
53 | 53 | |
54 | - /** |
|
55 | - * Can be extended in a subclass, to avoid |
|
56 | - * redefining the constructor. |
|
57 | - */ |
|
54 | + /** |
|
55 | + * Can be extended in a subclass, to avoid |
|
56 | + * redefining the constructor. |
|
57 | + */ |
|
58 | 58 | protected function init() |
59 | 59 | { |
60 | 60 | |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | return $this->buildURL($params, $dispatcher); |
125 | 125 | } |
126 | 126 | |
127 | - /** |
|
128 | - * Retrieves the name of the current dispatcher script / page. |
|
129 | - * This is made to be extended and implemented in a subclass. |
|
130 | - * |
|
131 | - * @return string |
|
132 | - */ |
|
127 | + /** |
|
128 | + * Retrieves the name of the current dispatcher script / page. |
|
129 | + * This is made to be extended and implemented in a subclass. |
|
130 | + * |
|
131 | + * @return string |
|
132 | + */ |
|
133 | 133 | public function getDispatcher() : string |
134 | 134 | { |
135 | 135 | return ''; |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | return $url; |
199 | 199 | } |
200 | 200 | |
201 | - /** |
|
202 | - * Retrieves the base URL of the application. |
|
203 | - * @return string |
|
204 | - */ |
|
201 | + /** |
|
202 | + * Retrieves the base URL of the application. |
|
203 | + * @return string |
|
204 | + */ |
|
205 | 205 | public function getBaseURL() : string |
206 | 206 | { |
207 | 207 | return $this->baseURL; |
@@ -231,13 +231,13 @@ discard block |
||
231 | 231 | return $this->knownParams[$name]; |
232 | 232 | } |
233 | 233 | |
234 | - /** |
|
235 | - * Retrieves a previously registered parameter instance. |
|
236 | - * |
|
237 | - * @param string $name |
|
238 | - * @throws Request_Exception |
|
239 | - * @return Request_Param |
|
240 | - */ |
|
234 | + /** |
|
235 | + * Retrieves a previously registered parameter instance. |
|
236 | + * |
|
237 | + * @param string $name |
|
238 | + * @throws Request_Exception |
|
239 | + * @return Request_Param |
|
240 | + */ |
|
241 | 241 | public function getRegisteredParam(string $name) : Request_Param |
242 | 242 | { |
243 | 243 | if(isset($this->knownParams[$name])) { |
@@ -254,48 +254,48 @@ discard block |
||
254 | 254 | ); |
255 | 255 | } |
256 | 256 | |
257 | - /** |
|
258 | - * Checks whether a parameter with the specified name |
|
259 | - * has been registered. |
|
260 | - * |
|
261 | - * @param string $name |
|
262 | - * @return bool |
|
263 | - */ |
|
257 | + /** |
|
258 | + * Checks whether a parameter with the specified name |
|
259 | + * has been registered. |
|
260 | + * |
|
261 | + * @param string $name |
|
262 | + * @return bool |
|
263 | + */ |
|
264 | 264 | public function hasRegisteredParam(string $name) : bool |
265 | 265 | { |
266 | 266 | return isset($this->knownParams[$name]); |
267 | 267 | } |
268 | 268 | |
269 | - /** |
|
270 | - * Retrieves an indexed array with accept mime types |
|
271 | - * that the client sent, in the order of preference |
|
272 | - * the client specified. |
|
273 | - * |
|
274 | - * Example: |
|
275 | - * |
|
276 | - * array( |
|
277 | - * 'text/html', |
|
278 | - * 'application/xhtml+xml', |
|
279 | - * 'image/webp' |
|
280 | - * ... |
|
281 | - * ) |
|
282 | - * |
|
283 | - * @return array |
|
284 | - * @see Request::parseAcceptHeaders() |
|
285 | - */ |
|
269 | + /** |
|
270 | + * Retrieves an indexed array with accept mime types |
|
271 | + * that the client sent, in the order of preference |
|
272 | + * the client specified. |
|
273 | + * |
|
274 | + * Example: |
|
275 | + * |
|
276 | + * array( |
|
277 | + * 'text/html', |
|
278 | + * 'application/xhtml+xml', |
|
279 | + * 'image/webp' |
|
280 | + * ... |
|
281 | + * ) |
|
282 | + * |
|
283 | + * @return array |
|
284 | + * @see Request::parseAcceptHeaders() |
|
285 | + */ |
|
286 | 286 | public static function getAcceptHeaders() : array |
287 | 287 | { |
288 | 288 | return self::parseAcceptHeaders()->getMimeStrings(); |
289 | 289 | } |
290 | 290 | |
291 | - /** |
|
292 | - * Returns an instance of the accept headers parser, |
|
293 | - * to access information on the browser's accepted |
|
294 | - * mime types. |
|
295 | - * |
|
296 | - * @return Request_AcceptHeaders |
|
297 | - * @see Request::getAcceptHeaders() |
|
298 | - */ |
|
291 | + /** |
|
292 | + * Returns an instance of the accept headers parser, |
|
293 | + * to access information on the browser's accepted |
|
294 | + * mime types. |
|
295 | + * |
|
296 | + * @return Request_AcceptHeaders |
|
297 | + * @see Request::getAcceptHeaders() |
|
298 | + */ |
|
299 | 299 | public static function parseAcceptHeaders() : Request_AcceptHeaders |
300 | 300 | { |
301 | 301 | static $accept; |
@@ -343,14 +343,14 @@ discard block |
||
343 | 343 | return false; |
344 | 344 | } |
345 | 345 | |
346 | - /** |
|
347 | - * Removes a single parameter from the request. |
|
348 | - * If the parameter has been registered, also |
|
349 | - * removes the registration info. |
|
350 | - * |
|
351 | - * @param string $name |
|
352 | - * @return Request |
|
353 | - */ |
|
346 | + /** |
|
347 | + * Removes a single parameter from the request. |
|
348 | + * If the parameter has been registered, also |
|
349 | + * removes the registration info. |
|
350 | + * |
|
351 | + * @param string $name |
|
352 | + * @return Request |
|
353 | + */ |
|
354 | 354 | public function removeParam(string $name) : Request |
355 | 355 | { |
356 | 356 | if(isset($_REQUEST[$name])) { |
@@ -364,12 +364,12 @@ discard block |
||
364 | 364 | return $this; |
365 | 365 | } |
366 | 366 | |
367 | - /** |
|
368 | - * Removes several parameters from the request. |
|
369 | - * |
|
370 | - * @param string[] $names |
|
371 | - * @return Request |
|
372 | - */ |
|
367 | + /** |
|
368 | + * Removes several parameters from the request. |
|
369 | + * |
|
370 | + * @param string[] $names |
|
371 | + * @return Request |
|
372 | + */ |
|
373 | 373 | public function removeParams(array $names) : Request |
374 | 374 | { |
375 | 375 | foreach($names as $name) { |
@@ -434,18 +434,18 @@ discard block |
||
434 | 434 | return $val; |
435 | 435 | } |
436 | 436 | |
437 | - /** |
|
438 | - * Treats the request parameter as a JSON string, and |
|
439 | - * if it exists and contains valid JSON, returns the |
|
440 | - * decoded JSON value as an array (default). |
|
441 | - * |
|
442 | - * @param string $name |
|
443 | - * @param bool $assoc |
|
444 | - * @return array|object |
|
445 | - * |
|
446 | - * @see Request::getJSONAssoc() |
|
447 | - * @see Request::getJSONObject() |
|
448 | - */ |
|
437 | + /** |
|
438 | + * Treats the request parameter as a JSON string, and |
|
439 | + * if it exists and contains valid JSON, returns the |
|
440 | + * decoded JSON value as an array (default). |
|
441 | + * |
|
442 | + * @param string $name |
|
443 | + * @param bool $assoc |
|
444 | + * @return array|object |
|
445 | + * |
|
446 | + * @see Request::getJSONAssoc() |
|
447 | + * @see Request::getJSONObject() |
|
448 | + */ |
|
449 | 449 | public function getJSON(string $name, bool $assoc=true) |
450 | 450 | { |
451 | 451 | $value = $this->getParam($name); |
@@ -470,13 +470,13 @@ discard block |
||
470 | 470 | return new \stdClass(); |
471 | 471 | } |
472 | 472 | |
473 | - /** |
|
474 | - * Like {@link Request::getJSON()}, but omitting the second |
|
475 | - * parameter. Use this for more readable code. |
|
476 | - * |
|
477 | - * @param string $name |
|
478 | - * @return array |
|
479 | - */ |
|
473 | + /** |
|
474 | + * Like {@link Request::getJSON()}, but omitting the second |
|
475 | + * parameter. Use this for more readable code. |
|
476 | + * |
|
477 | + * @param string $name |
|
478 | + * @return array |
|
479 | + */ |
|
480 | 480 | public function getJSONAssoc(string $name) : array |
481 | 481 | { |
482 | 482 | $result = $this->getJSON($name); |
@@ -487,13 +487,13 @@ discard block |
||
487 | 487 | return array(); |
488 | 488 | } |
489 | 489 | |
490 | - /** |
|
491 | - * Like {@link Request::getJSON()}, but omitting the second |
|
492 | - * parameter. Use this for more readable code. |
|
493 | - * |
|
494 | - * @param string $name |
|
495 | - * @return object |
|
496 | - */ |
|
490 | + /** |
|
491 | + * Like {@link Request::getJSON()}, but omitting the second |
|
492 | + * parameter. Use this for more readable code. |
|
493 | + * |
|
494 | + * @param string $name |
|
495 | + * @return object |
|
496 | + */ |
|
497 | 497 | public function getJSONObject(string $name) : object |
498 | 498 | { |
499 | 499 | $result = $this->getJSON($name, false); |
@@ -504,12 +504,12 @@ discard block |
||
504 | 504 | return new \stdClass(); |
505 | 505 | } |
506 | 506 | |
507 | - /** |
|
508 | - * Sends a JSON response with the correct headers. |
|
509 | - * |
|
510 | - * @param array|string $data |
|
511 | - * @param bool $exit Whether to exit the script afterwards. |
|
512 | - */ |
|
507 | + /** |
|
508 | + * Sends a JSON response with the correct headers. |
|
509 | + * |
|
510 | + * @param array|string $data |
|
511 | + * @param bool $exit Whether to exit the script afterwards. |
|
512 | + */ |
|
513 | 513 | public static function sendJSON($data, bool $exit=true) |
514 | 514 | { |
515 | 515 | $payload = $data; |
@@ -529,12 +529,12 @@ discard block |
||
529 | 529 | } |
530 | 530 | } |
531 | 531 | |
532 | - /** |
|
533 | - * Sends HTML to the browser with the correct headers. |
|
534 | - * |
|
535 | - * @param string $html |
|
536 | - * @param bool $exit Whether to exit the script afterwards. |
|
537 | - */ |
|
532 | + /** |
|
533 | + * Sends HTML to the browser with the correct headers. |
|
534 | + * |
|
535 | + * @param string $html |
|
536 | + * @param bool $exit Whether to exit the script afterwards. |
|
537 | + */ |
|
538 | 538 | public static function sendHTML(string $html, bool $exit=true) |
539 | 539 | { |
540 | 540 | header('Cache-Control: no-cache, must-revalidate'); |
@@ -549,16 +549,16 @@ discard block |
||
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | - /** |
|
553 | - * Creates a new instance of the URL comparer, which can check |
|
554 | - * whether the specified URLs match, regardless of the order in |
|
555 | - * which the query parameters are, if any. |
|
556 | - * |
|
557 | - * @param string $sourceURL |
|
558 | - * @param string $targetURL |
|
559 | - * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
560 | - * @return Request_URLComparer |
|
561 | - */ |
|
552 | + /** |
|
553 | + * Creates a new instance of the URL comparer, which can check |
|
554 | + * whether the specified URLs match, regardless of the order in |
|
555 | + * which the query parameters are, if any. |
|
556 | + * |
|
557 | + * @param string $sourceURL |
|
558 | + * @param string $targetURL |
|
559 | + * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
560 | + * @return Request_URLComparer |
|
561 | + */ |
|
562 | 562 | public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
563 | 563 | { |
564 | 564 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
@@ -567,10 +567,10 @@ discard block |
||
567 | 567 | return $comparer; |
568 | 568 | } |
569 | 569 | |
570 | - /** |
|
571 | - * Retrieves the full URL that was used to access the current page. |
|
572 | - * @return string |
|
573 | - */ |
|
570 | + /** |
|
571 | + * Retrieves the full URL that was used to access the current page. |
|
572 | + * @return string |
|
573 | + */ |
|
574 | 574 | public function getCurrentURL() : string |
575 | 575 | { |
576 | 576 | return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | public function getParam($name, $default = null) |
91 | 91 | { |
92 | 92 | $value = $default; |
93 | - if(isset($_REQUEST[$name])) { |
|
93 | + if (isset($_REQUEST[$name])) { |
|
94 | 94 | $value = $_REQUEST[$name]; |
95 | 95 | } |
96 | 96 | |
97 | - if(isset($this->knownParams[$name])) { |
|
97 | + if (isset($this->knownParams[$name])) { |
|
98 | 98 | $value = $this->knownParams[$name]->validate($value); |
99 | 99 | } |
100 | 100 | |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | |
144 | 144 | $exclude = array_merge($exclude, $this->getExcludeParams()); |
145 | 145 | |
146 | - foreach($exclude as $name) |
|
146 | + foreach ($exclude as $name) |
|
147 | 147 | { |
148 | - if(isset($vars[$name])) |
|
148 | + if (isset($vars[$name])) |
|
149 | 149 | { |
150 | 150 | unset($vars[$name]); |
151 | 151 | } |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | // remove the HTML_QuickForm2 form variable if present, to |
157 | 157 | // avoid redirect loops when using the refresh URL in |
158 | 158 | // a page in which a form has been submitted. |
159 | - foreach($names as $name) |
|
159 | + foreach ($names as $name) |
|
160 | 160 | { |
161 | - if(strstr($name, '_qf__')) |
|
161 | + if (strstr($name, '_qf__')) |
|
162 | 162 | { |
163 | 163 | unset($vars[$name]); |
164 | 164 | break; |
@@ -186,13 +186,13 @@ discard block |
||
186 | 186 | * @param string $dispatcher Relative path to script to use for the URL. Append trailing slash if needed. |
187 | 187 | * @return string |
188 | 188 | */ |
189 | - public function buildURL($params = array(), string $dispatcher='') |
|
189 | + public function buildURL($params = array(), string $dispatcher = '') |
|
190 | 190 | { |
191 | - $url = rtrim($this->getBaseURL(), '/') . '/' . $dispatcher; |
|
191 | + $url = rtrim($this->getBaseURL(), '/').'/'.$dispatcher; |
|
192 | 192 | |
193 | 193 | // append any leftover parameters to the end of the URL |
194 | 194 | if (!empty($params)) { |
195 | - $url .= '?' . http_build_query($params, null, '&'); |
|
195 | + $url .= '?'.http_build_query($params, null, '&'); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | return $url; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function registerParam($name) |
225 | 225 | { |
226 | - if(!isset($this->knownParams[$name])) { |
|
226 | + if (!isset($this->knownParams[$name])) { |
|
227 | 227 | $param = new Request_Param($this, $name); |
228 | 228 | $this->knownParams[$name] = $param; |
229 | 229 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function getRegisteredParam(string $name) : Request_Param |
242 | 242 | { |
243 | - if(isset($this->knownParams[$name])) { |
|
243 | + if (isset($this->knownParams[$name])) { |
|
244 | 244 | return $this->knownParams[$name]; |
245 | 245 | } |
246 | 246 | |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | { |
301 | 301 | static $accept; |
302 | 302 | |
303 | - if(!isset($accept)) { |
|
303 | + if (!isset($accept)) { |
|
304 | 304 | $accept = new Request_AcceptHeaders(); |
305 | 305 | } |
306 | 306 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | { |
320 | 320 | $_REQUEST[$name] = $value; |
321 | 321 | |
322 | - if(isset($this->knownParams[$name])) { |
|
322 | + if (isset($this->knownParams[$name])) { |
|
323 | 323 | unset($this->knownParams[$name]); |
324 | 324 | } |
325 | 325 | |
@@ -353,11 +353,11 @@ discard block |
||
353 | 353 | */ |
354 | 354 | public function removeParam(string $name) : Request |
355 | 355 | { |
356 | - if(isset($_REQUEST[$name])) { |
|
356 | + if (isset($_REQUEST[$name])) { |
|
357 | 357 | unset($_REQUEST[$name]); |
358 | 358 | } |
359 | 359 | |
360 | - if(isset($this->knownParams[$name])) { |
|
360 | + if (isset($this->knownParams[$name])) { |
|
361 | 361 | unset($this->knownParams[$name]); |
362 | 362 | } |
363 | 363 | |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | */ |
373 | 373 | public function removeParams(array $names) : Request |
374 | 374 | { |
375 | - foreach($names as $name) { |
|
375 | + foreach ($names as $name) { |
|
376 | 376 | $this->removeParam($name); |
377 | 377 | } |
378 | 378 | |
@@ -388,10 +388,10 @@ discard block |
||
388 | 388 | * @param string $name |
389 | 389 | * @return bool |
390 | 390 | */ |
391 | - public function getBool($name, $default=false) |
|
391 | + public function getBool($name, $default = false) |
|
392 | 392 | { |
393 | 393 | $value = $this->getParam($name, $default); |
394 | - if(ConvertHelper::isBoolean($value)) { |
|
394 | + if (ConvertHelper::isBoolean($value)) { |
|
395 | 395 | return ConvertHelper::string2bool($value); |
396 | 396 | } |
397 | 397 | |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | |
401 | 401 | public function validate() |
402 | 402 | { |
403 | - foreach($this->knownParams as $param) |
|
403 | + foreach ($this->knownParams as $param) |
|
404 | 404 | { |
405 | 405 | $name = $param->getName(); |
406 | 406 | |
407 | - if($param->isRequired() && !$this->hasParam($name)) |
|
407 | + if ($param->isRequired() && !$this->hasParam($name)) |
|
408 | 408 | { |
409 | 409 | throw new Request_Exception( |
410 | 410 | 'Missing request parameter '.$name, |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | * @param mixed $default |
427 | 427 | * @return string |
428 | 428 | */ |
429 | - public function getFilteredParam($name, $default=null) |
|
429 | + public function getFilteredParam($name, $default = null) |
|
430 | 430 | { |
431 | 431 | $val = $this->getParam($name, $default); |
432 | - if(is_string($val)) { |
|
432 | + if (is_string($val)) { |
|
433 | 433 | $val = htmlspecialchars(trim(strip_tags($val)), ENT_QUOTES, 'UTF-8'); |
434 | 434 | } |
435 | 435 | |
@@ -448,24 +448,24 @@ discard block |
||
448 | 448 | * @see Request::getJSONAssoc() |
449 | 449 | * @see Request::getJSONObject() |
450 | 450 | */ |
451 | - public function getJSON(string $name, bool $assoc=true) |
|
451 | + public function getJSON(string $name, bool $assoc = true) |
|
452 | 452 | { |
453 | 453 | $value = $this->getParam($name); |
454 | 454 | |
455 | - if(!empty($value) && is_string($value)) |
|
455 | + if (!empty($value) && is_string($value)) |
|
456 | 456 | { |
457 | 457 | $data = json_decode($value, $assoc); |
458 | 458 | |
459 | - if($assoc && is_array($data)) { |
|
459 | + if ($assoc && is_array($data)) { |
|
460 | 460 | return $data; |
461 | 461 | } |
462 | 462 | |
463 | - if(is_object($data)) { |
|
463 | + if (is_object($data)) { |
|
464 | 464 | return $data; |
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
468 | - if($assoc) { |
|
468 | + if ($assoc) { |
|
469 | 469 | return array(); |
470 | 470 | } |
471 | 471 | |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | public function getJSONAssoc(string $name) : array |
483 | 483 | { |
484 | 484 | $result = $this->getJSON($name); |
485 | - if(is_array($result)) { |
|
485 | + if (is_array($result)) { |
|
486 | 486 | return $result; |
487 | 487 | } |
488 | 488 | |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | public function getJSONObject(string $name) : object |
500 | 500 | { |
501 | 501 | $result = $this->getJSON($name, false); |
502 | - if(is_object($result)) { |
|
502 | + if (is_object($result)) { |
|
503 | 503 | return $result; |
504 | 504 | } |
505 | 505 | |
@@ -512,10 +512,10 @@ discard block |
||
512 | 512 | * @param array|string $data |
513 | 513 | * @param bool $exit Whether to exit the script afterwards. |
514 | 514 | */ |
515 | - public static function sendJSON($data, bool $exit=true) |
|
515 | + public static function sendJSON($data, bool $exit = true) |
|
516 | 516 | { |
517 | 517 | $payload = $data; |
518 | - if(!is_string($payload)) { |
|
518 | + if (!is_string($payload)) { |
|
519 | 519 | $payload = json_encode($payload); |
520 | 520 | } |
521 | 521 | |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | |
526 | 526 | echo $payload; |
527 | 527 | |
528 | - if($exit) |
|
528 | + if ($exit) |
|
529 | 529 | { |
530 | 530 | exit; |
531 | 531 | } |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | * @param string $html |
538 | 538 | * @param bool $exit Whether to exit the script afterwards. |
539 | 539 | */ |
540 | - public static function sendHTML(string $html, bool $exit=true) |
|
540 | + public static function sendHTML(string $html, bool $exit = true) |
|
541 | 541 | { |
542 | 542 | header('Cache-Control: no-cache, must-revalidate'); |
543 | 543 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | |
546 | 546 | echo $html; |
547 | 547 | |
548 | - if($exit) |
|
548 | + if ($exit) |
|
549 | 549 | { |
550 | 550 | exit; |
551 | 551 | } |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
562 | 562 | * @return Request_URLComparer |
563 | 563 | */ |
564 | - public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
|
564 | + public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams = array()) : Request_URLComparer |
|
565 | 565 | { |
566 | 566 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
567 | 567 | $comparer->addLimitParams($limitParams); |