@@ -137,9 +137,9 @@ private function transformToAscii(string $domain, int $option): array
137
137
return [strtolower ($ domain ), ['isTransitionalDifferent ' => false ]];
138
138
}
139
139
140
- $ output = idn_to_ascii ($ domain , $ option , INTL_IDNA_VARIANT_UTS46 , $ info );
141
- if (0 !== $ info ['errors ' ]) {
142
- throw new InvalidDomain (sprintf ('The host `%s` is invalid : %s ' , $ domain , self ::getIdnErrors ($ info ['errors ' ])));
140
+ $ output = idn_to_ascii ($ domain , $ option , INTL_IDNA_VARIANT_UTS46 , $ infos );
141
+ if (0 !== $ infos ['errors ' ]) {
142
+ throw new InvalidDomain (sprintf ('The host `%s` is invalid : %s ' , $ domain , self ::getIdnErrors ($ infos ['errors ' ])));
143
143
}
144
144
145
145
// @codeCoverageIgnoreStart
@@ -149,7 +149,7 @@ private function transformToAscii(string $domain, int $option): array
149
149
// @codeCoverageIgnoreEnd
150
150
151
151
if (false === strpos ($ output , '% ' )) {
152
- return [$ output , $ info ];
152
+ return [$ output , $ infos ];
153
153
}
154
154
155
155
throw new InvalidDomain (sprintf ('The host `%s` is invalid: it contains invalid characters ' , $ domain ));
@@ -188,7 +188,7 @@ private function idnToUnicode(string $domain, int $option = IDNA_DEFAULT): strin
188
188
* Filter and format the domain to ensure it is valid.
189
189
* Returns an array containing the formatted domain name in lowercase
190
190
* with its associated labels in reverse order
191
- * For example: setLabels ('wWw.uLb.Ac.be') should return ['www.ulb.ac.be', ['be', 'ac', 'ulb', 'www']];.
191
+ * For example: parse ('wWw.uLb.Ac.be') should return ['www.ulb.ac.be', ['be', 'ac', 'ulb', 'www']];.
192
192
*
193
193
* @param mixed $domain
194
194
* @param int $asciiOption
@@ -198,18 +198,18 @@ private function idnToUnicode(string $domain, int $option = IDNA_DEFAULT): strin
198
198
*
199
199
* @return array
200
200
*/
201
- private function setLabels ($ domain = null , int $ asciiOption = 0 , int $ unicodeOption = 0 ): array
201
+ private function parse ($ domain = null , int $ asciiOption = 0 , int $ unicodeOption = 0 ): array
202
202
{
203
203
if ($ domain instanceof DomainInterface) {
204
204
$ domain = $ domain ->getContent ();
205
205
}
206
206
207
207
if (null === $ domain ) {
208
- return [[], [ 'isTransitionalDifferent ' => false ] ];
208
+ return [' labels ' => [], 'isTransitionalDifferent ' => false ];
209
209
}
210
210
211
211
if ('' === $ domain ) {
212
- return [['' ], [ 'isTransitionalDifferent ' => false ] ];
212
+ return [' labels ' => ['' ], 'isTransitionalDifferent ' => false ];
213
213
}
214
214
215
215
if (!is_scalar ($ domain ) && !method_exists ($ domain , '__toString ' )) {
@@ -233,8 +233,8 @@ private function setLabels($domain = null, int $asciiOption = 0, int $unicodeOpt
233
233
^(?:(?®_name)\.){0,126}(?®_name)\.?$/ix ' ;
234
234
if (1 === preg_match ($ domain_name , $ formatted_domain )) {
235
235
return [
236
- array_reverse (explode ('. ' , strtolower ($ formatted_domain ))),
237
- [ 'isTransitionalDifferent ' => false ] ,
236
+ ' labels ' => array_reverse (explode ('. ' , strtolower ($ formatted_domain ))),
237
+ 'isTransitionalDifferent ' => false ,
238
238
];
239
239
}
240
240
@@ -251,10 +251,8 @@ private function setLabels($domain = null, int $asciiOption = 0, int $unicodeOpt
251
251
}
252
252
253
253
list ($ ascii_domain , $ infos ) = $ this ->transformToAscii ($ domain , $ asciiOption );
254
+ $ infos ['labels ' ] = array_reverse (explode ('. ' , $ this ->idnToUnicode ($ ascii_domain , $ unicodeOption )));
254
255
255
- return [
256
- array_reverse (explode ('. ' , $ this ->idnToUnicode ($ ascii_domain , $ unicodeOption ))),
257
- $ infos ,
258
- ];
256
+ return $ infos ;
259
257
}
260
258
}
0 commit comments