@@ -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; |
@@ -31,17 +31,17 @@ discard block |
||
31 | 31 | |
32 | 32 | const BASE_2 = 1024; |
33 | 33 | |
34 | - /** |
|
35 | - * @var ConvertHelper_StorageSizeEnum_Size[] |
|
36 | - */ |
|
34 | + /** |
|
35 | + * @var ConvertHelper_StorageSizeEnum_Size[] |
|
36 | + */ |
|
37 | 37 | protected static $sizes; |
38 | 38 | |
39 | - /** |
|
40 | - * Initializes the supported unit notations, and |
|
41 | - * how they are supposed to be calculated. |
|
42 | - * |
|
43 | - * @see ConvertHelper_SizeNotation::parseSize() |
|
44 | - */ |
|
39 | + /** |
|
40 | + * Initializes the supported unit notations, and |
|
41 | + * how they are supposed to be calculated. |
|
42 | + * |
|
43 | + * @see ConvertHelper_SizeNotation::parseSize() |
|
44 | + */ |
|
45 | 45 | protected static function init() |
46 | 46 | { |
47 | 47 | if(isset(self::$sizes)) { |
@@ -70,30 +70,30 @@ discard block |
||
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * Called whenever the application locale is changed, |
|
75 | - * to reset the size definitions so the labels get |
|
76 | - * translated to the new locale. |
|
77 | - * |
|
78 | - * @param \AppLocalize\Localization_Event_LocaleChanged $event |
|
79 | - */ |
|
73 | + /** |
|
74 | + * Called whenever the application locale is changed, |
|
75 | + * to reset the size definitions so the labels get |
|
76 | + * translated to the new locale. |
|
77 | + * |
|
78 | + * @param \AppLocalize\Localization_Event_LocaleChanged $event |
|
79 | + */ |
|
80 | 80 | public static function handle_localeChanged(\AppLocalize\Localization_Event_LocaleChanged $event) |
81 | 81 | { |
82 | 82 | self::$sizes = null; |
83 | 83 | } |
84 | 84 | |
85 | - /** |
|
86 | - * Adds a storage size to the internal collection. |
|
87 | - * |
|
88 | - * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
89 | - * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
90 | - * @param int $exponent The multiplier of the base to get the byte value |
|
91 | - * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
92 | - * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
93 | - * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
94 | - * |
|
95 | - * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
96 | - */ |
|
85 | + /** |
|
86 | + * Adds a storage size to the internal collection. |
|
87 | + * |
|
88 | + * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
89 | + * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
90 | + * @param int $exponent The multiplier of the base to get the byte value |
|
91 | + * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
92 | + * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
93 | + * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
94 | + * |
|
95 | + * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
96 | + */ |
|
97 | 97 | protected static function addSize(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) |
98 | 98 | { |
99 | 99 | self::$sizes[$name] = new ConvertHelper_StorageSizeEnum_Size( |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | ); |
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * Retrieves all known sizes. |
|
111 | - * |
|
112 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
113 | - */ |
|
109 | + /** |
|
110 | + * Retrieves all known sizes. |
|
111 | + * |
|
112 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
113 | + */ |
|
114 | 114 | public static function getSizes() |
115 | 115 | { |
116 | 116 | self::init(); |
@@ -118,15 +118,15 @@ discard block |
||
118 | 118 | return self::$sizes; |
119 | 119 | } |
120 | 120 | |
121 | - /** |
|
122 | - * Retrieves a size definition instance by its name. |
|
123 | - * |
|
124 | - * @param string $name Case insensitive. For example "kb", "MiB"... |
|
125 | - * @throws ConvertHelper_Exception |
|
126 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
127 | - * |
|
128 | - * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
129 | - */ |
|
121 | + /** |
|
122 | + * Retrieves a size definition instance by its name. |
|
123 | + * |
|
124 | + * @param string $name Case insensitive. For example "kb", "MiB"... |
|
125 | + * @throws ConvertHelper_Exception |
|
126 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
127 | + * |
|
128 | + * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
129 | + */ |
|
130 | 130 | public static function getSizeByName(string $name) : ConvertHelper_StorageSizeEnum_Size |
131 | 131 | { |
132 | 132 | self::init(); |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | ); |
149 | 149 | } |
150 | 150 | |
151 | - /** |
|
152 | - * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
153 | - * @return array |
|
154 | - */ |
|
151 | + /** |
|
152 | + * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
153 | + * @return array |
|
154 | + */ |
|
155 | 155 | public static function getSizeNames() : array |
156 | 156 | { |
157 | 157 | self::init(); |
@@ -159,16 +159,16 @@ discard block |
||
159 | 159 | return array_keys(self::$sizes); |
160 | 160 | } |
161 | 161 | |
162 | - /** |
|
163 | - * Retrieves all available storage sizes for the specified |
|
164 | - * base value. |
|
165 | - * |
|
166 | - * @param int $base |
|
167 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
168 | - * |
|
169 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
170 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
171 | - */ |
|
162 | + /** |
|
163 | + * Retrieves all available storage sizes for the specified |
|
164 | + * base value. |
|
165 | + * |
|
166 | + * @param int $base |
|
167 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
168 | + * |
|
169 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
170 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
171 | + */ |
|
172 | 172 | public static function getSizesByBase(int $base) |
173 | 173 | { |
174 | 174 | self::init(); |
@@ -20,24 +20,24 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class URLInfo_Parser |
22 | 22 | { |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | 26 | protected $url; |
27 | 27 | |
28 | - /** |
|
29 | - * @var bool |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var bool |
|
30 | + */ |
|
31 | 31 | protected $isValid = false; |
32 | 32 | |
33 | - /** |
|
34 | - * @var array |
|
35 | - */ |
|
33 | + /** |
|
34 | + * @var array |
|
35 | + */ |
|
36 | 36 | protected $info; |
37 | 37 | |
38 | - /** |
|
39 | - * @var array|NULL |
|
40 | - */ |
|
38 | + /** |
|
39 | + * @var array|NULL |
|
40 | + */ |
|
41 | 41 | protected $error; |
42 | 42 | |
43 | 43 | /** |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | - /** |
|
181 | - * Goes through all information in the parse_url result |
|
182 | - * array, and attempts to fix any user errors in formatting |
|
183 | - * that can be recovered from, mostly regarding stray spaces. |
|
184 | - */ |
|
180 | + /** |
|
181 | + * Goes through all information in the parse_url result |
|
182 | + * array, and attempts to fix any user errors in formatting |
|
183 | + * that can be recovered from, mostly regarding stray spaces. |
|
184 | + */ |
|
185 | 185 | protected function filterParsed() |
186 | 186 | { |
187 | 187 | foreach($this->info as $key => $val) |
@@ -20,9 +20,9 @@ |
||
20 | 20 | */ |
21 | 21 | class URLInfo_Highlighter |
22 | 22 | { |
23 | - /** |
|
24 | - * @var URLInfo |
|
25 | - */ |
|
23 | + /** |
|
24 | + * @var URLInfo |
|
25 | + */ |
|
26 | 26 | protected $info; |
27 | 27 | |
28 | 28 | public function __construct(URLInfo $info) |
@@ -37,42 +37,42 @@ discard block |
||
37 | 37 | const TYPE_PHONE = 'phone'; |
38 | 38 | const TYPE_URL = 'url'; |
39 | 39 | |
40 | - /** |
|
41 | - * The original URL that was passed to the constructor. |
|
42 | - * @var string |
|
43 | - */ |
|
40 | + /** |
|
41 | + * The original URL that was passed to the constructor. |
|
42 | + * @var string |
|
43 | + */ |
|
44 | 44 | protected $rawURL; |
45 | 45 | |
46 | - /** |
|
47 | - * @var array |
|
48 | - */ |
|
46 | + /** |
|
47 | + * @var array |
|
48 | + */ |
|
49 | 49 | protected $info; |
50 | 50 | |
51 | - /** |
|
52 | - * @var string[] |
|
53 | - */ |
|
51 | + /** |
|
52 | + * @var string[] |
|
53 | + */ |
|
54 | 54 | protected $excludedParams = array(); |
55 | 55 | |
56 | - /** |
|
57 | - * @var bool |
|
58 | - * @see URLInfo::setParamExclusion() |
|
59 | - */ |
|
56 | + /** |
|
57 | + * @var bool |
|
58 | + * @see URLInfo::setParamExclusion() |
|
59 | + */ |
|
60 | 60 | protected $paramExclusion = false; |
61 | 61 | |
62 | - /** |
|
63 | - * @var array |
|
64 | - * @see URLInfo::getTypeLabel() |
|
65 | - */ |
|
62 | + /** |
|
63 | + * @var array |
|
64 | + * @see URLInfo::getTypeLabel() |
|
65 | + */ |
|
66 | 66 | protected static $typeLabels; |
67 | 67 | |
68 | - /** |
|
69 | - * @var bool |
|
70 | - */ |
|
68 | + /** |
|
69 | + * @var bool |
|
70 | + */ |
|
71 | 71 | protected $highlightExcluded = false; |
72 | 72 | |
73 | - /** |
|
74 | - * @var array |
|
75 | - */ |
|
73 | + /** |
|
74 | + * @var array |
|
75 | + */ |
|
76 | 76 | protected $infoKeys = array( |
77 | 77 | 'scheme', |
78 | 78 | 'host', |
@@ -84,19 +84,19 @@ discard block |
||
84 | 84 | 'fragment' |
85 | 85 | ); |
86 | 86 | |
87 | - /** |
|
88 | - * @var string |
|
89 | - */ |
|
87 | + /** |
|
88 | + * @var string |
|
89 | + */ |
|
90 | 90 | protected $url; |
91 | 91 | |
92 | - /** |
|
93 | - * @var URLInfo_Parser |
|
94 | - */ |
|
92 | + /** |
|
93 | + * @var URLInfo_Parser |
|
94 | + */ |
|
95 | 95 | protected $parser; |
96 | 96 | |
97 | - /** |
|
98 | - * @var URLInfo_Normalizer |
|
99 | - */ |
|
97 | + /** |
|
98 | + * @var URLInfo_Normalizer |
|
99 | + */ |
|
100 | 100 | protected $normalizer; |
101 | 101 | |
102 | 102 | public function __construct(string $url) |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | $this->info = $this->parser->getInfo(); |
109 | 109 | } |
110 | 110 | |
111 | - /** |
|
112 | - * Filters an URL: removes control characters and the |
|
113 | - * like to have a clean URL to work with. |
|
114 | - * |
|
115 | - * @param string $url |
|
116 | - * @return string |
|
117 | - */ |
|
111 | + /** |
|
112 | + * Filters an URL: removes control characters and the |
|
113 | + * like to have a clean URL to work with. |
|
114 | + * |
|
115 | + * @param string $url |
|
116 | + * @return string |
|
117 | + */ |
|
118 | 118 | public static function filterURL(string $url) |
119 | 119 | { |
120 | 120 | return URLInfo_Filter::filter($url); |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | return $this->info['type'] === self::TYPE_PHONE; |
145 | 145 | } |
146 | 146 | |
147 | - /** |
|
148 | - * Whether the URL is a regular URL, not one of the |
|
149 | - * other types like a phone number or email address. |
|
150 | - * |
|
151 | - * @return bool |
|
152 | - */ |
|
147 | + /** |
|
148 | + * Whether the URL is a regular URL, not one of the |
|
149 | + * other types like a phone number or email address. |
|
150 | + * |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | 153 | public function isURL() : bool |
154 | 154 | { |
155 | 155 | $host = $this->getHost(); |
@@ -161,20 +161,20 @@ discard block |
||
161 | 161 | return $this->parser->isValid(); |
162 | 162 | } |
163 | 163 | |
164 | - /** |
|
165 | - * Retrieves the host name, or an empty string if none is present. |
|
166 | - * |
|
167 | - * @return string |
|
168 | - */ |
|
164 | + /** |
|
165 | + * Retrieves the host name, or an empty string if none is present. |
|
166 | + * |
|
167 | + * @return string |
|
168 | + */ |
|
169 | 169 | public function getHost() : string |
170 | 170 | { |
171 | 171 | return $this->getInfoKey('host'); |
172 | 172 | } |
173 | 173 | |
174 | - /** |
|
175 | - * Retrieves the path, or an empty string if none is present. |
|
176 | - * @return string |
|
177 | - */ |
|
174 | + /** |
|
175 | + * Retrieves the path, or an empty string if none is present. |
|
176 | + * @return string |
|
177 | + */ |
|
178 | 178 | public function getPath() : string |
179 | 179 | { |
180 | 180 | return $this->getInfoKey('path'); |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | return $this->getInfoKey('scheme'); |
191 | 191 | } |
192 | 192 | |
193 | - /** |
|
194 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
195 | - * @return int |
|
196 | - */ |
|
193 | + /** |
|
194 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
195 | + * @return int |
|
196 | + */ |
|
197 | 197 | public function getPort() : int |
198 | 198 | { |
199 | 199 | $port = $this->getInfoKey('port'); |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | return -1; |
206 | 206 | } |
207 | 207 | |
208 | - /** |
|
209 | - * Retrieves the raw query string, or an empty string if none is present. |
|
210 | - * |
|
211 | - * @return string |
|
212 | - * |
|
213 | - * @see URLInfo::getParams() |
|
214 | - */ |
|
208 | + /** |
|
209 | + * Retrieves the raw query string, or an empty string if none is present. |
|
210 | + * |
|
211 | + * @return string |
|
212 | + * |
|
213 | + * @see URLInfo::getParams() |
|
214 | + */ |
|
215 | 215 | public function getQuery() : string |
216 | 216 | { |
217 | 217 | return $this->getInfoKey('query'); |
@@ -227,20 +227,20 @@ discard block |
||
227 | 227 | return $this->getInfoKey('pass'); |
228 | 228 | } |
229 | 229 | |
230 | - /** |
|
231 | - * Whether the URL contains a port number. |
|
232 | - * @return bool |
|
233 | - */ |
|
230 | + /** |
|
231 | + * Whether the URL contains a port number. |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | 234 | public function hasPort() : bool |
235 | 235 | { |
236 | 236 | return $this->getPort() !== -1; |
237 | 237 | } |
238 | 238 | |
239 | - /** |
|
240 | - * Alias for the hasParams() method. |
|
241 | - * @return bool |
|
242 | - * @see URLInfo::hasParams() |
|
243 | - */ |
|
239 | + /** |
|
240 | + * Alias for the hasParams() method. |
|
241 | + * @return bool |
|
242 | + * @see URLInfo::hasParams() |
|
243 | + */ |
|
244 | 244 | public function hasQuery() : bool |
245 | 245 | { |
246 | 246 | return $this->hasParams(); |
@@ -298,25 +298,25 @@ discard block |
||
298 | 298 | return $this->normalizer->normalize(); |
299 | 299 | } |
300 | 300 | |
301 | - /** |
|
302 | - * Creates a hash of the URL, which can be used for comparisons. |
|
303 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
304 | - * the same links with a different parameter order will have the |
|
305 | - * same hash. |
|
306 | - * |
|
307 | - * @return string |
|
308 | - */ |
|
301 | + /** |
|
302 | + * Creates a hash of the URL, which can be used for comparisons. |
|
303 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
304 | + * the same links with a different parameter order will have the |
|
305 | + * same hash. |
|
306 | + * |
|
307 | + * @return string |
|
308 | + */ |
|
309 | 309 | public function getHash() |
310 | 310 | { |
311 | 311 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
312 | 312 | } |
313 | 313 | |
314 | - /** |
|
315 | - * Highlights the URL using HTML tags with specific highlighting |
|
316 | - * class names. |
|
317 | - * |
|
318 | - * @return string Will return an empty string if the URL is not valid. |
|
319 | - */ |
|
314 | + /** |
|
315 | + * Highlights the URL using HTML tags with specific highlighting |
|
316 | + * class names. |
|
317 | + * |
|
318 | + * @return string Will return an empty string if the URL is not valid. |
|
319 | + */ |
|
320 | 320 | public function getHighlighted() : string |
321 | 321 | { |
322 | 322 | if(!$this->isValid()) { |
@@ -350,15 +350,15 @@ discard block |
||
350 | 350 | return count($params); |
351 | 351 | } |
352 | 352 | |
353 | - /** |
|
354 | - * Retrieves all parameters specified in the url, |
|
355 | - * if any, as an associative array. |
|
356 | - * |
|
357 | - * NOTE: Ignores parameters that have been added |
|
358 | - * to the excluded parameters list. |
|
359 | - * |
|
360 | - * @return array |
|
361 | - */ |
|
353 | + /** |
|
354 | + * Retrieves all parameters specified in the url, |
|
355 | + * if any, as an associative array. |
|
356 | + * |
|
357 | + * NOTE: Ignores parameters that have been added |
|
358 | + * to the excluded parameters list. |
|
359 | + * |
|
360 | + * @return array |
|
361 | + */ |
|
362 | 362 | public function getParams() : array |
363 | 363 | { |
364 | 364 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -376,22 +376,22 @@ discard block |
||
376 | 376 | return $keep; |
377 | 377 | } |
378 | 378 | |
379 | - /** |
|
380 | - * Retrieves the names of all parameters present in the URL, if any. |
|
381 | - * @return string[] |
|
382 | - */ |
|
379 | + /** |
|
380 | + * Retrieves the names of all parameters present in the URL, if any. |
|
381 | + * @return string[] |
|
382 | + */ |
|
383 | 383 | public function getParamNames() : array |
384 | 384 | { |
385 | 385 | $params = $this->getParams(); |
386 | 386 | return array_keys($params); |
387 | 387 | } |
388 | 388 | |
389 | - /** |
|
390 | - * Retrieves a specific parameter value from the URL. |
|
391 | - * |
|
392 | - * @param string $name |
|
393 | - * @return string The parameter value, or an empty string if it does not exist. |
|
394 | - */ |
|
389 | + /** |
|
390 | + * Retrieves a specific parameter value from the URL. |
|
391 | + * |
|
392 | + * @param string $name |
|
393 | + * @return string The parameter value, or an empty string if it does not exist. |
|
394 | + */ |
|
395 | 395 | public function getParam(string $name) : string |
396 | 396 | { |
397 | 397 | if(isset($this->info['params'][$name])) { |
@@ -401,16 +401,16 @@ discard block |
||
401 | 401 | return ''; |
402 | 402 | } |
403 | 403 | |
404 | - /** |
|
405 | - * Excludes an URL parameter entirely if present: |
|
406 | - * the parser will act as if the parameter was not |
|
407 | - * even present in the source URL, effectively |
|
408 | - * stripping it. |
|
409 | - * |
|
410 | - * @param string $name |
|
411 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
412 | - * @return URLInfo |
|
413 | - */ |
|
404 | + /** |
|
405 | + * Excludes an URL parameter entirely if present: |
|
406 | + * the parser will act as if the parameter was not |
|
407 | + * even present in the source URL, effectively |
|
408 | + * stripping it. |
|
409 | + * |
|
410 | + * @param string $name |
|
411 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
412 | + * @return URLInfo |
|
413 | + */ |
|
414 | 414 | public function excludeParam(string $name, string $reason) : URLInfo |
415 | 415 | { |
416 | 416 | if(!isset($this->excludedParams[$name])) |
@@ -463,25 +463,25 @@ discard block |
||
463 | 463 | return self::$typeLabels[$this->getType()]; |
464 | 464 | } |
465 | 465 | |
466 | - /** |
|
467 | - * Whether excluded parameters should be highlighted in |
|
468 | - * a different color in the URL when using the |
|
469 | - * {@link URLInfo::getHighlighted()} method. |
|
470 | - * |
|
471 | - * @param bool $highlight |
|
472 | - * @return URLInfo |
|
473 | - */ |
|
466 | + /** |
|
467 | + * Whether excluded parameters should be highlighted in |
|
468 | + * a different color in the URL when using the |
|
469 | + * {@link URLInfo::getHighlighted()} method. |
|
470 | + * |
|
471 | + * @param bool $highlight |
|
472 | + * @return URLInfo |
|
473 | + */ |
|
474 | 474 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
475 | 475 | { |
476 | 476 | $this->highlightExcluded = $highlight; |
477 | 477 | return $this; |
478 | 478 | } |
479 | 479 | |
480 | - /** |
|
481 | - * Returns an array with all relevant URL information. |
|
482 | - * |
|
483 | - * @return array |
|
484 | - */ |
|
480 | + /** |
|
481 | + * Returns an array with all relevant URL information. |
|
482 | + * |
|
483 | + * @return array |
|
484 | + */ |
|
485 | 485 | public function toArray() : array |
486 | 486 | { |
487 | 487 | return array( |
@@ -525,24 +525,24 @@ discard block |
||
525 | 525 | return $this; |
526 | 526 | } |
527 | 527 | |
528 | - /** |
|
529 | - * Whether the parameter exclusion mode is enabled: |
|
530 | - * In this case, if any parameters have been added to the |
|
531 | - * exclusion list, all relevant methods will exclude these. |
|
532 | - * |
|
533 | - * @return bool |
|
534 | - */ |
|
528 | + /** |
|
529 | + * Whether the parameter exclusion mode is enabled: |
|
530 | + * In this case, if any parameters have been added to the |
|
531 | + * exclusion list, all relevant methods will exclude these. |
|
532 | + * |
|
533 | + * @return bool |
|
534 | + */ |
|
535 | 535 | public function isParamExclusionEnabled() : bool |
536 | 536 | { |
537 | 537 | return $this->paramExclusion; |
538 | 538 | } |
539 | 539 | |
540 | - /** |
|
541 | - * Checks whether the link contains any parameters that |
|
542 | - * are on the list of excluded parameters. |
|
543 | - * |
|
544 | - * @return bool |
|
545 | - */ |
|
540 | + /** |
|
541 | + * Checks whether the link contains any parameters that |
|
542 | + * are on the list of excluded parameters. |
|
543 | + * |
|
544 | + * @return bool |
|
545 | + */ |
|
546 | 546 | public function containsExcludedParams() : bool |
547 | 547 | { |
548 | 548 | if(empty($this->excludedParams)) { |
@@ -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']; |
@@ -28,20 +28,20 @@ discard block |
||
28 | 28 | $this->parse(); |
29 | 29 | } |
30 | 30 | |
31 | - /** |
|
32 | - * Retrieves an indexed array with accept mime types |
|
33 | - * that the client sent, in the order of preference |
|
34 | - * the client specified. |
|
35 | - * |
|
36 | - * Example: |
|
37 | - * |
|
38 | - * array( |
|
39 | - * 'text/html', |
|
40 | - * 'application/xhtml+xml', |
|
41 | - * 'image/webp' |
|
42 | - * ... |
|
43 | - * ) |
|
44 | - */ |
|
31 | + /** |
|
32 | + * Retrieves an indexed array with accept mime types |
|
33 | + * that the client sent, in the order of preference |
|
34 | + * the client specified. |
|
35 | + * |
|
36 | + * Example: |
|
37 | + * |
|
38 | + * array( |
|
39 | + * 'text/html', |
|
40 | + * 'application/xhtml+xml', |
|
41 | + * 'image/webp' |
|
42 | + * ... |
|
43 | + * ) |
|
44 | + */ |
|
45 | 45 | public function getMimeStrings() : array |
46 | 46 | { |
47 | 47 | $result = array(); |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | return $result; |
55 | 55 | } |
56 | 56 | |
57 | - /** |
|
58 | - * Checks that an accept header string exists, and tries to parse it. |
|
59 | - */ |
|
57 | + /** |
|
58 | + * Checks that an accept header string exists, and tries to parse it. |
|
59 | + */ |
|
60 | 60 | protected function parse() : void |
61 | 61 | { |
62 | 62 | // we may be in a CLI environment where the headers |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | $this->headers = $this->parseHeader($_SERVER['HTTP_ACCEPT']); |
69 | 69 | } |
70 | 70 | |
71 | - /** |
|
72 | - * Splits the accept header string and parses the mime types. |
|
73 | - * |
|
74 | - * @param string $acceptHeader |
|
75 | - */ |
|
71 | + /** |
|
72 | + * Splits the accept header string and parses the mime types. |
|
73 | + * |
|
74 | + * @param string $acceptHeader |
|
75 | + */ |
|
76 | 76 | protected function parseHeader(string $acceptHeader) : array |
77 | 77 | { |
78 | 78 | $tokens = preg_split('/\s*,\s*/', $acceptHeader); |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | return $accept; |
90 | 90 | } |
91 | 91 | |
92 | - /** |
|
93 | - * Parses a single mime type entry. |
|
94 | - * |
|
95 | - * @param int $i The position in the accept string |
|
96 | - * @param string $mime The mime type |
|
97 | - * @return array |
|
98 | - */ |
|
92 | + /** |
|
93 | + * Parses a single mime type entry. |
|
94 | + * |
|
95 | + * @param int $i The position in the accept string |
|
96 | + * @param string $mime The mime type |
|
97 | + * @return array |
|
98 | + */ |
|
99 | 99 | protected function parseEntry(int $i, string $mime) : array |
100 | 100 | { |
101 | 101 | $entry = array( |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | return $entry; |
126 | 126 | } |
127 | 127 | |
128 | - /** |
|
129 | - * Sorts the mime types collection, first by quality |
|
130 | - * and then by position in the list. |
|
131 | - * |
|
132 | - * @param array $a |
|
133 | - * @param array $b |
|
134 | - * @return number |
|
135 | - */ |
|
128 | + /** |
|
129 | + * Sorts the mime types collection, first by quality |
|
130 | + * and then by position in the list. |
|
131 | + * |
|
132 | + * @param array $a |
|
133 | + * @param array $b |
|
134 | + * @return number |
|
135 | + */ |
|
136 | 136 | protected function sortMimeTypes(array $a, array $b) |
137 | 137 | { |
138 | 138 | /* first tier: highest q factor wins */ |
@@ -76,32 +76,32 @@ discard block |
||
76 | 76 | |
77 | 77 | const ERROR_CANNOT_OPEN_FILE_TO_DETECT_BOM = 340032; |
78 | 78 | |
79 | - /** |
|
80 | - * Opens a serialized file and returns the unserialized data. |
|
81 | - * |
|
82 | - * @param string $file |
|
83 | - * @throws FileHelper_Exception |
|
84 | - * @return array |
|
85 | - * @deprecated Use parseSerializedFile() instead. |
|
86 | - * @see FileHelper::parseSerializedFile() |
|
87 | - */ |
|
79 | + /** |
|
80 | + * Opens a serialized file and returns the unserialized data. |
|
81 | + * |
|
82 | + * @param string $file |
|
83 | + * @throws FileHelper_Exception |
|
84 | + * @return array |
|
85 | + * @deprecated Use parseSerializedFile() instead. |
|
86 | + * @see FileHelper::parseSerializedFile() |
|
87 | + */ |
|
88 | 88 | public static function openUnserialized(string $file) : array |
89 | 89 | { |
90 | 90 | return self::parseSerializedFile($file); |
91 | 91 | } |
92 | 92 | |
93 | - /** |
|
94 | - * Opens a serialized file and returns the unserialized data. |
|
95 | - * |
|
96 | - * @param string $file |
|
97 | - * @throws FileHelper_Exception |
|
98 | - * @return array |
|
99 | - * @see FileHelper::parseSerializedFile() |
|
100 | - * |
|
101 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
102 | - * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
103 | - * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
104 | - */ |
|
93 | + /** |
|
94 | + * Opens a serialized file and returns the unserialized data. |
|
95 | + * |
|
96 | + * @param string $file |
|
97 | + * @throws FileHelper_Exception |
|
98 | + * @return array |
|
99 | + * @see FileHelper::parseSerializedFile() |
|
100 | + * |
|
101 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
102 | + * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
103 | + * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
104 | + */ |
|
105 | 105 | public static function parseSerializedFile(string $file) |
106 | 106 | { |
107 | 107 | self::requireFileExists($file); |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | return rmdir($rootFolder); |
171 | 171 | } |
172 | 172 | |
173 | - /** |
|
174 | - * Create a folder, if it does not exist yet. |
|
175 | - * |
|
176 | - * @param string $path |
|
177 | - * @throws FileHelper_Exception |
|
178 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
179 | - */ |
|
173 | + /** |
|
174 | + * Create a folder, if it does not exist yet. |
|
175 | + * |
|
176 | + * @param string $path |
|
177 | + * @throws FileHelper_Exception |
|
178 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
179 | + */ |
|
180 | 180 | public static function createFolder($path) |
181 | 181 | { |
182 | 182 | if(is_dir($path) || mkdir($path, 0777, true)) { |
@@ -223,22 +223,22 @@ discard block |
||
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | - /** |
|
227 | - * Copies a file to the target location. Includes checks |
|
228 | - * for most error sources, like the source file not being |
|
229 | - * readable. Automatically creates the target folder if it |
|
230 | - * does not exist yet. |
|
231 | - * |
|
232 | - * @param string $sourcePath |
|
233 | - * @param string $targetPath |
|
234 | - * @throws FileHelper_Exception |
|
235 | - * |
|
236 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
237 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
238 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
239 | - * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
240 | - * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
241 | - */ |
|
226 | + /** |
|
227 | + * Copies a file to the target location. Includes checks |
|
228 | + * for most error sources, like the source file not being |
|
229 | + * readable. Automatically creates the target folder if it |
|
230 | + * does not exist yet. |
|
231 | + * |
|
232 | + * @param string $sourcePath |
|
233 | + * @param string $targetPath |
|
234 | + * @throws FileHelper_Exception |
|
235 | + * |
|
236 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
237 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
238 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
239 | + * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
240 | + * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
241 | + */ |
|
242 | 242 | public static function copyFile($sourcePath, $targetPath) |
243 | 243 | { |
244 | 244 | self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND); |
@@ -289,15 +289,15 @@ discard block |
||
289 | 289 | ); |
290 | 290 | } |
291 | 291 | |
292 | - /** |
|
293 | - * Deletes the target file. Ignored if it cannot be found, |
|
294 | - * and throws an exception if it fails. |
|
295 | - * |
|
296 | - * @param string $filePath |
|
297 | - * @throws FileHelper_Exception |
|
298 | - * |
|
299 | - * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
300 | - */ |
|
292 | + /** |
|
293 | + * Deletes the target file. Ignored if it cannot be found, |
|
294 | + * and throws an exception if it fails. |
|
295 | + * |
|
296 | + * @param string $filePath |
|
297 | + * @throws FileHelper_Exception |
|
298 | + * |
|
299 | + * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
300 | + */ |
|
301 | 301 | public static function deleteFile(string $filePath) : void |
302 | 302 | { |
303 | 303 | if(!file_exists($filePath)) { |
@@ -319,15 +319,15 @@ discard block |
||
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
322 | - * Creates a new CSV parser instance and returns it. |
|
323 | - * |
|
324 | - * @param string $delimiter |
|
325 | - * @param string $enclosure |
|
326 | - * @param string $escape |
|
327 | - * @param bool $heading |
|
328 | - * @return \parseCSV |
|
329 | - * @todo Move this to the CSV helper. |
|
330 | - */ |
|
322 | + * Creates a new CSV parser instance and returns it. |
|
323 | + * |
|
324 | + * @param string $delimiter |
|
325 | + * @param string $enclosure |
|
326 | + * @param string $escape |
|
327 | + * @param bool $heading |
|
328 | + * @return \parseCSV |
|
329 | + * @todo Move this to the CSV helper. |
|
330 | + */ |
|
331 | 331 | public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : \parseCSV |
332 | 332 | { |
333 | 333 | if($delimiter==='') { $delimiter = ';'; } |
@@ -342,23 +342,23 @@ discard block |
||
342 | 342 | return $parser; |
343 | 343 | } |
344 | 344 | |
345 | - /** |
|
346 | - * Parses all lines in the specified string and returns an |
|
347 | - * indexed array with all csv values in each line. |
|
348 | - * |
|
349 | - * @param string $csv |
|
350 | - * @param string $delimiter |
|
351 | - * @param string $enclosure |
|
352 | - * @param string $escape |
|
353 | - * @param bool $heading |
|
354 | - * @return array |
|
355 | - * @throws FileHelper_Exception |
|
356 | - * |
|
357 | - * @todo Move this to the CSVHelper. |
|
358 | - * |
|
359 | - * @see parseCSVFile() |
|
360 | - * @see FileHelper::ERROR_PARSING_CSV |
|
361 | - */ |
|
345 | + /** |
|
346 | + * Parses all lines in the specified string and returns an |
|
347 | + * indexed array with all csv values in each line. |
|
348 | + * |
|
349 | + * @param string $csv |
|
350 | + * @param string $delimiter |
|
351 | + * @param string $enclosure |
|
352 | + * @param string $escape |
|
353 | + * @param bool $heading |
|
354 | + * @return array |
|
355 | + * @throws FileHelper_Exception |
|
356 | + * |
|
357 | + * @todo Move this to the CSVHelper. |
|
358 | + * |
|
359 | + * @see parseCSVFile() |
|
360 | + * @see FileHelper::ERROR_PARSING_CSV |
|
361 | + */ |
|
362 | 362 | public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
363 | 363 | { |
364 | 364 | $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading); |
@@ -537,31 +537,31 @@ discard block |
||
537 | 537 | ); |
538 | 538 | } |
539 | 539 | |
540 | - /** |
|
541 | - * Verifies whether the target file is a PHP file. The path |
|
542 | - * to the file can be a path to a file as a string, or a |
|
543 | - * DirectoryIterator object instance. |
|
544 | - * |
|
545 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
546 | - * @return boolean |
|
547 | - */ |
|
540 | + /** |
|
541 | + * Verifies whether the target file is a PHP file. The path |
|
542 | + * to the file can be a path to a file as a string, or a |
|
543 | + * DirectoryIterator object instance. |
|
544 | + * |
|
545 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
546 | + * @return boolean |
|
547 | + */ |
|
548 | 548 | public static function isPHPFile($pathOrDirIterator) |
549 | 549 | { |
550 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
551 | - return true; |
|
552 | - } |
|
550 | + if(self::getExtension($pathOrDirIterator) == 'php') { |
|
551 | + return true; |
|
552 | + } |
|
553 | 553 | |
554 | - return false; |
|
554 | + return false; |
|
555 | 555 | } |
556 | 556 | |
557 | - /** |
|
558 | - * Retrieves the extension of the specified file. Can be a path |
|
559 | - * to a file as a string, or a DirectoryIterator object instance. |
|
560 | - * |
|
561 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
562 | - * @param bool $lowercase |
|
563 | - * @return string |
|
564 | - */ |
|
557 | + /** |
|
558 | + * Retrieves the extension of the specified file. Can be a path |
|
559 | + * to a file as a string, or a DirectoryIterator object instance. |
|
560 | + * |
|
561 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
562 | + * @param bool $lowercase |
|
563 | + * @return string |
|
564 | + */ |
|
565 | 565 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
566 | 566 | { |
567 | 567 | if($pathOrDirIterator instanceof \DirectoryIterator) { |
@@ -572,51 +572,51 @@ discard block |
||
572 | 572 | |
573 | 573 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
574 | 574 | if($lowercase) { |
575 | - $ext = mb_strtolower($ext); |
|
575 | + $ext = mb_strtolower($ext); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | return $ext; |
579 | 579 | } |
580 | 580 | |
581 | - /** |
|
582 | - * Retrieves the file name from a path, with or without extension. |
|
583 | - * The path to the file can be a string, or a DirectoryIterator object |
|
584 | - * instance. |
|
585 | - * |
|
586 | - * In case of folders, behaves like the pathinfo function: returns |
|
587 | - * the name of the folder. |
|
588 | - * |
|
589 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
590 | - * @param bool $extension |
|
591 | - * @return string |
|
592 | - */ |
|
581 | + /** |
|
582 | + * Retrieves the file name from a path, with or without extension. |
|
583 | + * The path to the file can be a string, or a DirectoryIterator object |
|
584 | + * instance. |
|
585 | + * |
|
586 | + * In case of folders, behaves like the pathinfo function: returns |
|
587 | + * the name of the folder. |
|
588 | + * |
|
589 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
590 | + * @param bool $extension |
|
591 | + * @return string |
|
592 | + */ |
|
593 | 593 | public static function getFilename($pathOrDirIterator, $extension = true) |
594 | 594 | { |
595 | 595 | $path = $pathOrDirIterator; |
596 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
597 | - $path = $pathOrDirIterator->getFilename(); |
|
598 | - } |
|
596 | + if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
597 | + $path = $pathOrDirIterator->getFilename(); |
|
598 | + } |
|
599 | 599 | |
600 | - $path = self::normalizePath($path); |
|
600 | + $path = self::normalizePath($path); |
|
601 | 601 | |
602 | - if(!$extension) { |
|
603 | - return pathinfo($path, PATHINFO_FILENAME); |
|
604 | - } |
|
602 | + if(!$extension) { |
|
603 | + return pathinfo($path, PATHINFO_FILENAME); |
|
604 | + } |
|
605 | 605 | |
606 | - return pathinfo($path, PATHINFO_BASENAME); |
|
606 | + return pathinfo($path, PATHINFO_BASENAME); |
|
607 | 607 | } |
608 | 608 | |
609 | - /** |
|
610 | - * Tries to read the contents of the target file and |
|
611 | - * treat it as JSON to return the decoded JSON data. |
|
612 | - * |
|
613 | - * @param string $file |
|
614 | - * @throws FileHelper_Exception |
|
615 | - * @return array |
|
616 | - * |
|
617 | - * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
|
618 | - * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
|
619 | - */ |
|
609 | + /** |
|
610 | + * Tries to read the contents of the target file and |
|
611 | + * treat it as JSON to return the decoded JSON data. |
|
612 | + * |
|
613 | + * @param string $file |
|
614 | + * @throws FileHelper_Exception |
|
615 | + * @return array |
|
616 | + * |
|
617 | + * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
|
618 | + * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
|
619 | + */ |
|
620 | 620 | public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
621 | 621 | { |
622 | 622 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
@@ -652,16 +652,16 @@ discard block |
||
652 | 652 | return $json; |
653 | 653 | } |
654 | 654 | |
655 | - /** |
|
656 | - * Corrects common formatting mistakes when users enter |
|
657 | - * file names, like too many spaces, dots and the like. |
|
658 | - * |
|
659 | - * NOTE: if the file name contains a path, the path is |
|
660 | - * stripped, leaving only the file name. |
|
661 | - * |
|
662 | - * @param string $name |
|
663 | - * @return string |
|
664 | - */ |
|
655 | + /** |
|
656 | + * Corrects common formatting mistakes when users enter |
|
657 | + * file names, like too many spaces, dots and the like. |
|
658 | + * |
|
659 | + * NOTE: if the file name contains a path, the path is |
|
660 | + * stripped, leaving only the file name. |
|
661 | + * |
|
662 | + * @param string $name |
|
663 | + * @return string |
|
664 | + */ |
|
665 | 665 | public static function fixFileName(string $name) : string |
666 | 666 | { |
667 | 667 | $name = trim($name); |
@@ -691,68 +691,68 @@ discard block |
||
691 | 691 | return $name; |
692 | 692 | } |
693 | 693 | |
694 | - /** |
|
695 | - * Creates an instance of the file finder, which is an easier |
|
696 | - * alternative to the other manual findFile methods, since all |
|
697 | - * options can be set by chaining. |
|
698 | - * |
|
699 | - * @param string $path |
|
700 | - * @return FileHelper_FileFinder |
|
701 | - */ |
|
694 | + /** |
|
695 | + * Creates an instance of the file finder, which is an easier |
|
696 | + * alternative to the other manual findFile methods, since all |
|
697 | + * options can be set by chaining. |
|
698 | + * |
|
699 | + * @param string $path |
|
700 | + * @return FileHelper_FileFinder |
|
701 | + */ |
|
702 | 702 | public static function createFileFinder(string $path) : FileHelper_FileFinder |
703 | 703 | { |
704 | 704 | return new FileHelper_FileFinder($path); |
705 | 705 | } |
706 | 706 | |
707 | - /** |
|
708 | - * Searches for all HTML files in the target folder. |
|
709 | - * |
|
710 | - * NOTE: This method only exists for backwards compatibility. |
|
711 | - * Use the `createFileFinder()` method instead, which offers |
|
712 | - * an object oriented interface that is much easier to use. |
|
713 | - * |
|
714 | - * @param string $targetFolder |
|
715 | - * @param array $options |
|
716 | - * @return array An indexed array with files. |
|
717 | - * @see FileHelper::createFileFinder() |
|
718 | - */ |
|
707 | + /** |
|
708 | + * Searches for all HTML files in the target folder. |
|
709 | + * |
|
710 | + * NOTE: This method only exists for backwards compatibility. |
|
711 | + * Use the `createFileFinder()` method instead, which offers |
|
712 | + * an object oriented interface that is much easier to use. |
|
713 | + * |
|
714 | + * @param string $targetFolder |
|
715 | + * @param array $options |
|
716 | + * @return array An indexed array with files. |
|
717 | + * @see FileHelper::createFileFinder() |
|
718 | + */ |
|
719 | 719 | public static function findHTMLFiles(string $targetFolder, array $options=array()) : array |
720 | 720 | { |
721 | 721 | return self::findFiles($targetFolder, array('html'), $options); |
722 | 722 | } |
723 | 723 | |
724 | - /** |
|
725 | - * Searches for all PHP files in the target folder. |
|
726 | - * |
|
727 | - * NOTE: This method only exists for backwards compatibility. |
|
728 | - * Use the `createFileFinder()` method instead, which offers |
|
729 | - * an object oriented interface that is much easier to use. |
|
730 | - * |
|
731 | - * @param string $targetFolder |
|
732 | - * @param array $options |
|
733 | - * @return array An indexed array of PHP files. |
|
734 | - * @see FileHelper::createFileFinder() |
|
735 | - */ |
|
724 | + /** |
|
725 | + * Searches for all PHP files in the target folder. |
|
726 | + * |
|
727 | + * NOTE: This method only exists for backwards compatibility. |
|
728 | + * Use the `createFileFinder()` method instead, which offers |
|
729 | + * an object oriented interface that is much easier to use. |
|
730 | + * |
|
731 | + * @param string $targetFolder |
|
732 | + * @param array $options |
|
733 | + * @return array An indexed array of PHP files. |
|
734 | + * @see FileHelper::createFileFinder() |
|
735 | + */ |
|
736 | 736 | public static function findPHPFiles(string $targetFolder, array $options=array()) : array |
737 | 737 | { |
738 | 738 | return self::findFiles($targetFolder, array('php'), $options); |
739 | 739 | } |
740 | 740 | |
741 | - /** |
|
742 | - * Finds files according to the specified options. |
|
743 | - * |
|
744 | - * NOTE: This method only exists for backwards compatibility. |
|
745 | - * Use the `createFileFinder()` method instead, which offers |
|
746 | - * an object oriented interface that is much easier to use. |
|
747 | - * |
|
748 | - * @param string $targetFolder |
|
749 | - * @param array $extensions |
|
750 | - * @param array $options |
|
751 | - * @param array $files |
|
752 | - * @throws FileHelper_Exception |
|
753 | - * @return array |
|
754 | - * @see FileHelper::createFileFinder() |
|
755 | - */ |
|
741 | + /** |
|
742 | + * Finds files according to the specified options. |
|
743 | + * |
|
744 | + * NOTE: This method only exists for backwards compatibility. |
|
745 | + * Use the `createFileFinder()` method instead, which offers |
|
746 | + * an object oriented interface that is much easier to use. |
|
747 | + * |
|
748 | + * @param string $targetFolder |
|
749 | + * @param array $extensions |
|
750 | + * @param array $options |
|
751 | + * @param array $files |
|
752 | + * @throws FileHelper_Exception |
|
753 | + * @return array |
|
754 | + * @see FileHelper::createFileFinder() |
|
755 | + */ |
|
756 | 756 | public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array |
757 | 757 | { |
758 | 758 | $finder = self::createFileFinder($targetFolder); |
@@ -776,13 +776,13 @@ discard block |
||
776 | 776 | return $files; |
777 | 777 | } |
778 | 778 | |
779 | - /** |
|
780 | - * Removes the extension from the specified path or file name, |
|
781 | - * if any, and returns the name without the extension. |
|
782 | - * |
|
783 | - * @param string $filename |
|
784 | - * @return sTring |
|
785 | - */ |
|
779 | + /** |
|
780 | + * Removes the extension from the specified path or file name, |
|
781 | + * if any, and returns the name without the extension. |
|
782 | + * |
|
783 | + * @param string $filename |
|
784 | + * @return sTring |
|
785 | + */ |
|
786 | 786 | public static function removeExtension(string $filename) : string |
787 | 787 | { |
788 | 788 | // normalize paths to allow windows style slashes even on nix servers |
@@ -791,22 +791,22 @@ discard block |
||
791 | 791 | return pathinfo($filename, PATHINFO_FILENAME); |
792 | 792 | } |
793 | 793 | |
794 | - /** |
|
795 | - * Detects the UTF BOM in the target file, if any. Returns |
|
796 | - * the encoding matching the BOM, which can be any of the |
|
797 | - * following: |
|
798 | - * |
|
799 | - * <ul> |
|
800 | - * <li>UTF32-BE</li> |
|
801 | - * <li>UTF32-LE</li> |
|
802 | - * <li>UTF16-BE</li> |
|
803 | - * <li>UTF16-LE</li> |
|
804 | - * <li>UTF8</li> |
|
805 | - * </ul> |
|
806 | - * |
|
807 | - * @param string $filename |
|
808 | - * @return string|NULL |
|
809 | - */ |
|
794 | + /** |
|
795 | + * Detects the UTF BOM in the target file, if any. Returns |
|
796 | + * the encoding matching the BOM, which can be any of the |
|
797 | + * following: |
|
798 | + * |
|
799 | + * <ul> |
|
800 | + * <li>UTF32-BE</li> |
|
801 | + * <li>UTF32-LE</li> |
|
802 | + * <li>UTF16-BE</li> |
|
803 | + * <li>UTF16-LE</li> |
|
804 | + * <li>UTF8</li> |
|
805 | + * </ul> |
|
806 | + * |
|
807 | + * @param string $filename |
|
808 | + * @return string|NULL |
|
809 | + */ |
|
810 | 810 | public static function detectUTFBom(string $filename) : ?string |
811 | 811 | { |
812 | 812 | $fp = fopen($filename, 'r'); |
@@ -838,13 +838,13 @@ discard block |
||
838 | 838 | |
839 | 839 | protected static $utfBoms; |
840 | 840 | |
841 | - /** |
|
842 | - * Retrieves a list of all UTF byte order mark character |
|
843 | - * sequences, as an assocative array with UTF encoding => bom sequence |
|
844 | - * pairs. |
|
845 | - * |
|
846 | - * @return array |
|
847 | - */ |
|
841 | + /** |
|
842 | + * Retrieves a list of all UTF byte order mark character |
|
843 | + * sequences, as an assocative array with UTF encoding => bom sequence |
|
844 | + * pairs. |
|
845 | + * |
|
846 | + * @return array |
|
847 | + */ |
|
848 | 848 | public static function getUTFBOMs() |
849 | 849 | { |
850 | 850 | if(!isset(self::$utfBoms)) { |
@@ -860,15 +860,15 @@ discard block |
||
860 | 860 | return self::$utfBoms; |
861 | 861 | } |
862 | 862 | |
863 | - /** |
|
864 | - * Checks whether the specified encoding is a valid |
|
865 | - * unicode encoding, for example "UTF16-LE" or "UTF8". |
|
866 | - * Also accounts for alternate way to write the, like |
|
867 | - * "UTF-8", and omitting little/big endian suffixes. |
|
868 | - * |
|
869 | - * @param string $encoding |
|
870 | - * @return boolean |
|
871 | - */ |
|
863 | + /** |
|
864 | + * Checks whether the specified encoding is a valid |
|
865 | + * unicode encoding, for example "UTF16-LE" or "UTF8". |
|
866 | + * Also accounts for alternate way to write the, like |
|
867 | + * "UTF-8", and omitting little/big endian suffixes. |
|
868 | + * |
|
869 | + * @param string $encoding |
|
870 | + * @return boolean |
|
871 | + */ |
|
872 | 872 | public static function isValidUnicodeEncoding(string $encoding) : bool |
873 | 873 | { |
874 | 874 | $encodings = self::getKnownUnicodeEncodings(); |
@@ -887,40 +887,40 @@ discard block |
||
887 | 887 | return in_array($encoding, $keep); |
888 | 888 | } |
889 | 889 | |
890 | - /** |
|
891 | - * Retrieves a list of all known unicode file encodings. |
|
892 | - * @return array |
|
893 | - */ |
|
890 | + /** |
|
891 | + * Retrieves a list of all known unicode file encodings. |
|
892 | + * @return array |
|
893 | + */ |
|
894 | 894 | public static function getKnownUnicodeEncodings() |
895 | 895 | { |
896 | 896 | return array_keys(self::getUTFBOMs()); |
897 | 897 | } |
898 | 898 | |
899 | - /** |
|
900 | - * Normalizes the slash style in a file or folder path, |
|
901 | - * by replacing any antislashes with forward slashes. |
|
902 | - * |
|
903 | - * @param string $path |
|
904 | - * @return string |
|
905 | - */ |
|
899 | + /** |
|
900 | + * Normalizes the slash style in a file or folder path, |
|
901 | + * by replacing any antislashes with forward slashes. |
|
902 | + * |
|
903 | + * @param string $path |
|
904 | + * @return string |
|
905 | + */ |
|
906 | 906 | public static function normalizePath(string $path) : string |
907 | 907 | { |
908 | 908 | return str_replace(array('\\', '//'), array('/', '/'), $path); |
909 | 909 | } |
910 | 910 | |
911 | - /** |
|
912 | - * Saves the specified data to a file, JSON encoded. |
|
913 | - * |
|
914 | - * @param mixed $data |
|
915 | - * @param string $file |
|
916 | - * @param bool $pretty |
|
917 | - * @throws FileHelper_Exception |
|
918 | - * |
|
919 | - * @see FileHelper::ERROR_JSON_ENCODE_ERROR |
|
920 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
921 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
922 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
923 | - */ |
|
911 | + /** |
|
912 | + * Saves the specified data to a file, JSON encoded. |
|
913 | + * |
|
914 | + * @param mixed $data |
|
915 | + * @param string $file |
|
916 | + * @param bool $pretty |
|
917 | + * @throws FileHelper_Exception |
|
918 | + * |
|
919 | + * @see FileHelper::ERROR_JSON_ENCODE_ERROR |
|
920 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
921 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
922 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
923 | + */ |
|
924 | 924 | public static function saveAsJSON($data, string $file, bool $pretty=false) |
925 | 925 | { |
926 | 926 | $options = null; |
@@ -944,18 +944,18 @@ discard block |
||
944 | 944 | self::saveFile($file, $json); |
945 | 945 | } |
946 | 946 | |
947 | - /** |
|
948 | - * Saves the specified content to the target file, creating |
|
949 | - * the file and the folder as necessary. |
|
950 | - * |
|
951 | - * @param string $filePath |
|
952 | - * @param string $content |
|
953 | - * @throws FileHelper_Exception |
|
954 | - * |
|
955 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
956 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
957 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
958 | - */ |
|
947 | + /** |
|
948 | + * Saves the specified content to the target file, creating |
|
949 | + * the file and the folder as necessary. |
|
950 | + * |
|
951 | + * @param string $filePath |
|
952 | + * @param string $content |
|
953 | + * @throws FileHelper_Exception |
|
954 | + * |
|
955 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
956 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
957 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
958 | + */ |
|
959 | 959 | public static function saveFile(string $filePath, string $content='') : void |
960 | 960 | { |
961 | 961 | // target file already exists |
@@ -1008,12 +1008,12 @@ discard block |
||
1008 | 1008 | ); |
1009 | 1009 | } |
1010 | 1010 | |
1011 | - /** |
|
1012 | - * Checks whether it is possible to run PHP command |
|
1013 | - * line commands. |
|
1014 | - * |
|
1015 | - * @return boolean |
|
1016 | - */ |
|
1011 | + /** |
|
1012 | + * Checks whether it is possible to run PHP command |
|
1013 | + * line commands. |
|
1014 | + * |
|
1015 | + * @return boolean |
|
1016 | + */ |
|
1017 | 1017 | public static function canMakePHPCalls() : bool |
1018 | 1018 | { |
1019 | 1019 | return self::cliCommandExists('php'); |
@@ -1090,16 +1090,16 @@ discard block |
||
1090 | 1090 | return $result; |
1091 | 1091 | } |
1092 | 1092 | |
1093 | - /** |
|
1094 | - * Validates a PHP file's syntax. |
|
1095 | - * |
|
1096 | - * NOTE: This will fail silently if the PHP command line |
|
1097 | - * is not available. Use {@link FileHelper::canMakePHPCalls()} |
|
1098 | - * to check this beforehand as needed. |
|
1099 | - * |
|
1100 | - * @param string $path |
|
1101 | - * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise. |
|
1102 | - */ |
|
1093 | + /** |
|
1094 | + * Validates a PHP file's syntax. |
|
1095 | + * |
|
1096 | + * NOTE: This will fail silently if the PHP command line |
|
1097 | + * is not available. Use {@link FileHelper::canMakePHPCalls()} |
|
1098 | + * to check this beforehand as needed. |
|
1099 | + * |
|
1100 | + * @param string $path |
|
1101 | + * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise. |
|
1102 | + */ |
|
1103 | 1103 | public static function checkPHPFileSyntax($path) |
1104 | 1104 | { |
1105 | 1105 | if(!self::canMakePHPCalls()) { |
@@ -1123,14 +1123,14 @@ discard block |
||
1123 | 1123 | return $output; |
1124 | 1124 | } |
1125 | 1125 | |
1126 | - /** |
|
1127 | - * Retrieves the last modified date for the specified file or folder. |
|
1128 | - * |
|
1129 | - * Note: If the target does not exist, returns null. |
|
1130 | - * |
|
1131 | - * @param string $path |
|
1132 | - * @return \DateTime|NULL |
|
1133 | - */ |
|
1126 | + /** |
|
1127 | + * Retrieves the last modified date for the specified file or folder. |
|
1128 | + * |
|
1129 | + * Note: If the target does not exist, returns null. |
|
1130 | + * |
|
1131 | + * @param string $path |
|
1132 | + * @return \DateTime|NULL |
|
1133 | + */ |
|
1134 | 1134 | public static function getModifiedDate($path) |
1135 | 1135 | { |
1136 | 1136 | $time = filemtime($path); |
@@ -1143,24 +1143,24 @@ discard block |
||
1143 | 1143 | return null; |
1144 | 1144 | } |
1145 | 1145 | |
1146 | - /** |
|
1147 | - * Retrieves the names of all subfolders in the specified path. |
|
1148 | - * |
|
1149 | - * Available options: |
|
1150 | - * |
|
1151 | - * - recursive: true/false |
|
1152 | - * Whether to search for subfolders recursively. |
|
1153 | - * |
|
1154 | - * - absolute-paths: true/false |
|
1155 | - * Whether to return a list of absolute paths. |
|
1156 | - * |
|
1157 | - * @param string $targetFolder |
|
1158 | - * @param array $options |
|
1159 | - * @throws FileHelper_Exception |
|
1160 | - * @return string[] |
|
1161 | - * |
|
1162 | - * @todo Move this to a separate class. |
|
1163 | - */ |
|
1146 | + /** |
|
1147 | + * Retrieves the names of all subfolders in the specified path. |
|
1148 | + * |
|
1149 | + * Available options: |
|
1150 | + * |
|
1151 | + * - recursive: true/false |
|
1152 | + * Whether to search for subfolders recursively. |
|
1153 | + * |
|
1154 | + * - absolute-paths: true/false |
|
1155 | + * Whether to return a list of absolute paths. |
|
1156 | + * |
|
1157 | + * @param string $targetFolder |
|
1158 | + * @param array $options |
|
1159 | + * @throws FileHelper_Exception |
|
1160 | + * @return string[] |
|
1161 | + * |
|
1162 | + * @todo Move this to a separate class. |
|
1163 | + */ |
|
1164 | 1164 | public static function getSubfolders($targetFolder, $options = array()) |
1165 | 1165 | { |
1166 | 1166 | if(!is_dir($targetFolder)) |
@@ -1221,16 +1221,16 @@ discard block |
||
1221 | 1221 | return $result; |
1222 | 1222 | } |
1223 | 1223 | |
1224 | - /** |
|
1225 | - * Retrieves the maximum allowed upload file size, in bytes. |
|
1226 | - * Takes into account the PHP ini settings <code>post_max_size</code> |
|
1227 | - * and <code>upload_max_filesize</code>. Since these cannot |
|
1228 | - * be modified at runtime, they are the hard limits for uploads. |
|
1229 | - * |
|
1230 | - * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
1231 | - * |
|
1232 | - * @return int Will return <code>-1</code> if no limit. |
|
1233 | - */ |
|
1224 | + /** |
|
1225 | + * Retrieves the maximum allowed upload file size, in bytes. |
|
1226 | + * Takes into account the PHP ini settings <code>post_max_size</code> |
|
1227 | + * and <code>upload_max_filesize</code>. Since these cannot |
|
1228 | + * be modified at runtime, they are the hard limits for uploads. |
|
1229 | + * |
|
1230 | + * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
1231 | + * |
|
1232 | + * @return int Will return <code>-1</code> if no limit. |
|
1233 | + */ |
|
1234 | 1234 | public static function getMaxUploadFilesize() : int |
1235 | 1235 | { |
1236 | 1236 | static $max_size = -1; |
@@ -1267,16 +1267,16 @@ discard block |
||
1267 | 1267 | return round($size); |
1268 | 1268 | } |
1269 | 1269 | |
1270 | - /** |
|
1271 | - * Makes a path relative using a folder depth: will reduce the |
|
1272 | - * length of the path so that only the amount of folders defined |
|
1273 | - * in the <code>$depth</code> attribute are shown below the actual |
|
1274 | - * folder or file in the path. |
|
1275 | - * |
|
1276 | - * @param string $path The absolute or relative path |
|
1277 | - * @param int $depth The folder depth to reduce the path to |
|
1278 | - * @return string |
|
1279 | - */ |
|
1270 | + /** |
|
1271 | + * Makes a path relative using a folder depth: will reduce the |
|
1272 | + * length of the path so that only the amount of folders defined |
|
1273 | + * in the <code>$depth</code> attribute are shown below the actual |
|
1274 | + * folder or file in the path. |
|
1275 | + * |
|
1276 | + * @param string $path The absolute or relative path |
|
1277 | + * @param int $depth The folder depth to reduce the path to |
|
1278 | + * @return string |
|
1279 | + */ |
|
1280 | 1280 | public static function relativizePathByDepth(string $path, int $depth=2) : string |
1281 | 1281 | { |
1282 | 1282 | $path = self::normalizePath($path); |
@@ -1314,23 +1314,23 @@ discard block |
||
1314 | 1314 | return trim(implode('/', $tokens), '/'); |
1315 | 1315 | } |
1316 | 1316 | |
1317 | - /** |
|
1318 | - * Makes the specified path relative to another path, |
|
1319 | - * by removing one from the other if found. Also |
|
1320 | - * normalizes the path to use forward slashes. |
|
1321 | - * |
|
1322 | - * Example: |
|
1323 | - * |
|
1324 | - * <pre> |
|
1325 | - * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
1326 | - * </pre> |
|
1327 | - * |
|
1328 | - * Result: <code>to/file.txt</code> |
|
1329 | - * |
|
1330 | - * @param string $path |
|
1331 | - * @param string $relativeTo |
|
1332 | - * @return string |
|
1333 | - */ |
|
1317 | + /** |
|
1318 | + * Makes the specified path relative to another path, |
|
1319 | + * by removing one from the other if found. Also |
|
1320 | + * normalizes the path to use forward slashes. |
|
1321 | + * |
|
1322 | + * Example: |
|
1323 | + * |
|
1324 | + * <pre> |
|
1325 | + * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
1326 | + * </pre> |
|
1327 | + * |
|
1328 | + * Result: <code>to/file.txt</code> |
|
1329 | + * |
|
1330 | + * @param string $path |
|
1331 | + * @param string $relativeTo |
|
1332 | + * @return string |
|
1333 | + */ |
|
1334 | 1334 | public static function relativizePath(string $path, string $relativeTo) : string |
1335 | 1335 | { |
1336 | 1336 | $path = self::normalizePath($path); |
@@ -1342,17 +1342,17 @@ discard block |
||
1342 | 1342 | return $relative; |
1343 | 1343 | } |
1344 | 1344 | |
1345 | - /** |
|
1346 | - * Checks that the target file exists, and throws an exception |
|
1347 | - * if it does not. |
|
1348 | - * |
|
1349 | - * @param string $path |
|
1350 | - * @param int|NULL $errorCode Optional custom error code |
|
1351 | - * @throws FileHelper_Exception |
|
1352 | - * @return string The real path to the file |
|
1353 | - * |
|
1354 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1355 | - */ |
|
1345 | + /** |
|
1346 | + * Checks that the target file exists, and throws an exception |
|
1347 | + * if it does not. |
|
1348 | + * |
|
1349 | + * @param string $path |
|
1350 | + * @param int|NULL $errorCode Optional custom error code |
|
1351 | + * @throws FileHelper_Exception |
|
1352 | + * @return string The real path to the file |
|
1353 | + * |
|
1354 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1355 | + */ |
|
1356 | 1356 | public static function requireFileExists(string $path, $errorCode=null) : string |
1357 | 1357 | { |
1358 | 1358 | $result = realpath($path); |
@@ -1371,18 +1371,18 @@ discard block |
||
1371 | 1371 | ); |
1372 | 1372 | } |
1373 | 1373 | |
1374 | - /** |
|
1375 | - * Reads a specific line number from the target file and returns its |
|
1376 | - * contents, if the file has such a line. Does so with little memory |
|
1377 | - * usage, as the file is not read entirely into memory. |
|
1378 | - * |
|
1379 | - * @param string $path |
|
1380 | - * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
1381 | - * @return string|NULL Will return null if the requested line does not exist. |
|
1382 | - * @throws FileHelper_Exception |
|
1383 | - * |
|
1384 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1385 | - */ |
|
1374 | + /** |
|
1375 | + * Reads a specific line number from the target file and returns its |
|
1376 | + * contents, if the file has such a line. Does so with little memory |
|
1377 | + * usage, as the file is not read entirely into memory. |
|
1378 | + * |
|
1379 | + * @param string $path |
|
1380 | + * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
1381 | + * @return string|NULL Will return null if the requested line does not exist. |
|
1382 | + * @throws FileHelper_Exception |
|
1383 | + * |
|
1384 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1385 | + */ |
|
1386 | 1386 | public static function getLineFromFile(string $path, int $lineNumber) : ?string |
1387 | 1387 | { |
1388 | 1388 | self::requireFileExists($path); |
@@ -1398,19 +1398,19 @@ discard block |
||
1398 | 1398 | $file->seek($targetLine); |
1399 | 1399 | |
1400 | 1400 | if($file->key() !== $targetLine) { |
1401 | - return null; |
|
1401 | + return null; |
|
1402 | 1402 | } |
1403 | 1403 | |
1404 | 1404 | return $file->current(); |
1405 | 1405 | } |
1406 | 1406 | |
1407 | - /** |
|
1408 | - * Retrieves the total amount of lines in the file, without |
|
1409 | - * reading the whole file into memory. |
|
1410 | - * |
|
1411 | - * @param string $path |
|
1412 | - * @return int |
|
1413 | - */ |
|
1407 | + /** |
|
1408 | + * Retrieves the total amount of lines in the file, without |
|
1409 | + * reading the whole file into memory. |
|
1410 | + * |
|
1411 | + * @param string $path |
|
1412 | + * @return int |
|
1413 | + */ |
|
1414 | 1414 | public static function countFileLines(string $path) : int |
1415 | 1415 | { |
1416 | 1416 | self::requireFileExists($path); |
@@ -1440,26 +1440,26 @@ discard block |
||
1440 | 1440 | return $number+1; |
1441 | 1441 | } |
1442 | 1442 | |
1443 | - /** |
|
1444 | - * Parses the target file to detect any PHP classes contained |
|
1445 | - * within, and retrieve information on them. Does not use the |
|
1446 | - * PHP reflection API. |
|
1447 | - * |
|
1448 | - * @param string $filePath |
|
1449 | - * @return FileHelper_PHPClassInfo |
|
1450 | - */ |
|
1443 | + /** |
|
1444 | + * Parses the target file to detect any PHP classes contained |
|
1445 | + * within, and retrieve information on them. Does not use the |
|
1446 | + * PHP reflection API. |
|
1447 | + * |
|
1448 | + * @param string $filePath |
|
1449 | + * @return FileHelper_PHPClassInfo |
|
1450 | + */ |
|
1451 | 1451 | public static function findPHPClasses(string $filePath) : FileHelper_PHPClassInfo |
1452 | 1452 | { |
1453 | 1453 | return new FileHelper_PHPClassInfo($filePath); |
1454 | 1454 | } |
1455 | 1455 | |
1456 | - /** |
|
1457 | - * Detects the end of line style used in the target file, if any. |
|
1458 | - * Can be used with large files, because it only reads part of it. |
|
1459 | - * |
|
1460 | - * @param string $filePath The path to the file. |
|
1461 | - * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found. |
|
1462 | - */ |
|
1456 | + /** |
|
1457 | + * Detects the end of line style used in the target file, if any. |
|
1458 | + * Can be used with large files, because it only reads part of it. |
|
1459 | + * |
|
1460 | + * @param string $filePath The path to the file. |
|
1461 | + * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found. |
|
1462 | + */ |
|
1463 | 1463 | public static function detectEOLCharacter(string $filePath) : ?ConvertHelper_EOL |
1464 | 1464 | { |
1465 | 1465 | // 20 lines is enough to get a good picture of the newline style in the file. |
@@ -1472,18 +1472,18 @@ discard block |
||
1472 | 1472 | return ConvertHelper::detectEOLCharacter($string); |
1473 | 1473 | } |
1474 | 1474 | |
1475 | - /** |
|
1476 | - * Reads the specified amount of lines from the target file. |
|
1477 | - * Unicode BOM compatible: any byte order marker is stripped |
|
1478 | - * from the resulting lines. |
|
1479 | - * |
|
1480 | - * @param string $filePath |
|
1481 | - * @param int $amount Set to 0 to read all lines. |
|
1482 | - * @return array |
|
1483 | - * |
|
1484 | - * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
|
1485 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1486 | - */ |
|
1475 | + /** |
|
1476 | + * Reads the specified amount of lines from the target file. |
|
1477 | + * Unicode BOM compatible: any byte order marker is stripped |
|
1478 | + * from the resulting lines. |
|
1479 | + * |
|
1480 | + * @param string $filePath |
|
1481 | + * @param int $amount Set to 0 to read all lines. |
|
1482 | + * @return array |
|
1483 | + * |
|
1484 | + * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
|
1485 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1486 | + */ |
|
1487 | 1487 | public static function readLines(string $filePath, int $amount=0) : array |
1488 | 1488 | { |
1489 | 1489 | self::requireFileExists($filePath); |
@@ -1534,16 +1534,16 @@ discard block |
||
1534 | 1534 | return $result; |
1535 | 1535 | } |
1536 | 1536 | |
1537 | - /** |
|
1538 | - * Reads all content from a file. |
|
1539 | - * |
|
1540 | - * @param string $filePath |
|
1541 | - * @throws FileHelper_Exception |
|
1542 | - * @return string |
|
1543 | - * |
|
1544 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1545 | - * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
1546 | - */ |
|
1537 | + /** |
|
1538 | + * Reads all content from a file. |
|
1539 | + * |
|
1540 | + * @param string $filePath |
|
1541 | + * @throws FileHelper_Exception |
|
1542 | + * @return string |
|
1543 | + * |
|
1544 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1545 | + * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
1546 | + */ |
|
1547 | 1547 | public static function readContents(string $filePath) : string |
1548 | 1548 | { |
1549 | 1549 | self::requireFileExists($filePath); |