@@ -22,19 +22,19 @@ discard block |
||
22 | 22 | { |
23 | 23 | const ERROR_NO_BOUNDARIES_SPECIFIED = 44401; |
24 | 24 | |
25 | - /** |
|
26 | - * @var RequestHelper |
|
27 | - */ |
|
25 | + /** |
|
26 | + * @var RequestHelper |
|
27 | + */ |
|
28 | 28 | protected $helper; |
29 | 29 | |
30 | - /** |
|
31 | - * @var RequestHelper_Boundaries_Boundary[] |
|
32 | - */ |
|
30 | + /** |
|
31 | + * @var RequestHelper_Boundaries_Boundary[] |
|
32 | + */ |
|
33 | 33 | protected $boundaries = array(); |
34 | 34 | |
35 | - /** |
|
36 | - * @var integer |
|
37 | - */ |
|
35 | + /** |
|
36 | + * @var integer |
|
37 | + */ |
|
38 | 38 | protected $contentLength = 0; |
39 | 39 | |
40 | 40 | public function __construct(RequestHelper $helper) |
@@ -42,45 +42,45 @@ discard block |
||
42 | 42 | $this->helper = $helper; |
43 | 43 | } |
44 | 44 | |
45 | - /** |
|
46 | - * Retrieves the string that is used to separate mime boundaries in the body. |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
45 | + /** |
|
46 | + * Retrieves the string that is used to separate mime boundaries in the body. |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | 50 | public function getMimeBoundary() : string |
51 | 51 | { |
52 | 52 | return $this->helper->getMimeBoundary(); |
53 | 53 | } |
54 | 54 | |
55 | - /** |
|
56 | - * Retrieves the end of line character(s) used in the body. |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
55 | + /** |
|
56 | + * Retrieves the end of line character(s) used in the body. |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | 60 | public function getEOL() : string |
61 | 61 | { |
62 | 62 | return $this->helper->getEOL(); |
63 | 63 | } |
64 | 64 | |
65 | - /** |
|
66 | - * Retrieves the total content length of all boundary contents. |
|
67 | - * |
|
68 | - * @return int |
|
69 | - */ |
|
65 | + /** |
|
66 | + * Retrieves the total content length of all boundary contents. |
|
67 | + * |
|
68 | + * @return int |
|
69 | + */ |
|
70 | 70 | public function getContentLength() : int |
71 | 71 | { |
72 | 72 | return $this->contentLength; |
73 | 73 | } |
74 | 74 | |
75 | - /** |
|
76 | - * Adds a file to be sent with the request. |
|
77 | - * |
|
78 | - * @param string $varName The variable name to send the file in |
|
79 | - * @param string $fileName The name of the file as it should be received at the destination |
|
80 | - * @param string $content The raw content of the file |
|
81 | - * @param string $contentType The content type, use the constants to specify this |
|
82 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
83 | - */ |
|
75 | + /** |
|
76 | + * Adds a file to be sent with the request. |
|
77 | + * |
|
78 | + * @param string $varName The variable name to send the file in |
|
79 | + * @param string $fileName The name of the file as it should be received at the destination |
|
80 | + * @param string $content The raw content of the file |
|
81 | + * @param string $contentType The content type, use the constants to specify this |
|
82 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
83 | + */ |
|
84 | 84 | public function addFile(string $varName, string $fileName, string $content, string $contentType = RequestHelper::FILETYPE_TEXT, string $encoding = RequestHelper::ENCODING_UTF8) : RequestHelper_Boundaries |
85 | 85 | { |
86 | 86 | $boundary = $this->createBoundary(chunk_split(base64_encode($content))) |
@@ -92,13 +92,13 @@ discard block |
||
92 | 92 | return $this->addBoundary($boundary); |
93 | 93 | } |
94 | 94 | |
95 | - /** |
|
96 | - * Adds arbitrary content. |
|
97 | - * |
|
98 | - * @param string $varName |
|
99 | - * @param string $content |
|
100 | - * @param string $contentType |
|
101 | - */ |
|
95 | + /** |
|
96 | + * Adds arbitrary content. |
|
97 | + * |
|
98 | + * @param string $varName |
|
99 | + * @param string $content |
|
100 | + * @param string $contentType |
|
101 | + */ |
|
102 | 102 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper_Boundaries |
103 | 103 | { |
104 | 104 | $boundary = $this->createBoundary($content) |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | return $this->addBoundary($boundary); |
110 | 110 | } |
111 | 111 | |
112 | - /** |
|
113 | - * Adds a variable to be sent with the request. If it |
|
114 | - * already exists, its value is overwritten. |
|
115 | - * |
|
116 | - * @param string $name |
|
117 | - * @param string $value |
|
118 | - */ |
|
112 | + /** |
|
113 | + * Adds a variable to be sent with the request. If it |
|
114 | + * already exists, its value is overwritten. |
|
115 | + * |
|
116 | + * @param string $name |
|
117 | + * @param string $value |
|
118 | + */ |
|
119 | 119 | public function addVariable(string $name, string $value) : RequestHelper_Boundaries |
120 | 120 | { |
121 | 121 | $boundary = $this->createBoundary($value) |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | return $this; |
133 | 133 | } |
134 | 134 | |
135 | - /** |
|
136 | - * Renders the response body with all mime boundaries. |
|
137 | - * |
|
138 | - * @return string |
|
139 | - */ |
|
135 | + /** |
|
136 | + * Renders the response body with all mime boundaries. |
|
137 | + * |
|
138 | + * @return string |
|
139 | + */ |
|
140 | 140 | public function render() : string |
141 | 141 | { |
142 | 142 | if(empty($this->boundaries)) |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function render() : string |
141 | 141 | { |
142 | - if(empty($this->boundaries)) |
|
142 | + if (empty($this->boundaries)) |
|
143 | 143 | { |
144 | 144 | throw new RequestHelper_Exception( |
145 | 145 | 'No mime boundaries added', |
@@ -150,13 +150,13 @@ discard block |
||
150 | 150 | |
151 | 151 | $result = ''; |
152 | 152 | |
153 | - foreach($this->boundaries as $boundary) |
|
153 | + foreach ($this->boundaries as $boundary) |
|
154 | 154 | { |
155 | 155 | $result .= $boundary->render(); |
156 | 156 | } |
157 | 157 | |
158 | - $result .= "--" . $this->getMimeBoundary() . "--" . |
|
159 | - $this->getEOL() . $this->getEOL(); // always finish with two eol's!! |
|
158 | + $result .= "--".$this->getMimeBoundary()."--". |
|
159 | + $this->getEOL().$this->getEOL(); // always finish with two eol's!! |
|
160 | 160 | |
161 | 161 | return $result; |
162 | 162 | } |
@@ -32,23 +32,23 @@ |
||
32 | 32 | $this->info = $info; |
33 | 33 | } |
34 | 34 | |
35 | - /** |
|
36 | - * Enables the authentication information in the URL, |
|
37 | - * if a username and password are present. |
|
38 | - * |
|
39 | - * @param bool $enable Whether to turn it on or off. |
|
40 | - * @return URLInfo_Normalizer |
|
41 | - */ |
|
35 | + /** |
|
36 | + * Enables the authentication information in the URL, |
|
37 | + * if a username and password are present. |
|
38 | + * |
|
39 | + * @param bool $enable Whether to turn it on or off. |
|
40 | + * @return URLInfo_Normalizer |
|
41 | + */ |
|
42 | 42 | public function enableAuth(bool $enable=true) : URLInfo_Normalizer |
43 | 43 | { |
44 | 44 | $this->auth = $enable; |
45 | 45 | return $this; |
46 | 46 | } |
47 | 47 | |
48 | - /** |
|
49 | - * Retrieves the normalized URL. |
|
50 | - * @return string |
|
51 | - */ |
|
48 | + /** |
|
49 | + * Retrieves the normalized URL. |
|
50 | + * @return string |
|
51 | + */ |
|
52 | 52 | public function normalize() : string |
53 | 53 | { |
54 | 54 | $method = 'normalize_'.$this->info->getType(); |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param bool $enable Whether to turn it on or off. |
40 | 40 | * @return URLInfo_Normalizer |
41 | 41 | */ |
42 | - public function enableAuth(bool $enable=true) : URLInfo_Normalizer |
|
42 | + public function enableAuth(bool $enable = true) : URLInfo_Normalizer |
|
43 | 43 | { |
44 | 44 | $this->auth = $enable; |
45 | 45 | return $this; |
@@ -86,48 +86,48 @@ discard block |
||
86 | 86 | |
87 | 87 | protected function renderAuth(string $normalized) : string |
88 | 88 | { |
89 | - if(!$this->info->hasUsername() || !$this->auth) { |
|
89 | + if (!$this->info->hasUsername() || !$this->auth) { |
|
90 | 90 | return $normalized; |
91 | 91 | } |
92 | 92 | |
93 | - return $normalized . urlencode($this->info->getUsername()).':'.urlencode($this->info->getPassword()).'@'; |
|
93 | + return $normalized.urlencode($this->info->getUsername()).':'.urlencode($this->info->getPassword()).'@'; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | protected function renderPort(string $normalized) : string |
97 | 97 | { |
98 | - if(!$this->info->hasPort()) { |
|
98 | + if (!$this->info->hasPort()) { |
|
99 | 99 | return $normalized; |
100 | 100 | } |
101 | 101 | |
102 | - return $normalized . ':'.$this->info->getPort(); |
|
102 | + return $normalized.':'.$this->info->getPort(); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | protected function renderPath(string $normalized) : string |
106 | 106 | { |
107 | - if(!$this->info->hasPath()) { |
|
107 | + if (!$this->info->hasPath()) { |
|
108 | 108 | return $normalized; |
109 | 109 | } |
110 | 110 | |
111 | - return $normalized . $this->info->getPath(); |
|
111 | + return $normalized.$this->info->getPath(); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | protected function renderParams(string $normalized) : string |
115 | 115 | { |
116 | 116 | $params = $this->info->getParams(); |
117 | 117 | |
118 | - if(empty($params)) { |
|
118 | + if (empty($params)) { |
|
119 | 119 | return $normalized; |
120 | 120 | } |
121 | 121 | |
122 | - return $normalized . '?'.http_build_query($params); |
|
122 | + return $normalized.'?'.http_build_query($params); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | protected function renderFragment(string $normalized) : string |
126 | 126 | { |
127 | - if(!$this->info->hasFragment()) { |
|
127 | + if (!$this->info->hasFragment()) { |
|
128 | 128 | return $normalized; |
129 | 129 | } |
130 | 130 | |
131 | - return $normalized . '#'.$this->info->getFragment(); |
|
131 | + return $normalized.'#'.$this->info->getFragment(); |
|
132 | 132 | } |
133 | 133 | } |
@@ -39,42 +39,42 @@ discard block |
||
39 | 39 | const TYPE_PHONE = 'phone'; |
40 | 40 | const TYPE_URL = 'url'; |
41 | 41 | |
42 | - /** |
|
43 | - * The original URL that was passed to the constructor. |
|
44 | - * @var string |
|
45 | - */ |
|
42 | + /** |
|
43 | + * The original URL that was passed to the constructor. |
|
44 | + * @var string |
|
45 | + */ |
|
46 | 46 | protected $rawURL; |
47 | 47 | |
48 | - /** |
|
49 | - * @var array |
|
50 | - */ |
|
48 | + /** |
|
49 | + * @var array |
|
50 | + */ |
|
51 | 51 | protected $info; |
52 | 52 | |
53 | - /** |
|
54 | - * @var string[] |
|
55 | - */ |
|
53 | + /** |
|
54 | + * @var string[] |
|
55 | + */ |
|
56 | 56 | protected $excludedParams = array(); |
57 | 57 | |
58 | - /** |
|
59 | - * @var bool |
|
60 | - * @see URLInfo::setParamExclusion() |
|
61 | - */ |
|
58 | + /** |
|
59 | + * @var bool |
|
60 | + * @see URLInfo::setParamExclusion() |
|
61 | + */ |
|
62 | 62 | protected $paramExclusion = false; |
63 | 63 | |
64 | - /** |
|
65 | - * @var array |
|
66 | - * @see URLInfo::getTypeLabel() |
|
67 | - */ |
|
64 | + /** |
|
65 | + * @var array |
|
66 | + * @see URLInfo::getTypeLabel() |
|
67 | + */ |
|
68 | 68 | protected static $typeLabels; |
69 | 69 | |
70 | - /** |
|
71 | - * @var bool |
|
72 | - */ |
|
70 | + /** |
|
71 | + * @var bool |
|
72 | + */ |
|
73 | 73 | protected $highlightExcluded = false; |
74 | 74 | |
75 | - /** |
|
76 | - * @var array |
|
77 | - */ |
|
75 | + /** |
|
76 | + * @var array |
|
77 | + */ |
|
78 | 78 | protected $infoKeys = array( |
79 | 79 | 'scheme', |
80 | 80 | 'host', |
@@ -86,19 +86,19 @@ discard block |
||
86 | 86 | 'fragment' |
87 | 87 | ); |
88 | 88 | |
89 | - /** |
|
90 | - * @var string |
|
91 | - */ |
|
89 | + /** |
|
90 | + * @var string |
|
91 | + */ |
|
92 | 92 | protected $url; |
93 | 93 | |
94 | - /** |
|
95 | - * @var URLInfo_Parser |
|
96 | - */ |
|
94 | + /** |
|
95 | + * @var URLInfo_Parser |
|
96 | + */ |
|
97 | 97 | protected $parser; |
98 | 98 | |
99 | - /** |
|
100 | - * @var URLInfo_Normalizer |
|
101 | - */ |
|
99 | + /** |
|
100 | + * @var URLInfo_Normalizer |
|
101 | + */ |
|
102 | 102 | protected $normalizer; |
103 | 103 | |
104 | 104 | public function __construct(string $url) |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | $this->info = $this->parser->getInfo(); |
111 | 111 | } |
112 | 112 | |
113 | - /** |
|
114 | - * Filters an URL: removes control characters and the |
|
115 | - * like to have a clean URL to work with. |
|
116 | - * |
|
117 | - * @param string $url |
|
118 | - * @return string |
|
119 | - */ |
|
113 | + /** |
|
114 | + * Filters an URL: removes control characters and the |
|
115 | + * like to have a clean URL to work with. |
|
116 | + * |
|
117 | + * @param string $url |
|
118 | + * @return string |
|
119 | + */ |
|
120 | 120 | public static function filterURL(string $url) |
121 | 121 | { |
122 | 122 | return URLInfo_Filter::filter($url); |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | return $this->info['type'] === self::TYPE_PHONE; |
147 | 147 | } |
148 | 148 | |
149 | - /** |
|
150 | - * Whether the URL is a regular URL, not one of the |
|
151 | - * other types like a phone number or email address. |
|
152 | - * |
|
153 | - * @return bool |
|
154 | - */ |
|
149 | + /** |
|
150 | + * Whether the URL is a regular URL, not one of the |
|
151 | + * other types like a phone number or email address. |
|
152 | + * |
|
153 | + * @return bool |
|
154 | + */ |
|
155 | 155 | public function isURL() : bool |
156 | 156 | { |
157 | 157 | $host = $this->getHost(); |
@@ -163,20 +163,20 @@ discard block |
||
163 | 163 | return $this->parser->isValid(); |
164 | 164 | } |
165 | 165 | |
166 | - /** |
|
167 | - * Retrieves the host name, or an empty string if none is present. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
166 | + /** |
|
167 | + * Retrieves the host name, or an empty string if none is present. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | 171 | public function getHost() : string |
172 | 172 | { |
173 | 173 | return $this->getInfoKey('host'); |
174 | 174 | } |
175 | 175 | |
176 | - /** |
|
177 | - * Retrieves the path, or an empty string if none is present. |
|
178 | - * @return string |
|
179 | - */ |
|
176 | + /** |
|
177 | + * Retrieves the path, or an empty string if none is present. |
|
178 | + * @return string |
|
179 | + */ |
|
180 | 180 | public function getPath() : string |
181 | 181 | { |
182 | 182 | return $this->getInfoKey('path'); |
@@ -192,10 +192,10 @@ discard block |
||
192 | 192 | return $this->getInfoKey('scheme'); |
193 | 193 | } |
194 | 194 | |
195 | - /** |
|
196 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
197 | - * @return int |
|
198 | - */ |
|
195 | + /** |
|
196 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
197 | + * @return int |
|
198 | + */ |
|
199 | 199 | public function getPort() : int |
200 | 200 | { |
201 | 201 | $port = $this->getInfoKey('port'); |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | return -1; |
208 | 208 | } |
209 | 209 | |
210 | - /** |
|
211 | - * Retrieves the raw query string, or an empty string if none is present. |
|
212 | - * |
|
213 | - * @return string |
|
214 | - * |
|
215 | - * @see URLInfo::getParams() |
|
216 | - */ |
|
210 | + /** |
|
211 | + * Retrieves the raw query string, or an empty string if none is present. |
|
212 | + * |
|
213 | + * @return string |
|
214 | + * |
|
215 | + * @see URLInfo::getParams() |
|
216 | + */ |
|
217 | 217 | public function getQuery() : string |
218 | 218 | { |
219 | 219 | return $this->getInfoKey('query'); |
@@ -229,20 +229,20 @@ discard block |
||
229 | 229 | return $this->getInfoKey('pass'); |
230 | 230 | } |
231 | 231 | |
232 | - /** |
|
233 | - * Whether the URL contains a port number. |
|
234 | - * @return bool |
|
235 | - */ |
|
232 | + /** |
|
233 | + * Whether the URL contains a port number. |
|
234 | + * @return bool |
|
235 | + */ |
|
236 | 236 | public function hasPort() : bool |
237 | 237 | { |
238 | 238 | return $this->getPort() !== -1; |
239 | 239 | } |
240 | 240 | |
241 | - /** |
|
242 | - * Alias for the hasParams() method. |
|
243 | - * @return bool |
|
244 | - * @see URLInfo::hasParams() |
|
245 | - */ |
|
241 | + /** |
|
242 | + * Alias for the hasParams() method. |
|
243 | + * @return bool |
|
244 | + * @see URLInfo::hasParams() |
|
245 | + */ |
|
246 | 246 | public function hasQuery() : bool |
247 | 247 | { |
248 | 248 | return $this->hasParams(); |
@@ -287,23 +287,23 @@ discard block |
||
287 | 287 | return ''; |
288 | 288 | } |
289 | 289 | |
290 | - /** |
|
291 | - * Retrieves a normalized URL: this ensures that all parameters |
|
292 | - * in the URL are always in the same order. |
|
293 | - * |
|
294 | - * @return string |
|
295 | - */ |
|
290 | + /** |
|
291 | + * Retrieves a normalized URL: this ensures that all parameters |
|
292 | + * in the URL are always in the same order. |
|
293 | + * |
|
294 | + * @return string |
|
295 | + */ |
|
296 | 296 | public function getNormalized() : string |
297 | 297 | { |
298 | 298 | return $this->normalize(true); |
299 | 299 | } |
300 | 300 | |
301 | - /** |
|
302 | - * Like getNormalized(), but if a username and password are present |
|
303 | - * in the URL, returns the URL without them. |
|
304 | - * |
|
305 | - * @return string |
|
306 | - */ |
|
301 | + /** |
|
302 | + * Like getNormalized(), but if a username and password are present |
|
303 | + * in the URL, returns the URL without them. |
|
304 | + * |
|
305 | + * @return string |
|
306 | + */ |
|
307 | 307 | public function getNormalizedWithoutAuth() : string |
308 | 308 | { |
309 | 309 | return $this->normalize(false); |
@@ -324,25 +324,25 @@ discard block |
||
324 | 324 | return $this->normalizer->normalize(); |
325 | 325 | } |
326 | 326 | |
327 | - /** |
|
328 | - * Creates a hash of the URL, which can be used for comparisons. |
|
329 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
330 | - * the same links with a different parameter order will have the |
|
331 | - * same hash. |
|
332 | - * |
|
333 | - * @return string |
|
334 | - */ |
|
327 | + /** |
|
328 | + * Creates a hash of the URL, which can be used for comparisons. |
|
329 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
330 | + * the same links with a different parameter order will have the |
|
331 | + * same hash. |
|
332 | + * |
|
333 | + * @return string |
|
334 | + */ |
|
335 | 335 | public function getHash() |
336 | 336 | { |
337 | 337 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
338 | 338 | } |
339 | 339 | |
340 | - /** |
|
341 | - * Highlights the URL using HTML tags with specific highlighting |
|
342 | - * class names. |
|
343 | - * |
|
344 | - * @return string Will return an empty string if the URL is not valid. |
|
345 | - */ |
|
340 | + /** |
|
341 | + * Highlights the URL using HTML tags with specific highlighting |
|
342 | + * class names. |
|
343 | + * |
|
344 | + * @return string Will return an empty string if the URL is not valid. |
|
345 | + */ |
|
346 | 346 | public function getHighlighted() : string |
347 | 347 | { |
348 | 348 | if(!$this->isValid()) { |
@@ -376,15 +376,15 @@ discard block |
||
376 | 376 | return count($params); |
377 | 377 | } |
378 | 378 | |
379 | - /** |
|
380 | - * Retrieves all parameters specified in the url, |
|
381 | - * if any, as an associative array. |
|
382 | - * |
|
383 | - * NOTE: Ignores parameters that have been added |
|
384 | - * to the excluded parameters list. |
|
385 | - * |
|
386 | - * @return array |
|
387 | - */ |
|
379 | + /** |
|
380 | + * Retrieves all parameters specified in the url, |
|
381 | + * if any, as an associative array. |
|
382 | + * |
|
383 | + * NOTE: Ignores parameters that have been added |
|
384 | + * to the excluded parameters list. |
|
385 | + * |
|
386 | + * @return array |
|
387 | + */ |
|
388 | 388 | public function getParams() : array |
389 | 389 | { |
390 | 390 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -402,22 +402,22 @@ discard block |
||
402 | 402 | return $keep; |
403 | 403 | } |
404 | 404 | |
405 | - /** |
|
406 | - * Retrieves the names of all parameters present in the URL, if any. |
|
407 | - * @return string[] |
|
408 | - */ |
|
405 | + /** |
|
406 | + * Retrieves the names of all parameters present in the URL, if any. |
|
407 | + * @return string[] |
|
408 | + */ |
|
409 | 409 | public function getParamNames() : array |
410 | 410 | { |
411 | 411 | $params = $this->getParams(); |
412 | 412 | return array_keys($params); |
413 | 413 | } |
414 | 414 | |
415 | - /** |
|
416 | - * Retrieves a specific parameter value from the URL. |
|
417 | - * |
|
418 | - * @param string $name |
|
419 | - * @return string The parameter value, or an empty string if it does not exist. |
|
420 | - */ |
|
415 | + /** |
|
416 | + * Retrieves a specific parameter value from the URL. |
|
417 | + * |
|
418 | + * @param string $name |
|
419 | + * @return string The parameter value, or an empty string if it does not exist. |
|
420 | + */ |
|
421 | 421 | public function getParam(string $name) : string |
422 | 422 | { |
423 | 423 | if(isset($this->info['params'][$name])) { |
@@ -427,16 +427,16 @@ discard block |
||
427 | 427 | return ''; |
428 | 428 | } |
429 | 429 | |
430 | - /** |
|
431 | - * Excludes an URL parameter entirely if present: |
|
432 | - * the parser will act as if the parameter was not |
|
433 | - * even present in the source URL, effectively |
|
434 | - * stripping it. |
|
435 | - * |
|
436 | - * @param string $name |
|
437 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
438 | - * @return URLInfo |
|
439 | - */ |
|
430 | + /** |
|
431 | + * Excludes an URL parameter entirely if present: |
|
432 | + * the parser will act as if the parameter was not |
|
433 | + * even present in the source URL, effectively |
|
434 | + * stripping it. |
|
435 | + * |
|
436 | + * @param string $name |
|
437 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
438 | + * @return URLInfo |
|
439 | + */ |
|
440 | 440 | public function excludeParam(string $name, string $reason) : URLInfo |
441 | 441 | { |
442 | 442 | if(!isset($this->excludedParams[$name])) |
@@ -489,25 +489,25 @@ discard block |
||
489 | 489 | return self::$typeLabels[$this->getType()]; |
490 | 490 | } |
491 | 491 | |
492 | - /** |
|
493 | - * Whether excluded parameters should be highlighted in |
|
494 | - * a different color in the URL when using the |
|
495 | - * {@link URLInfo::getHighlighted()} method. |
|
496 | - * |
|
497 | - * @param bool $highlight |
|
498 | - * @return URLInfo |
|
499 | - */ |
|
492 | + /** |
|
493 | + * Whether excluded parameters should be highlighted in |
|
494 | + * a different color in the URL when using the |
|
495 | + * {@link URLInfo::getHighlighted()} method. |
|
496 | + * |
|
497 | + * @param bool $highlight |
|
498 | + * @return URLInfo |
|
499 | + */ |
|
500 | 500 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
501 | 501 | { |
502 | 502 | $this->highlightExcluded = $highlight; |
503 | 503 | return $this; |
504 | 504 | } |
505 | 505 | |
506 | - /** |
|
507 | - * Returns an array with all relevant URL information. |
|
508 | - * |
|
509 | - * @return array |
|
510 | - */ |
|
506 | + /** |
|
507 | + * Returns an array with all relevant URL information. |
|
508 | + * |
|
509 | + * @return array |
|
510 | + */ |
|
511 | 511 | public function toArray() : array |
512 | 512 | { |
513 | 513 | return array( |
@@ -551,24 +551,24 @@ discard block |
||
551 | 551 | return $this; |
552 | 552 | } |
553 | 553 | |
554 | - /** |
|
555 | - * Whether the parameter exclusion mode is enabled: |
|
556 | - * In this case, if any parameters have been added to the |
|
557 | - * exclusion list, all relevant methods will exclude these. |
|
558 | - * |
|
559 | - * @return bool |
|
560 | - */ |
|
554 | + /** |
|
555 | + * Whether the parameter exclusion mode is enabled: |
|
556 | + * In this case, if any parameters have been added to the |
|
557 | + * exclusion list, all relevant methods will exclude these. |
|
558 | + * |
|
559 | + * @return bool |
|
560 | + */ |
|
561 | 561 | public function isParamExclusionEnabled() : bool |
562 | 562 | { |
563 | 563 | return $this->paramExclusion; |
564 | 564 | } |
565 | 565 | |
566 | - /** |
|
567 | - * Checks whether the link contains any parameters that |
|
568 | - * are on the list of excluded parameters. |
|
569 | - * |
|
570 | - * @return bool |
|
571 | - */ |
|
566 | + /** |
|
567 | + * Checks whether the link contains any parameters that |
|
568 | + * are on the list of excluded parameters. |
|
569 | + * |
|
570 | + * @return bool |
|
571 | + */ |
|
572 | 572 | public function containsExcludedParams() : bool |
573 | 573 | { |
574 | 574 | if(empty($this->excludedParams)) { |
@@ -636,16 +636,16 @@ discard block |
||
636 | 636 | return $this->highlightExcluded; |
637 | 637 | } |
638 | 638 | |
639 | - /** |
|
640 | - * Checks if the URL exists, i.e. can be connected to. Will return |
|
641 | - * true if the returned HTTP status code is `200` or `302`. |
|
642 | - * |
|
643 | - * NOTE: If the target URL requires HTTP authentication, the username |
|
644 | - * and password should be integrated into the URL. |
|
645 | - * |
|
646 | - * @return bool |
|
647 | - * @throws BaseException |
|
648 | - */ |
|
639 | + /** |
|
640 | + * Checks if the URL exists, i.e. can be connected to. Will return |
|
641 | + * true if the returned HTTP status code is `200` or `302`. |
|
642 | + * |
|
643 | + * NOTE: If the target URL requires HTTP authentication, the username |
|
644 | + * and password should be integrated into the URL. |
|
645 | + * |
|
646 | + * @return bool |
|
647 | + * @throws BaseException |
|
648 | + */ |
|
649 | 649 | public function tryConnect(bool $verifySSL=true) : bool |
650 | 650 | { |
651 | 651 | requireCURL(); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | { |
201 | 201 | $port = $this->getInfoKey('port'); |
202 | 202 | |
203 | - if(!empty($port)) { |
|
203 | + if (!empty($port)) { |
|
204 | 204 | return (int)$port; |
205 | 205 | } |
206 | 206 | |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | |
281 | 281 | protected function getInfoKey(string $name) : string |
282 | 282 | { |
283 | - if(isset($this->info[$name])) { |
|
283 | + if (isset($this->info[$name])) { |
|
284 | 284 | return (string)$this->info[$name]; |
285 | 285 | } |
286 | 286 | |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | return $this->normalize(false); |
310 | 310 | } |
311 | 311 | |
312 | - protected function normalize(bool $auth=true) : string |
|
312 | + protected function normalize(bool $auth = true) : string |
|
313 | 313 | { |
314 | - if(!$this->isValid()) { |
|
314 | + if (!$this->isValid()) { |
|
315 | 315 | return ''; |
316 | 316 | } |
317 | 317 | |
318 | - if(!isset($this->normalizer)) { |
|
318 | + if (!isset($this->normalizer)) { |
|
319 | 319 | $this->normalizer = new URLInfo_Normalizer($this); |
320 | 320 | } |
321 | 321 | |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function getHighlighted() : string |
347 | 347 | { |
348 | - if(!$this->isValid()) { |
|
348 | + if (!$this->isValid()) { |
|
349 | 349 | return ''; |
350 | 350 | } |
351 | 351 | |
@@ -387,14 +387,14 @@ discard block |
||
387 | 387 | */ |
388 | 388 | public function getParams() : array |
389 | 389 | { |
390 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
390 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
391 | 391 | return $this->info['params']; |
392 | 392 | } |
393 | 393 | |
394 | 394 | $keep = array(); |
395 | - foreach($this->info['params'] as $name => $value) |
|
395 | + foreach ($this->info['params'] as $name => $value) |
|
396 | 396 | { |
397 | - if(!isset($this->excludedParams[$name])) { |
|
397 | + if (!isset($this->excludedParams[$name])) { |
|
398 | 398 | $keep[$name] = $value; |
399 | 399 | } |
400 | 400 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | */ |
421 | 421 | public function getParam(string $name) : string |
422 | 422 | { |
423 | - if(isset($this->info['params'][$name])) { |
|
423 | + if (isset($this->info['params'][$name])) { |
|
424 | 424 | return $this->info['params'][$name]; |
425 | 425 | } |
426 | 426 | |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | */ |
440 | 440 | public function excludeParam(string $name, string $reason) : URLInfo |
441 | 441 | { |
442 | - if(!isset($this->excludedParams[$name])) |
|
442 | + if (!isset($this->excludedParams[$name])) |
|
443 | 443 | { |
444 | 444 | $this->excludedParams[$name] = $reason; |
445 | 445 | $this->setParamExclusion(); |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | |
466 | 466 | public function getTypeLabel() : string |
467 | 467 | { |
468 | - if(!isset(self::$typeLabels)) |
|
468 | + if (!isset(self::$typeLabels)) |
|
469 | 469 | { |
470 | 470 | self::$typeLabels = array( |
471 | 471 | self::TYPE_EMAIL => t('Email'), |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | |
478 | 478 | $type = $this->getType(); |
479 | 479 | |
480 | - if(!isset(self::$typeLabels[$type])) |
|
480 | + if (!isset(self::$typeLabels[$type])) |
|
481 | 481 | { |
482 | 482 | throw new BaseException( |
483 | 483 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | * @param bool $highlight |
498 | 498 | * @return URLInfo |
499 | 499 | */ |
500 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
500 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
501 | 501 | { |
502 | 502 | $this->highlightExcluded = $highlight; |
503 | 503 | return $this; |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * @see URLInfo::isParamExclusionEnabled() |
546 | 546 | * @see URLInfo::setHighlightExcluded() |
547 | 547 | */ |
548 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
548 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
549 | 549 | { |
550 | 550 | $this->paramExclusion = $enabled; |
551 | 551 | return $this; |
@@ -571,13 +571,13 @@ discard block |
||
571 | 571 | */ |
572 | 572 | public function containsExcludedParams() : bool |
573 | 573 | { |
574 | - if(empty($this->excludedParams)) { |
|
574 | + if (empty($this->excludedParams)) { |
|
575 | 575 | return false; |
576 | 576 | } |
577 | 577 | |
578 | 578 | $names = array_keys($this->info['params']); |
579 | - foreach($names as $name) { |
|
580 | - if(isset($this->excludedParams[$name])) { |
|
579 | + foreach ($names as $name) { |
|
580 | + if (isset($this->excludedParams[$name])) { |
|
581 | 581 | return true; |
582 | 582 | } |
583 | 583 | } |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | |
594 | 594 | public function offsetSet($offset, $value) |
595 | 595 | { |
596 | - if(in_array($offset, $this->infoKeys)) { |
|
596 | + if (in_array($offset, $this->infoKeys)) { |
|
597 | 597 | $this->info[$offset] = $value; |
598 | 598 | } |
599 | 599 | } |
@@ -610,11 +610,11 @@ discard block |
||
610 | 610 | |
611 | 611 | public function offsetGet($offset) |
612 | 612 | { |
613 | - if($offset === 'port') { |
|
613 | + if ($offset === 'port') { |
|
614 | 614 | return $this->getPort(); |
615 | 615 | } |
616 | 616 | |
617 | - if(in_array($offset, $this->infoKeys)) { |
|
617 | + if (in_array($offset, $this->infoKeys)) { |
|
618 | 618 | return $this->getInfoKey($offset); |
619 | 619 | } |
620 | 620 | |
@@ -646,12 +646,12 @@ discard block |
||
646 | 646 | * @return bool |
647 | 647 | * @throws BaseException |
648 | 648 | */ |
649 | - public function tryConnect(bool $verifySSL=true) : bool |
|
649 | + public function tryConnect(bool $verifySSL = true) : bool |
|
650 | 650 | { |
651 | 651 | requireCURL(); |
652 | 652 | |
653 | 653 | $ch = curl_init(); |
654 | - if(!is_resource($ch)) |
|
654 | + if (!is_resource($ch)) |
|
655 | 655 | { |
656 | 656 | throw new BaseException( |
657 | 657 | 'Could not initialize a new cURL instance.', |
@@ -667,13 +667,13 @@ discard block |
||
667 | 667 | curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
668 | 668 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
669 | 669 | |
670 | - if(!$verifySSL) |
|
670 | + if (!$verifySSL) |
|
671 | 671 | { |
672 | 672 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
673 | 673 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
674 | 674 | } |
675 | 675 | |
676 | - if($this->hasUsername()) |
|
676 | + if ($this->hasUsername()) |
|
677 | 677 | { |
678 | 678 | curl_setopt($ch, CURLOPT_USERNAME, $this->getUsername()); |
679 | 679 | curl_setopt($ch, CURLOPT_PASSWORD, $this->getPassword()); |
@@ -216,8 +216,7 @@ |
||
216 | 216 | curl_errno($ch), |
217 | 217 | curl_error($ch) |
218 | 218 | ); |
219 | - } |
|
220 | - else |
|
219 | + } else |
|
221 | 220 | { |
222 | 221 | $this->response->setBody((string)$output); |
223 | 222 | } |
@@ -29,56 +29,56 @@ discard block |
||
29 | 29 | |
30 | 30 | const ERROR_CURL_INIT_FAILED = 17903; |
31 | 31 | |
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | 35 | protected $eol = "\r\n"; |
36 | 36 | |
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | 40 | protected $mimeBoundary; |
41 | 41 | |
42 | - /** |
|
43 | - * @var string |
|
44 | - */ |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + */ |
|
45 | 45 | protected $data = ''; |
46 | 46 | |
47 | - /** |
|
48 | - * @var string |
|
49 | - */ |
|
47 | + /** |
|
48 | + * @var string |
|
49 | + */ |
|
50 | 50 | protected $destination; |
51 | 51 | |
52 | - /** |
|
53 | - * @var array |
|
54 | - */ |
|
52 | + /** |
|
53 | + * @var array |
|
54 | + */ |
|
55 | 55 | protected $headers = array(); |
56 | 56 | |
57 | - /** |
|
58 | - * Whether to verify SSL certificates. |
|
59 | - * @var bool |
|
60 | - */ |
|
57 | + /** |
|
58 | + * Whether to verify SSL certificates. |
|
59 | + * @var bool |
|
60 | + */ |
|
61 | 61 | protected $verifySSL = true; |
62 | 62 | |
63 | - /** |
|
64 | - * @var RequestHelper_Boundaries |
|
65 | - */ |
|
63 | + /** |
|
64 | + * @var RequestHelper_Boundaries |
|
65 | + */ |
|
66 | 66 | protected $boundaries; |
67 | 67 | |
68 | - /** |
|
69 | - * @var RequestHelper_Response|NULL |
|
70 | - */ |
|
68 | + /** |
|
69 | + * @var RequestHelper_Response|NULL |
|
70 | + */ |
|
71 | 71 | protected $response; |
72 | 72 | |
73 | - /** |
|
74 | - * @var integer |
|
75 | - */ |
|
73 | + /** |
|
74 | + * @var integer |
|
75 | + */ |
|
76 | 76 | protected $timeout = 30; |
77 | 77 | |
78 | - /** |
|
79 | - * Creates a new request helper to send POST data to the specified destination URL. |
|
80 | - * @param string $destinationURL |
|
81 | - */ |
|
78 | + /** |
|
79 | + * Creates a new request helper to send POST data to the specified destination URL. |
|
80 | + * @param string $destinationURL |
|
81 | + */ |
|
82 | 82 | public function __construct(string $destinationURL) |
83 | 83 | { |
84 | 84 | $this->destination = $destinationURL; |
@@ -105,15 +105,15 @@ discard block |
||
105 | 105 | return $this; |
106 | 106 | } |
107 | 107 | |
108 | - /** |
|
109 | - * Adds a file to be sent with the request. |
|
110 | - * |
|
111 | - * @param string $varName The variable name to send the file in |
|
112 | - * @param string $fileName The name of the file as it should be received at the destination |
|
113 | - * @param string $content The raw content of the file |
|
114 | - * @param string $contentType The content type, use the constants to specify this |
|
115 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
116 | - */ |
|
108 | + /** |
|
109 | + * Adds a file to be sent with the request. |
|
110 | + * |
|
111 | + * @param string $varName The variable name to send the file in |
|
112 | + * @param string $fileName The name of the file as it should be received at the destination |
|
113 | + * @param string $content The raw content of the file |
|
114 | + * @param string $contentType The content type, use the constants to specify this |
|
115 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
116 | + */ |
|
117 | 117 | public function addFile(string $varName, string $fileName, string $content, string $contentType = self::FILETYPE_TEXT, string $encoding = self::ENCODING_UTF8) : RequestHelper |
118 | 118 | { |
119 | 119 | $this->boundaries->addFile($varName, $fileName, $content, $contentType, $encoding); |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | return $this; |
122 | 122 | } |
123 | 123 | |
124 | - /** |
|
125 | - * Adds arbitrary content. |
|
126 | - * |
|
127 | - * @param string $varName The variable name to send the content in. |
|
128 | - * @param string $content |
|
129 | - * @param string $contentType |
|
130 | - */ |
|
124 | + /** |
|
125 | + * Adds arbitrary content. |
|
126 | + * |
|
127 | + * @param string $varName The variable name to send the content in. |
|
128 | + * @param string $content |
|
129 | + * @param string $contentType |
|
130 | + */ |
|
131 | 131 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper |
132 | 132 | { |
133 | 133 | $this->boundaries->addContent($varName, $content, $contentType); |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | return $this; |
150 | 150 | } |
151 | 151 | |
152 | - /** |
|
153 | - * Sets an HTTP header to include in the request. |
|
154 | - * |
|
155 | - * @param string $name |
|
156 | - * @param string $value |
|
157 | - * @return RequestHelper |
|
158 | - */ |
|
152 | + /** |
|
153 | + * Sets an HTTP header to include in the request. |
|
154 | + * |
|
155 | + * @param string $name |
|
156 | + * @param string $value |
|
157 | + * @return RequestHelper |
|
158 | + */ |
|
159 | 159 | public function setHeader(string $name, string $value) : RequestHelper |
160 | 160 | { |
161 | 161 | $this->headers[$name] = $value; |
@@ -163,36 +163,36 @@ discard block |
||
163 | 163 | return $this; |
164 | 164 | } |
165 | 165 | |
166 | - /** |
|
167 | - * Disables SSL certificate checking. |
|
168 | - * |
|
169 | - * @return RequestHelper |
|
170 | - */ |
|
166 | + /** |
|
167 | + * Disables SSL certificate checking. |
|
168 | + * |
|
169 | + * @return RequestHelper |
|
170 | + */ |
|
171 | 171 | public function disableSSLChecks() : RequestHelper |
172 | 172 | { |
173 | 173 | $this->verifySSL = false; |
174 | 174 | return $this; |
175 | 175 | } |
176 | 176 | |
177 | - /** |
|
178 | - * @var integer |
|
179 | - */ |
|
177 | + /** |
|
178 | + * @var integer |
|
179 | + */ |
|
180 | 180 | protected $contentLength = 0; |
181 | 181 | |
182 | - /** |
|
183 | - * Sends the POST request to the destination, and returns |
|
184 | - * the response text. |
|
185 | - * |
|
186 | - * The response object is stored internally, so after calling |
|
187 | - * this method it may be retrieved at any moment using the |
|
188 | - * {@link getResponse()} method. |
|
189 | - * |
|
190 | - * @return string |
|
191 | - * @see RequestHelper::getResponse() |
|
192 | - * @throws RequestHelper_Exception |
|
193 | - * |
|
194 | - * @see RequestHelper::ERROR_REQUEST_FAILED |
|
195 | - */ |
|
182 | + /** |
|
183 | + * Sends the POST request to the destination, and returns |
|
184 | + * the response text. |
|
185 | + * |
|
186 | + * The response object is stored internally, so after calling |
|
187 | + * this method it may be retrieved at any moment using the |
|
188 | + * {@link getResponse()} method. |
|
189 | + * |
|
190 | + * @return string |
|
191 | + * @see RequestHelper::getResponse() |
|
192 | + * @throws RequestHelper_Exception |
|
193 | + * |
|
194 | + * @see RequestHelper::ERROR_REQUEST_FAILED |
|
195 | + */ |
|
196 | 196 | public function send() : string |
197 | 197 | { |
198 | 198 | $this->data = $this->boundaries->render(); |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | return $this->data; |
233 | 233 | } |
234 | 234 | |
235 | - /** |
|
236 | - * Creates a new CURL resource configured according to the |
|
237 | - * request's settings. |
|
238 | - * |
|
239 | - * @param URLInfo $url |
|
240 | - * @throws RequestHelper_Exception |
|
241 | - * @return resource |
|
242 | - */ |
|
235 | + /** |
|
236 | + * Creates a new CURL resource configured according to the |
|
237 | + * request's settings. |
|
238 | + * |
|
239 | + * @param URLInfo $url |
|
240 | + * @throws RequestHelper_Exception |
|
241 | + * @return resource |
|
242 | + */ |
|
243 | 243 | protected function createCURL(URLInfo $url) |
244 | 244 | { |
245 | 245 | $ch = curl_init(); |
@@ -279,13 +279,13 @@ discard block |
||
279 | 279 | return $ch; |
280 | 280 | } |
281 | 281 | |
282 | - /** |
|
283 | - * Compiles the associative headers array into |
|
284 | - * the format understood by CURL, namely an indexed |
|
285 | - * array with one header string per entry. |
|
286 | - * |
|
287 | - * @return array |
|
288 | - */ |
|
282 | + /** |
|
283 | + * Compiles the associative headers array into |
|
284 | + * the format understood by CURL, namely an indexed |
|
285 | + * array with one header string per entry. |
|
286 | + * |
|
287 | + * @return array |
|
288 | + */ |
|
289 | 289 | protected function renderHeaders() : array |
290 | 290 | { |
291 | 291 | $result = array(); |
@@ -297,12 +297,12 @@ discard block |
||
297 | 297 | return $result; |
298 | 298 | } |
299 | 299 | |
300 | - /** |
|
301 | - * Retrieves the raw response header, in the form of an indexed |
|
302 | - * array containing all response header lines. |
|
303 | - * |
|
304 | - * @return array |
|
305 | - */ |
|
300 | + /** |
|
301 | + * Retrieves the raw response header, in the form of an indexed |
|
302 | + * array containing all response header lines. |
|
303 | + * |
|
304 | + * @return array |
|
305 | + */ |
|
306 | 306 | public function getResponseHeader() : array |
307 | 307 | { |
308 | 308 | $response = $this->getResponse(); |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | // CURL will complain about an empty response when the |
211 | 211 | // server sends a 100-continue code. That should not be |
212 | 212 | // regarded as an error. |
213 | - if($output === false && $this->response->getCode() !== 100) |
|
213 | + if ($output === false && $this->response->getCode() !== 100) |
|
214 | 214 | { |
215 | 215 | $this->response->setError( |
216 | 216 | curl_errno($ch), |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | protected function createCURL(URLInfo $url) |
244 | 244 | { |
245 | 245 | $ch = curl_init(); |
246 | - if(!is_resource($ch)) |
|
246 | + if (!is_resource($ch)) |
|
247 | 247 | { |
248 | 248 | throw new RequestHelper_Exception( |
249 | 249 | 'Could not initialize a new cURL instance.', |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | } |
254 | 254 | |
255 | 255 | $this->setHeader('Content-Length', (string)$this->boundaries->getContentLength()); |
256 | - $this->setHeader('Content-Type', 'multipart/form-data; charset=UTF-8; boundary=' . $this->mimeBoundary); |
|
256 | + $this->setHeader('Content-Type', 'multipart/form-data; charset=UTF-8; boundary='.$this->mimeBoundary); |
|
257 | 257 | |
258 | 258 | //curl_setopt($ch, CURLOPT_VERBOSE, true); |
259 | 259 | curl_setopt($ch, CURLOPT_POST, true); |
@@ -264,13 +264,13 @@ discard block |
||
264 | 264 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
265 | 265 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->renderHeaders()); |
266 | 266 | |
267 | - if($this->verifySSL) |
|
267 | + if ($this->verifySSL) |
|
268 | 268 | { |
269 | 269 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
270 | 270 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
271 | 271 | } |
272 | 272 | |
273 | - if($url->hasUsername()) |
|
273 | + if ($url->hasUsername()) |
|
274 | 274 | { |
275 | 275 | curl_setopt($ch, CURLOPT_USERNAME, $url->getUsername()); |
276 | 276 | curl_setopt($ch, CURLOPT_PASSWORD, $url->getPassword()); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | { |
291 | 291 | $result = array(); |
292 | 292 | |
293 | - foreach($this->headers as $name => $value) { |
|
293 | + foreach ($this->headers as $name => $value) { |
|
294 | 294 | $result[] = $name.': '.$value; |
295 | 295 | } |
296 | 296 | |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | { |
308 | 308 | $response = $this->getResponse(); |
309 | 309 | |
310 | - if($response !== null) { |
|
310 | + if ($response !== null) { |
|
311 | 311 | return $response->getHeaders(); |
312 | 312 | } |
313 | 313 |
@@ -87,37 +87,37 @@ |
||
87 | 87 | */ |
88 | 88 | interface Interface_Classable |
89 | 89 | { |
90 | - /** |
|
91 | - * @param string $name |
|
92 | - * @return Interface_Classable |
|
93 | - */ |
|
90 | + /** |
|
91 | + * @param string $name |
|
92 | + * @return Interface_Classable |
|
93 | + */ |
|
94 | 94 | public function addClass(string $name); |
95 | 95 | |
96 | - /** |
|
97 | - * @param array $names |
|
98 | - * @return Interface_Classable |
|
99 | - */ |
|
96 | + /** |
|
97 | + * @param array $names |
|
98 | + * @return Interface_Classable |
|
99 | + */ |
|
100 | 100 | public function addClasses(array $names); |
101 | 101 | |
102 | - /** |
|
103 | - * @param string $name |
|
104 | - * @return bool |
|
105 | - */ |
|
102 | + /** |
|
103 | + * @param string $name |
|
104 | + * @return bool |
|
105 | + */ |
|
106 | 106 | public function hasClass(string $name) : bool; |
107 | 107 | |
108 | - /** |
|
109 | - * @param string $name |
|
110 | - * @return Interface_Classable |
|
111 | - */ |
|
108 | + /** |
|
109 | + * @param string $name |
|
110 | + * @return Interface_Classable |
|
111 | + */ |
|
112 | 112 | public function removeClass(string $name); |
113 | 113 | |
114 | - /** |
|
115 | - * @return array |
|
116 | - */ |
|
114 | + /** |
|
115 | + * @return array |
|
116 | + */ |
|
117 | 117 | public function getClasses() : array; |
118 | 118 | |
119 | - /** |
|
120 | - * @return string |
|
121 | - */ |
|
119 | + /** |
|
120 | + * @return string |
|
121 | + */ |
|
122 | 122 | public function classesToString() : string; |
123 | 123 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | public function addClass(string $name) |
31 | 31 | { |
32 | - if(!in_array($name, $this->classes)) { |
|
32 | + if (!in_array($name, $this->classes)) { |
|
33 | 33 | $this->classes[] = $name; |
34 | 34 | } |
35 | 35 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | public function addClasses(array $names) |
40 | 40 | { |
41 | - foreach($names as $name) { |
|
41 | + foreach ($names as $name) { |
|
42 | 42 | $this->addClass($name); |
43 | 43 | } |
44 | 44 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | $idx = array_search($name, $this->classes); |
56 | 56 | |
57 | - if($idx !== false) { |
|
57 | + if ($idx !== false) { |
|
58 | 58 | unset($this->classes[$idx]); |
59 | 59 | sort($this->classes); |
60 | 60 | } |
@@ -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 = array(); |
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() : void |
46 | 46 | { |
47 | 47 | if(!empty(self::$sizes)) { |
@@ -68,30 +68,30 @@ discard block |
||
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - /** |
|
72 | - * Called whenever the application locale is changed, |
|
73 | - * to reset the size definitions so the labels get |
|
74 | - * translated to the new locale. |
|
75 | - * |
|
76 | - * @param \AppLocalize\Localization_Event_LocaleChanged $event |
|
77 | - */ |
|
71 | + /** |
|
72 | + * Called whenever the application locale is changed, |
|
73 | + * to reset the size definitions so the labels get |
|
74 | + * translated to the new locale. |
|
75 | + * |
|
76 | + * @param \AppLocalize\Localization_Event_LocaleChanged $event |
|
77 | + */ |
|
78 | 78 | public static function handle_localeChanged(\AppLocalize\Localization_Event_LocaleChanged $event) : void |
79 | 79 | { |
80 | 80 | self::$sizes = array(); |
81 | 81 | } |
82 | 82 | |
83 | - /** |
|
84 | - * Adds a storage size to the internal collection. |
|
85 | - * |
|
86 | - * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
87 | - * @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. |
|
88 | - * @param int $exponent The multiplier of the base to get the byte value |
|
89 | - * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
90 | - * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
91 | - * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
92 | - * |
|
93 | - * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
94 | - */ |
|
83 | + /** |
|
84 | + * Adds a storage size to the internal collection. |
|
85 | + * |
|
86 | + * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
87 | + * @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. |
|
88 | + * @param int $exponent The multiplier of the base to get the byte value |
|
89 | + * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
90 | + * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
91 | + * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
92 | + * |
|
93 | + * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
94 | + */ |
|
95 | 95 | protected static function addSize(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) : void |
96 | 96 | { |
97 | 97 | self::$sizes[$name] = new ConvertHelper_StorageSizeEnum_Size( |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
107 | - /** |
|
108 | - * Retrieves all known sizes. |
|
109 | - * |
|
110 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
111 | - */ |
|
107 | + /** |
|
108 | + * Retrieves all known sizes. |
|
109 | + * |
|
110 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
111 | + */ |
|
112 | 112 | public static function getSizes() : array |
113 | 113 | { |
114 | 114 | self::init(); |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | return self::$sizes; |
117 | 117 | } |
118 | 118 | |
119 | - /** |
|
120 | - * Retrieves a size definition instance by its name. |
|
121 | - * |
|
122 | - * @param string $name Case insensitive. For example "kb", "MiB"... |
|
123 | - * @throws ConvertHelper_Exception |
|
124 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
125 | - * |
|
126 | - * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
127 | - */ |
|
119 | + /** |
|
120 | + * Retrieves a size definition instance by its name. |
|
121 | + * |
|
122 | + * @param string $name Case insensitive. For example "kb", "MiB"... |
|
123 | + * @throws ConvertHelper_Exception |
|
124 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
125 | + * |
|
126 | + * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
127 | + */ |
|
128 | 128 | public static function getSizeByName(string $name) : ConvertHelper_StorageSizeEnum_Size |
129 | 129 | { |
130 | 130 | self::init(); |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | ); |
147 | 147 | } |
148 | 148 | |
149 | - /** |
|
150 | - * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
151 | - * @return array |
|
152 | - */ |
|
149 | + /** |
|
150 | + * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
151 | + * @return array |
|
152 | + */ |
|
153 | 153 | public static function getSizeNames() : array |
154 | 154 | { |
155 | 155 | self::init(); |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | return array_keys(self::$sizes); |
158 | 158 | } |
159 | 159 | |
160 | - /** |
|
161 | - * Retrieves all available storage sizes for the specified |
|
162 | - * base value. |
|
163 | - * |
|
164 | - * @param int $base |
|
165 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
166 | - * |
|
167 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
168 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
169 | - */ |
|
160 | + /** |
|
161 | + * Retrieves all available storage sizes for the specified |
|
162 | + * base value. |
|
163 | + * |
|
164 | + * @param int $base |
|
165 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
166 | + * |
|
167 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
168 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
169 | + */ |
|
170 | 170 | public static function getSizesByBase(int $base) : array |
171 | 171 | { |
172 | 172 | self::init(); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected static function init() : void |
46 | 46 | { |
47 | - if(!empty(self::$sizes)) { |
|
47 | + if (!empty(self::$sizes)) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | self::addSize('b', 1, 1, t('B'), t('Byte'), t('Bytes')); |
64 | 64 | |
65 | - if(class_exists('AppLocalize\Localization')) |
|
65 | + if (class_exists('AppLocalize\Localization')) |
|
66 | 66 | { |
67 | 67 | \AppLocalize\Localization::onLocaleChanged(array(self::class, 'handle_localeChanged')); |
68 | 68 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | $name = strtolower($name); |
133 | 133 | |
134 | - if(isset(self::$sizes[$name])) { |
|
134 | + if (isset(self::$sizes[$name])) { |
|
135 | 135 | return self::$sizes[$name]; |
136 | 136 | } |
137 | 137 | |
@@ -173,9 +173,9 @@ discard block |
||
173 | 173 | |
174 | 174 | $result = array(); |
175 | 175 | |
176 | - foreach(self::$sizes as $size) |
|
176 | + foreach (self::$sizes as $size) |
|
177 | 177 | { |
178 | - if($size->getBase() === $base) { |
|
178 | + if ($size->getBase() === $base) { |
|
179 | 179 | $result[] = $size; |
180 | 180 | } |
181 | 181 | } |
@@ -20,43 +20,43 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class ConvertHelper_TabsNormalizer |
22 | 22 | { |
23 | - /** |
|
24 | - * @var integer |
|
25 | - */ |
|
23 | + /** |
|
24 | + * @var integer |
|
25 | + */ |
|
26 | 26 | protected $max = 0; |
27 | 27 | |
28 | - /** |
|
29 | - * @var integer |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var integer |
|
30 | + */ |
|
31 | 31 | protected $min = PHP_INT_MAX; |
32 | 32 | |
33 | - /** |
|
34 | - * @var bool |
|
35 | - */ |
|
33 | + /** |
|
34 | + * @var bool |
|
35 | + */ |
|
36 | 36 | protected $tabs2spaces = false; |
37 | 37 | |
38 | - /** |
|
39 | - * @var array |
|
40 | - */ |
|
38 | + /** |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $lines = array(); |
42 | 42 | |
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | 46 | protected $eol = ''; |
47 | 47 | |
48 | - /** |
|
49 | - * @var integer |
|
50 | - */ |
|
48 | + /** |
|
49 | + * @var integer |
|
50 | + */ |
|
51 | 51 | protected $tabSize = 4; |
52 | 52 | |
53 | - /** |
|
54 | - * Whether to enable or disable the conversion |
|
55 | - * of tabs to spaces. |
|
56 | - * |
|
57 | - * @param bool $enable |
|
58 | - * @return ConvertHelper_TabsNormalizer |
|
59 | - */ |
|
53 | + /** |
|
54 | + * Whether to enable or disable the conversion |
|
55 | + * of tabs to spaces. |
|
56 | + * |
|
57 | + * @param bool $enable |
|
58 | + * @return ConvertHelper_TabsNormalizer |
|
59 | + */ |
|
60 | 60 | public function convertTabsToSpaces(bool $enable=true) : ConvertHelper_TabsNormalizer |
61 | 61 | { |
62 | 62 | $this->tabs2spaces = $enable; |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | return $this; |
65 | 65 | } |
66 | 66 | |
67 | - /** |
|
68 | - * Sets the size of a tab, in spaces. Used to convert tabs |
|
69 | - * from spaces and the other way around. Defaults to 4. |
|
70 | - * |
|
71 | - * @param int $amountSpaces |
|
72 | - * @return ConvertHelper_TabsNormalizer |
|
73 | - */ |
|
67 | + /** |
|
68 | + * Sets the size of a tab, in spaces. Used to convert tabs |
|
69 | + * from spaces and the other way around. Defaults to 4. |
|
70 | + * |
|
71 | + * @param int $amountSpaces |
|
72 | + * @return ConvertHelper_TabsNormalizer |
|
73 | + */ |
|
74 | 74 | public function setTabSize(int $amountSpaces) : ConvertHelper_TabsNormalizer |
75 | 75 | { |
76 | 76 | $this->tabSize = $amountSpaces; |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | return $this; |
79 | 79 | } |
80 | 80 | |
81 | - /** |
|
82 | - * Normalizes tabs in the specified string by indenting everything |
|
83 | - * back to the minimum tab distance. With the second parameter, |
|
84 | - * tabs can optionally be converted to spaces as well (recommended |
|
85 | - * for HTML output). |
|
86 | - * |
|
87 | - * @param string $string |
|
88 | - * @return string |
|
89 | - */ |
|
81 | + /** |
|
82 | + * Normalizes tabs in the specified string by indenting everything |
|
83 | + * back to the minimum tab distance. With the second parameter, |
|
84 | + * tabs can optionally be converted to spaces as well (recommended |
|
85 | + * for HTML output). |
|
86 | + * |
|
87 | + * @param string $string |
|
88 | + * @return string |
|
89 | + */ |
|
90 | 90 | public function normalize(string $string) : string |
91 | 91 | { |
92 | 92 | $this->splitLines($string); |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | return implode($this->eol, $converted); |
144 | 144 | } |
145 | 145 | |
146 | - /** |
|
147 | - * Finds out the minimum and maximum amount of |
|
148 | - * tabs in the string. |
|
149 | - */ |
|
146 | + /** |
|
147 | + * Finds out the minimum and maximum amount of |
|
148 | + * tabs in the string. |
|
149 | + */ |
|
150 | 150 | protected function countOccurrences() : void |
151 | 151 | { |
152 | 152 | foreach($this->lines as $line) |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param bool $enable |
58 | 58 | * @return ConvertHelper_TabsNormalizer |
59 | 59 | */ |
60 | - public function convertTabsToSpaces(bool $enable=true) : ConvertHelper_TabsNormalizer |
|
60 | + public function convertTabsToSpaces(bool $enable = true) : ConvertHelper_TabsNormalizer |
|
61 | 61 | { |
62 | 62 | $this->tabs2spaces = $enable; |
63 | 63 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | $result = $this->_normalize(); |
96 | 96 | |
97 | - if($this->tabs2spaces) |
|
97 | + if ($this->tabs2spaces) |
|
98 | 98 | { |
99 | 99 | $result = ConvertHelper::tabs2spaces($result, $this->tabSize); |
100 | 100 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | { |
109 | 109 | $eol = ConvertHelper::detectEOLCharacter($string); |
110 | 110 | |
111 | - if($eol !== null) |
|
111 | + if ($eol !== null) |
|
112 | 112 | { |
113 | 113 | $this->eol = $eol->getCharacter(); |
114 | 114 | } |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | { |
127 | 127 | $converted = array(); |
128 | 128 | |
129 | - foreach($this->lines as $line) |
|
129 | + foreach ($this->lines as $line) |
|
130 | 130 | { |
131 | 131 | $amount = substr_count($line, "\t") - $this->min; |
132 | 132 | |
133 | 133 | $line = trim($line, "\n\r\t"); |
134 | 134 | |
135 | - if($amount >= 1) |
|
135 | + if ($amount >= 1) |
|
136 | 136 | { |
137 | - $line = str_repeat("\t", $amount) . $line; |
|
137 | + $line = str_repeat("\t", $amount).$line; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $converted[] = $line; |
@@ -149,23 +149,23 @@ discard block |
||
149 | 149 | */ |
150 | 150 | protected function countOccurrences() : void |
151 | 151 | { |
152 | - foreach($this->lines as $line) |
|
152 | + foreach ($this->lines as $line) |
|
153 | 153 | { |
154 | 154 | $amount = substr_count($line, "\t"); |
155 | 155 | |
156 | - if($amount > $this->max) |
|
156 | + if ($amount > $this->max) |
|
157 | 157 | { |
158 | 158 | $this->max = $amount; |
159 | 159 | continue; |
160 | 160 | } |
161 | 161 | |
162 | - if($amount > 0 && $amount < $this->min) |
|
162 | + if ($amount > 0 && $amount < $this->min) |
|
163 | 163 | { |
164 | 164 | $this->min = $amount; |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - if($this->min === PHP_INT_MAX) { |
|
168 | + if ($this->min === PHP_INT_MAX) { |
|
169 | 169 | $this->min = 0; |
170 | 170 | } |
171 | 171 | } |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | ) |
70 | 70 | ); |
71 | 71 | |
72 | - /** |
|
73 | - * @var array |
|
74 | - */ |
|
72 | + /** |
|
73 | + * @var array |
|
74 | + */ |
|
75 | 75 | protected $selected = array(); |
76 | 76 | |
77 | 77 | public function convert(string $string) : string |
@@ -81,16 +81,16 @@ discard block |
||
81 | 81 | return str_replace(array_keys($chars), array_values($chars), $string); |
82 | 82 | } |
83 | 83 | |
84 | - /** |
|
85 | - * Selects a character set to replace. Can be called |
|
86 | - * several times to add additional sets to the collection. |
|
87 | - * |
|
88 | - * @param string $type See the <code>CHAR_XXX</code> constants. |
|
89 | - * @return ConvertHelper_HiddenConverter |
|
90 | - * |
|
91 | - * @see ConvertHelper_HiddenConverter::CHARS_CONTROL |
|
92 | - * @see ConvertHelper_HiddenConverter::CHARS_WHITESPACE |
|
93 | - */ |
|
84 | + /** |
|
85 | + * Selects a character set to replace. Can be called |
|
86 | + * several times to add additional sets to the collection. |
|
87 | + * |
|
88 | + * @param string $type See the <code>CHAR_XXX</code> constants. |
|
89 | + * @return ConvertHelper_HiddenConverter |
|
90 | + * |
|
91 | + * @see ConvertHelper_HiddenConverter::CHARS_CONTROL |
|
92 | + * @see ConvertHelper_HiddenConverter::CHARS_WHITESPACE |
|
93 | + */ |
|
94 | 94 | public function selectCharacters(string $type) : ConvertHelper_HiddenConverter |
95 | 95 | { |
96 | 96 | if(!in_array($type, $this->selected)) { |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | return $this; |
101 | 101 | } |
102 | 102 | |
103 | - /** |
|
104 | - * Resolves the list of characters to make visible. |
|
105 | - * |
|
106 | - * @return array |
|
107 | - */ |
|
103 | + /** |
|
104 | + * Resolves the list of characters to make visible. |
|
105 | + * |
|
106 | + * @return array |
|
107 | + */ |
|
108 | 108 | protected function resolveSelection() : array |
109 | 109 | { |
110 | 110 | $selected = $this->selected; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function selectCharacters(string $type) : ConvertHelper_HiddenConverter |
95 | 95 | { |
96 | - if(!in_array($type, $this->selected)) { |
|
96 | + if (!in_array($type, $this->selected)) { |
|
97 | 97 | $this->selected[] = $type; |
98 | 98 | } |
99 | 99 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | { |
110 | 110 | $selected = $this->selected; |
111 | 111 | |
112 | - if(empty($this->selected)) |
|
112 | + if (empty($this->selected)) |
|
113 | 113 | { |
114 | 114 | $selected = array( |
115 | 115 | self::CHARS_WHITESPACE, |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | |
120 | 120 | $result = array(); |
121 | 121 | |
122 | - foreach($selected as $type) |
|
122 | + foreach ($selected as $type) |
|
123 | 123 | { |
124 | - if(isset($this->characters[$type])) |
|
124 | + if (isset($this->characters[$type])) |
|
125 | 125 | { |
126 | 126 | $result = array_merge($result, $this->characters[$type]); |
127 | 127 | } |
@@ -114,18 +114,18 @@ discard block |
||
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | - /** |
|
118 | - * Adds a callback as a validation method. The callback gets the |
|
119 | - * value to validate as first parameter, and any additional |
|
120 | - * parameters passed here get appended to that. |
|
121 | - * |
|
122 | - * The callback must return boolean true or false depending on |
|
123 | - * whether the value is valid. |
|
124 | - * |
|
125 | - * @param callable $callback |
|
126 | - * @param array $args |
|
127 | - * @return Request_Param |
|
128 | - */ |
|
117 | + /** |
|
118 | + * Adds a callback as a validation method. The callback gets the |
|
119 | + * value to validate as first parameter, and any additional |
|
120 | + * parameters passed here get appended to that. |
|
121 | + * |
|
122 | + * The callback must return boolean true or false depending on |
|
123 | + * whether the value is valid. |
|
124 | + * |
|
125 | + * @param callable $callback |
|
126 | + * @param array $args |
|
127 | + * @return Request_Param |
|
128 | + */ |
|
129 | 129 | public function setCallback($callback, array $args=array()) : Request_Param |
130 | 130 | { |
131 | 131 | if(!is_callable($callback)) { |
@@ -189,12 +189,12 @@ discard block |
||
189 | 189 | return $value; |
190 | 190 | } |
191 | 191 | |
192 | - /** |
|
193 | - * Runs the value through all validations that were added. |
|
194 | - * |
|
195 | - * @param mixed $value |
|
196 | - * @return mixed |
|
197 | - */ |
|
192 | + /** |
|
193 | + * Runs the value through all validations that were added. |
|
194 | + * |
|
195 | + * @param mixed $value |
|
196 | + * @return mixed |
|
197 | + */ |
|
198 | 198 | protected function applyValidations($value, bool $subval=false) |
199 | 199 | { |
200 | 200 | // go through all enqueued validations in turn, each time |
@@ -207,17 +207,17 @@ discard block |
||
207 | 207 | return $value; |
208 | 208 | } |
209 | 209 | |
210 | - /** |
|
211 | - * Validates the specified value using the validation type. Returns |
|
212 | - * the validated value. |
|
213 | - * |
|
214 | - * @param mixed $value |
|
215 | - * @param string $type |
|
216 | - * @param array $params |
|
217 | - * @param bool $subval Whether this is a subvalue in a list |
|
218 | - * @throws Request_Exception |
|
219 | - * @return mixed |
|
220 | - */ |
|
210 | + /** |
|
211 | + * Validates the specified value using the validation type. Returns |
|
212 | + * the validated value. |
|
213 | + * |
|
214 | + * @param mixed $value |
|
215 | + * @param string $type |
|
216 | + * @param array $params |
|
217 | + * @param bool $subval Whether this is a subvalue in a list |
|
218 | + * @throws Request_Exception |
|
219 | + * @return mixed |
|
220 | + */ |
|
221 | 221 | protected function validateType($value, string $type, array $params, bool $subval) |
222 | 222 | { |
223 | 223 | $class = '\AppUtils\Request_Param_Validator_'.ucfirst($type); |
@@ -286,13 +286,13 @@ discard block |
||
286 | 286 | |
287 | 287 | protected $valueType = self::VALUE_TYPE_STRING; |
288 | 288 | |
289 | - /** |
|
290 | - * Sets the variable to contain a comma-separated list of integer IDs. |
|
291 | - * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
292 | - * <code>145</code>. |
|
293 | - * |
|
294 | - * @return Request_Param |
|
295 | - */ |
|
289 | + /** |
|
290 | + * Sets the variable to contain a comma-separated list of integer IDs. |
|
291 | + * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
292 | + * <code>145</code>. |
|
293 | + * |
|
294 | + * @return Request_Param |
|
295 | + */ |
|
296 | 296 | public function setIDList() |
297 | 297 | { |
298 | 298 | $this->valueType = self::VALUE_TYPE_LIST; |
@@ -302,13 +302,13 @@ discard block |
||
302 | 302 | return $this; |
303 | 303 | } |
304 | 304 | |
305 | - /** |
|
306 | - * Sets the variable to be an alias, as defined by the |
|
307 | - * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
308 | - * |
|
309 | - * @return Request_Param |
|
310 | - * @see RegexHelper::REGEX_ALIAS |
|
311 | - */ |
|
305 | + /** |
|
306 | + * Sets the variable to be an alias, as defined by the |
|
307 | + * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
308 | + * |
|
309 | + * @return Request_Param |
|
310 | + * @see RegexHelper::REGEX_ALIAS |
|
311 | + */ |
|
312 | 312 | public function setAlias() |
313 | 313 | { |
314 | 314 | return $this->setRegex(RegexHelper::REGEX_ALIAS); |
@@ -349,12 +349,12 @@ discard block |
||
349 | 349 | return $this->setValidation(self::VALIDATION_TYPE_ALPHA); |
350 | 350 | } |
351 | 351 | |
352 | - /** |
|
353 | - * Sets the parameter value as a string containing lowercase |
|
354 | - * and/or uppercase letters, as well as numbers. |
|
355 | - * |
|
356 | - * @return Request_Param |
|
357 | - */ |
|
352 | + /** |
|
353 | + * Sets the parameter value as a string containing lowercase |
|
354 | + * and/or uppercase letters, as well as numbers. |
|
355 | + * |
|
356 | + * @return Request_Param |
|
357 | + */ |
|
358 | 358 | public function setAlnum() |
359 | 359 | { |
360 | 360 | return $this->setValidation(self::VALIDATION_TYPE_ALNUM); |
@@ -387,17 +387,17 @@ discard block |
||
387 | 387 | ); |
388 | 388 | } |
389 | 389 | |
390 | - /** |
|
391 | - * Only available for array values: the parameter must be |
|
392 | - * an array value, and the array may only contain values |
|
393 | - * specified in the values array. |
|
394 | - * |
|
395 | - * Submitted values that are not in the allowed list of |
|
396 | - * values are stripped from the value. |
|
397 | - * |
|
398 | - * @param array $values List of allowed values |
|
399 | - * @return \AppUtils\Request_Param |
|
400 | - */ |
|
390 | + /** |
|
391 | + * Only available for array values: the parameter must be |
|
392 | + * an array value, and the array may only contain values |
|
393 | + * specified in the values array. |
|
394 | + * |
|
395 | + * Submitted values that are not in the allowed list of |
|
396 | + * values are stripped from the value. |
|
397 | + * |
|
398 | + * @param array $values List of allowed values |
|
399 | + * @return \AppUtils\Request_Param |
|
400 | + */ |
|
401 | 401 | public function setValuesList(array $values) |
402 | 402 | { |
403 | 403 | $this->setArray(); |
@@ -410,11 +410,11 @@ discard block |
||
410 | 410 | ); |
411 | 411 | } |
412 | 412 | |
413 | - /** |
|
414 | - * Whether the parameter is a list of values. |
|
415 | - * |
|
416 | - * @return bool |
|
417 | - */ |
|
413 | + /** |
|
414 | + * Whether the parameter is a list of values. |
|
415 | + * |
|
416 | + * @return bool |
|
417 | + */ |
|
418 | 418 | public function isList() : bool |
419 | 419 | { |
420 | 420 | return $this->valueType === self::VALUE_TYPE_LIST; |
@@ -425,53 +425,53 @@ discard block |
||
425 | 425 | return $this->setValidation(self::VALIDATION_TYPE_ARRAY); |
426 | 426 | } |
427 | 427 | |
428 | - /** |
|
429 | - * Specifies that a JSON-encoded string is expected. |
|
430 | - * |
|
431 | - * NOTE: Numbers or quoted strings are technically valid |
|
432 | - * JSON, but are not accepted, because it is assumed |
|
433 | - * at least an array or object are expected. |
|
434 | - * |
|
435 | - * @return \AppUtils\Request_Param |
|
436 | - */ |
|
428 | + /** |
|
429 | + * Specifies that a JSON-encoded string is expected. |
|
430 | + * |
|
431 | + * NOTE: Numbers or quoted strings are technically valid |
|
432 | + * JSON, but are not accepted, because it is assumed |
|
433 | + * at least an array or object are expected. |
|
434 | + * |
|
435 | + * @return \AppUtils\Request_Param |
|
436 | + */ |
|
437 | 437 | public function setJSON() : Request_Param |
438 | 438 | { |
439 | 439 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => true)); |
440 | 440 | } |
441 | 441 | |
442 | - /** |
|
443 | - * Like {@link Request_Param::setJSON()}, but accepts |
|
444 | - * only JSON objects. Arrays will not be accepted. |
|
445 | - * |
|
446 | - * @return \AppUtils\Request_Param |
|
447 | - */ |
|
442 | + /** |
|
443 | + * Like {@link Request_Param::setJSON()}, but accepts |
|
444 | + * only JSON objects. Arrays will not be accepted. |
|
445 | + * |
|
446 | + * @return \AppUtils\Request_Param |
|
447 | + */ |
|
448 | 448 | public function setJSONObject() : Request_Param |
449 | 449 | { |
450 | 450 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => false)); |
451 | 451 | } |
452 | 452 | |
453 | - /** |
|
454 | - * The parameter is a string boolean representation. This means |
|
455 | - * it can be any of the following: "yes", "true", "no", "false". |
|
456 | - * The value is automatically converted to a boolean when retrieving |
|
457 | - * the parameter. |
|
458 | - * |
|
459 | - * @return Request_Param |
|
460 | - */ |
|
453 | + /** |
|
454 | + * The parameter is a string boolean representation. This means |
|
455 | + * it can be any of the following: "yes", "true", "no", "false". |
|
456 | + * The value is automatically converted to a boolean when retrieving |
|
457 | + * the parameter. |
|
458 | + * |
|
459 | + * @return Request_Param |
|
460 | + */ |
|
461 | 461 | public function setBoolean() : Request_Param |
462 | 462 | { |
463 | 463 | return $this->addClassFilter('Boolean'); |
464 | 464 | } |
465 | 465 | |
466 | - /** |
|
467 | - * Validates the request parameter as an MD5 string, |
|
468 | - * so that only values resembling md5 values are accepted. |
|
469 | - * |
|
470 | - * NOTE: This can only guarantee the format, not whether |
|
471 | - * it is an actual valid hash of something. |
|
472 | - * |
|
473 | - * @return \AppUtils\Request_Param |
|
474 | - */ |
|
466 | + /** |
|
467 | + * Validates the request parameter as an MD5 string, |
|
468 | + * so that only values resembling md5 values are accepted. |
|
469 | + * |
|
470 | + * NOTE: This can only guarantee the format, not whether |
|
471 | + * it is an actual valid hash of something. |
|
472 | + * |
|
473 | + * @return \AppUtils\Request_Param |
|
474 | + */ |
|
475 | 475 | public function setMD5() : Request_Param |
476 | 476 | { |
477 | 477 | return $this->setRegex(RegexHelper::REGEX_MD5); |
@@ -513,14 +513,14 @@ discard block |
||
513 | 513 | return $this; |
514 | 514 | } |
515 | 515 | |
516 | - /** |
|
517 | - * Retrieves the value of the request parameter, |
|
518 | - * applying all filters (if any) and validation |
|
519 | - * (if any). |
|
520 | - * |
|
521 | - * @param mixed $default |
|
522 | - * @return mixed |
|
523 | - */ |
|
516 | + /** |
|
517 | + * Retrieves the value of the request parameter, |
|
518 | + * applying all filters (if any) and validation |
|
519 | + * (if any). |
|
520 | + * |
|
521 | + * @param mixed $default |
|
522 | + * @return mixed |
|
523 | + */ |
|
524 | 524 | public function get($default=null) |
525 | 525 | { |
526 | 526 | $value = $this->request->getParam($this->paramName); |
@@ -608,12 +608,12 @@ discard block |
||
608 | 608 | return $this; |
609 | 609 | } |
610 | 610 | |
611 | - /** |
|
612 | - * Adds a filter that trims whitespace from the request |
|
613 | - * parameter using the PHP <code>trim</code> function. |
|
614 | - * |
|
615 | - * @return \AppUtils\Request_Param |
|
616 | - */ |
|
611 | + /** |
|
612 | + * Adds a filter that trims whitespace from the request |
|
613 | + * parameter using the PHP <code>trim</code> function. |
|
614 | + * |
|
615 | + * @return \AppUtils\Request_Param |
|
616 | + */ |
|
617 | 617 | public function addFilterTrim() : Request_Param |
618 | 618 | { |
619 | 619 | // to guarantee we only work with strings |
@@ -622,13 +622,13 @@ discard block |
||
622 | 622 | return $this->addCallbackFilter('trim'); |
623 | 623 | } |
624 | 624 | |
625 | - /** |
|
626 | - * Converts the value to a string, even if it is not |
|
627 | - * a string value. Complex types like arrays and objects |
|
628 | - * are converted to an empty string. |
|
629 | - * |
|
630 | - * @return \AppUtils\Request_Param |
|
631 | - */ |
|
625 | + /** |
|
626 | + * Converts the value to a string, even if it is not |
|
627 | + * a string value. Complex types like arrays and objects |
|
628 | + * are converted to an empty string. |
|
629 | + * |
|
630 | + * @return \AppUtils\Request_Param |
|
631 | + */ |
|
632 | 632 | public function addStringFilter() : Request_Param |
633 | 633 | { |
634 | 634 | return $this->addClassFilter('String'); |
@@ -678,12 +678,12 @@ discard block |
||
678 | 678 | return $this->addCallbackFilter('strip_tags', array($allowedTags)); |
679 | 679 | } |
680 | 680 | |
681 | - /** |
|
682 | - * Adds a filter that strips all whitespace from the |
|
683 | - * request parameter, from spaces to tabs and newlines. |
|
684 | - * |
|
685 | - * @return \AppUtils\Request_Param |
|
686 | - */ |
|
681 | + /** |
|
682 | + * Adds a filter that strips all whitespace from the |
|
683 | + * request parameter, from spaces to tabs and newlines. |
|
684 | + * |
|
685 | + * @return \AppUtils\Request_Param |
|
686 | + */ |
|
687 | 687 | public function addStripWhitespaceFilter() : Request_Param |
688 | 688 | { |
689 | 689 | // to ensure we only work with strings. |
@@ -692,14 +692,14 @@ discard block |
||
692 | 692 | return $this->addClassFilter('StripWhitespace'); |
693 | 693 | } |
694 | 694 | |
695 | - /** |
|
696 | - * Adds a filter that transforms comma separated values |
|
697 | - * into an array of values. |
|
698 | - * |
|
699 | - * @param bool $trimEntries Trim whitespace from each entry? |
|
700 | - * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
701 | - * @return \AppUtils\Request_Param |
|
702 | - */ |
|
695 | + /** |
|
696 | + * Adds a filter that transforms comma separated values |
|
697 | + * into an array of values. |
|
698 | + * |
|
699 | + * @param bool $trimEntries Trim whitespace from each entry? |
|
700 | + * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
701 | + * @return \AppUtils\Request_Param |
|
702 | + */ |
|
703 | 703 | public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
704 | 704 | { |
705 | 705 | $this->setArray(); |
@@ -724,12 +724,12 @@ discard block |
||
724 | 724 | ); |
725 | 725 | } |
726 | 726 | |
727 | - /** |
|
728 | - * Adds a filter that encodes all HTML special characters |
|
729 | - * using the PHP <code>htmlspecialchars</code> function. |
|
730 | - * |
|
731 | - * @return \AppUtils\Request_Param |
|
732 | - */ |
|
727 | + /** |
|
728 | + * Adds a filter that encodes all HTML special characters |
|
729 | + * using the PHP <code>htmlspecialchars</code> function. |
|
730 | + * |
|
731 | + * @return \AppUtils\Request_Param |
|
732 | + */ |
|
733 | 733 | public function addHTMLSpecialcharsFilter() : Request_Param |
734 | 734 | { |
735 | 735 | return $this->addCallbackFilter('htmlspecialchars', array(ENT_QUOTES, 'UTF-8')); |
@@ -742,14 +742,14 @@ discard block |
||
742 | 742 | |
743 | 743 | protected $required = false; |
744 | 744 | |
745 | - /** |
|
746 | - * Marks this request parameter as required. To use this feature, |
|
747 | - * you have to call the request's {@link Request::validate()} |
|
748 | - * method. |
|
749 | - * |
|
750 | - * @return Request_Param |
|
751 | - * @see Request::validate() |
|
752 | - */ |
|
745 | + /** |
|
746 | + * Marks this request parameter as required. To use this feature, |
|
747 | + * you have to call the request's {@link Request::validate()} |
|
748 | + * method. |
|
749 | + * |
|
750 | + * @return Request_Param |
|
751 | + * @see Request::validate() |
|
752 | + */ |
|
753 | 753 | public function makeRequired() : Request_Param |
754 | 754 | { |
755 | 755 | $this->required = true; |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | * @param array $args |
127 | 127 | * @return Request_Param |
128 | 128 | */ |
129 | - public function setCallback($callback, array $args=array()) : Request_Param |
|
129 | + public function setCallback($callback, array $args = array()) : Request_Param |
|
130 | 130 | { |
131 | - if(!is_callable($callback)) { |
|
131 | + if (!is_callable($callback)) { |
|
132 | 132 | throw new Request_Exception( |
133 | 133 | 'Not a valid callback', |
134 | 134 | 'The specified callback is not a valid callable entity.', |
@@ -159,22 +159,22 @@ discard block |
||
159 | 159 | // first off, apply filtering |
160 | 160 | $value = $this->filter($value); |
161 | 161 | |
162 | - if($this->valueType === self::VALUE_TYPE_LIST) |
|
162 | + if ($this->valueType === self::VALUE_TYPE_LIST) |
|
163 | 163 | { |
164 | - if(!is_array($value)) |
|
164 | + if (!is_array($value)) |
|
165 | 165 | { |
166 | 166 | $value = explode(',', $value); |
167 | 167 | } |
168 | 168 | |
169 | 169 | $keep = array(); |
170 | 170 | |
171 | - foreach($value as $subval) |
|
171 | + foreach ($value as $subval) |
|
172 | 172 | { |
173 | 173 | $subval = $this->filter($subval); |
174 | 174 | |
175 | 175 | $subval = $this->applyValidations($subval, true); |
176 | 176 | |
177 | - if($subval !== null) { |
|
177 | + if ($subval !== null) { |
|
178 | 178 | $keep[] = $subval; |
179 | 179 | } |
180 | 180 | } |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * @param mixed $value |
196 | 196 | * @return mixed |
197 | 197 | */ |
198 | - protected function applyValidations($value, bool $subval=false) |
|
198 | + protected function applyValidations($value, bool $subval = false) |
|
199 | 199 | { |
200 | 200 | // go through all enqueued validations in turn, each time |
201 | 201 | // replacing the value with the adjusted, validated value. |
202 | - foreach($this->validations as $validateDef) |
|
202 | + foreach ($this->validations as $validateDef) |
|
203 | 203 | { |
204 | 204 | $value = $this->validateType($value, $validateDef['type'], $validateDef['params'], $subval); |
205 | 205 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | { |
223 | 223 | $class = '\AppUtils\Request_Param_Validator_'.ucfirst($type); |
224 | 224 | |
225 | - if(!class_exists($class)) |
|
225 | + if (!class_exists($class)) |
|
226 | 226 | { |
227 | 227 | throw new Request_Exception( |
228 | 228 | 'Unknown validation type.', |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | { |
377 | 377 | $args = func_get_args(); // cannot be used as function parameter in some PHP versions |
378 | 378 | |
379 | - if(is_array($args[0])) |
|
379 | + if (is_array($args[0])) |
|
380 | 380 | { |
381 | 381 | $args = $args[0]; |
382 | 382 | } |
@@ -521,10 +521,10 @@ discard block |
||
521 | 521 | * @param mixed $default |
522 | 522 | * @return mixed |
523 | 523 | */ |
524 | - public function get($default=null) |
|
524 | + public function get($default = null) |
|
525 | 525 | { |
526 | 526 | $value = $this->request->getParam($this->paramName); |
527 | - if($value !== null && $value !== '') { |
|
527 | + if ($value !== null && $value !== '') { |
|
528 | 528 | return $value; |
529 | 529 | } |
530 | 530 | |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | { |
544 | 544 | $total = count($this->filters); |
545 | 545 | for ($i = 0; $i < $total; $i++) { |
546 | - $method = 'applyFilter_' . $this->filters[$i]['type']; |
|
546 | + $method = 'applyFilter_'.$this->filters[$i]['type']; |
|
547 | 547 | $value = $this->$method($value, $this->filters[$i]['params']); |
548 | 548 | } |
549 | 549 | |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | * @param bool $stripEmptyEntries Remove empty entries from the array? |
701 | 701 | * @return \AppUtils\Request_Param |
702 | 702 | */ |
703 | - public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
|
703 | + public function addCommaSeparatedFilter(bool $trimEntries = true, bool $stripEmptyEntries = true) : Request_Param |
|
704 | 704 | { |
705 | 705 | $this->setArray(); |
706 | 706 | |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | ); |
714 | 714 | } |
715 | 715 | |
716 | - protected function addClassFilter(string $name, array $params=array()) : Request_Param |
|
716 | + protected function addClassFilter(string $name, array $params = array()) : Request_Param |
|
717 | 717 | { |
718 | 718 | return $this->addFilter( |
719 | 719 | self::FILTER_TYPE_CLASS, |