Skip to content

Commit d2f77d3

Browse files
committed
Merge branch 'feature/alternate-IDNA-setters' into develop
2 parents d4110ac + 4358200 commit d2f77d3

File tree

9 files changed

+260
-66
lines changed

9 files changed

+260
-66
lines changed

src/Domain.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ public function labels(): array
336336
}
337337

338338
/**
339-
* Set IDNA_* options for functions idn_to_ascii.
339+
* Gets conversion options for idn_to_ascii.
340+
*
341+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
340342
*
341343
* @see https://www.php.net/manual/en/intl.constants.php
342344
*
@@ -348,7 +350,9 @@ public function getAsciiIDNAOption(): int
348350
}
349351

350352
/**
351-
* Set IDNA_* options for functions idn_to_utf8.
353+
* Gets conversion options for idn_to_utf8.
354+
*
355+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
352356
*
353357
* @see https://www.php.net/manual/en/intl.constants.php
354358
*
@@ -360,7 +364,7 @@ public function getUnicodeIDNAOption(): int
360364
}
361365

362366
/**
363-
* return true if domain contains deviation characters.
367+
* Returns true if domain contains deviation characters.
364368
*
365369
* @see http://unicode.org/reports/tr46/#Transition_Considerations
366370
*
@@ -777,24 +781,44 @@ public function withoutLabel(int $key, int ...$keys): self
777781

778782
return new self($domain, $this->publicSuffix, $this->asciiIDNAOption, $this->unicodeIDNAOption);
779783
}
780-
784+
785+
/**
786+
* Sets conversion options for idn_to_ascii.
787+
*
788+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
789+
*
790+
* @see https://www.php.net/manual/en/intl.constants.php
791+
*
792+
* @param int $option
793+
*
794+
* @return self
795+
*/
796+
public function withAsciiIDNAOption(int $option): self
797+
{
798+
if ($option === $this->asciiIDNAOption) {
799+
return $this;
800+
}
801+
802+
return new self($this->domain, $this->publicSuffix, $option, $this->unicodeIDNAOption);
803+
}
804+
781805
/**
782-
* Set IDNA_* options for functions idn_to_ascii, idn_to_utf8.
806+
* Sets conversion options for idn_to_utf8.
807+
*
808+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
809+
*
783810
* @see https://www.php.net/manual/en/intl.constants.php
784811
*
785-
* @param int $asciiIDNAOption
786-
* @param int $unicodeIDNAOption
812+
* @param int $option
787813
*
788814
* @return self
789815
*/
790-
public function withIDNAOptions(int $asciiIDNAOption, int $unicodeIDNAOption): self
816+
public function withUnicodeIDNAOption(int $option): self
791817
{
792-
if ($asciiIDNAOption === $this->asciiIDNAOption
793-
&& $unicodeIDNAOption === $this->unicodeIDNAOption
794-
) {
818+
if ($option === $this->unicodeIDNAOption) {
795819
return $this;
796820
}
797821

798-
return new self($this->domain, $this->publicSuffix, $asciiIDNAOption, $unicodeIDNAOption);
822+
return new self($this->domain, $this->publicSuffix, $this->asciiIDNAOption, $option);
799823
}
800824
}

src/PublicSuffix.php

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ public function labels(): array
264264
}
265265

266266
/**
267-
* Set IDNA_* options for functions idn_to_ascii.
267+
* Gets conversion options for idn_to_ascii.
268+
*
269+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
268270
*
269271
* @see https://www.php.net/manual/en/intl.constants.php
270272
*
@@ -276,7 +278,9 @@ public function getAsciiIDNAOption(): int
276278
}
277279

278280
/**
279-
* Set IDNA_* options for functions idn_to_utf8.
281+
* Gets conversion options for idn_to_utf8.
282+
*
283+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
280284
*
281285
* @see https://www.php.net/manual/en/intl.constants.php
282286
*
@@ -288,7 +292,7 @@ public function getUnicodeIDNAOption(): int
288292
}
289293

290294
/**
291-
* return true if domain contains deviation characters.
295+
* Returns true if domain contains deviation characters.
292296
*
293297
* @see http://unicode.org/reports/tr46/#Transition_Considerations
294298
*
@@ -367,20 +371,42 @@ public function toUnicode()
367371
}
368372

369373
/**
370-
* Set IDNA_* options for functions idn_to_ascii, idn_to_utf8.
374+
* Sets conversion options for idn_to_ascii.
375+
*
376+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
377+
*
378+
* @see https://www.php.net/manual/en/intl.constants.php
379+
*
380+
* @param int $option
381+
*
382+
* @return self
383+
*/
384+
public function withAsciiIDNAOption(int $option): self
385+
{
386+
if ($option === $this->asciiIDNAOption) {
387+
return $this;
388+
}
389+
390+
return new self($this->publicSuffix, $this->section, $option, $this->unicodeIDNAOption);
391+
}
392+
393+
/**
394+
* Sets conversion options for idn_to_utf8.
395+
*
396+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
397+
*
371398
* @see https://www.php.net/manual/en/intl.constants.php
372399
*
373-
* @param int $asciiIDNAOption
374-
* @param int $unicodeIDNAOption
400+
* @param int $option
375401
*
376402
* @return self
377403
*/
378-
public function withIDNAOptions(int $asciiIDNAOption, int $unicodeIDNAOption): self
404+
public function withUnicodeIDNAOption(int $option): self
379405
{
380-
if ($asciiIDNAOption === $this->asciiIDNAOption && $unicodeIDNAOption === $this->unicodeIDNAOption) {
406+
if ($option === $this->unicodeIDNAOption) {
381407
return $this;
382408
}
383409

384-
return new self($this->publicSuffix, $this->section, $asciiIDNAOption, $unicodeIDNAOption);
410+
return new self($this->publicSuffix, $this->section, $this->asciiIDNAOption, $option);
385411
}
386412
}

src/Rules.php

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ public static function __set_state(array $properties): self
144144
}
145145

146146
/**
147-
* Set IDNA_* options for functions idn_to_ascii.
147+
* Gets conversion options for idn_to_ascii.
148+
*
149+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
148150
*
149151
* @see https://www.php.net/manual/en/intl.constants.php
150152
*
@@ -156,7 +158,9 @@ public function getAsciiIDNAOption(): int
156158
}
157159

158160
/**
159-
* Set IDNA_* options for functions idn_to_utf8.
161+
* Gets conversion options for idn_to_utf8.
162+
*
163+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
160164
*
161165
* @see https://www.php.net/manual/en/intl.constants.php
162166
*
@@ -193,8 +197,10 @@ public function getPublicSuffix($domain, string $section = self::ALL_DOMAINS): P
193197

194198
/**
195199
* Returns PSL info for a given domain.
196-
* @param mixed $domain
197-
* @param string $section
200+
*
201+
* @param mixed $domain
202+
* @param string $section
203+
*
198204
* @return Domain
199205
*/
200206
public function resolve($domain, string $section = self::ALL_DOMAINS): Domain
@@ -310,22 +316,46 @@ private function findPublicSuffixFromSection(DomainInterface $domain, string $se
310316
}
311317

312318
/**
313-
* Set IDNA_* options for functions idn_to_ascii, idn_to_utf8.
319+
* Sets conversion options for idn_to_ascii.
320+
*
321+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
322+
*
314323
* @see https://www.php.net/manual/en/intl.constants.php
315324
*
316325
* @param int $asciiIDNAOption
317-
* @param int $unicodeIDNAOption
326+
*
327+
* @return self
318328
*/
319-
public function withIDNAOptions(int $asciiIDNAOption, int $unicodeIDNAOption): self
329+
public function withAsciiIDNAOption(int $asciiIDNAOption): self
320330
{
321-
if ($asciiIDNAOption === $this->asciiIDNAOption
322-
&& $unicodeIDNAOption === $this->unicodeIDNAOption
323-
) {
331+
if ($asciiIDNAOption === $this->asciiIDNAOption) {
324332
return $this;
325333
}
326334

327335
$clone = clone $this;
328336
$clone->asciiIDNAOption = $asciiIDNAOption;
337+
338+
return $clone;
339+
}
340+
341+
/**
342+
* Sets conversion options for idn_to_utf8.
343+
*
344+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
345+
*
346+
* @see https://www.php.net/manual/en/intl.constants.php
347+
*
348+
* @param int $unicodeIDNAOption
349+
*
350+
* @return self
351+
*/
352+
public function withUnicodeIDNAOption(int $unicodeIDNAOption): self
353+
{
354+
if ($unicodeIDNAOption === $this->unicodeIDNAOption) {
355+
return $this;
356+
}
357+
358+
$clone = clone $this;
329359
$clone->unicodeIDNAOption = $unicodeIDNAOption;
330360

331361
return $clone;

src/TLDConverter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use function strpos;
2525
use function trim;
2626
use const DATE_ATOM;
27+
use const IDNA_DEFAULT;
2728

2829
/**
2930
* IANA Root Zone Database Parser.

src/TopLevelDomains.php

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ public function getModifiedDate(): DateTimeImmutable
177177
}
178178

179179
/**
180-
* Set IDNA_* options for functions idn_to_ascii.
180+
* Gets conversion options for idn_to_ascii.
181+
*
182+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
181183
*
182184
* @see https://www.php.net/manual/en/intl.constants.php
183185
*
@@ -189,7 +191,9 @@ public function getAsciiIDNAOption(): int
189191
}
190192

191193
/**
192-
* Set IDNA_* options for functions idn_to_utf8.
194+
* Gets conversion options for idn_to_utf8.
195+
*
196+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
193197
*
194198
* @see https://www.php.net/manual/en/intl.constants.php
195199
*
@@ -311,25 +315,47 @@ public function resolve($domain): Domain
311315
}
312316

313317
/**
314-
* Set IDNA_* options for functions idn_to_ascii, idn_to_utf8.
318+
* Sets conversion options for idn_to_ascii.
319+
*
320+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
321+
*
322+
* @see https://www.php.net/manual/en/intl.constants.php
323+
*
324+
* @param int $option
325+
*
326+
* @return self
327+
*/
328+
public function withAsciiIDNAOption(int $option): self
329+
{
330+
if ($option === $this->asciiIDNAOption) {
331+
return $this;
332+
}
333+
334+
$clone = clone $this;
335+
$clone->asciiIDNAOption = $option;
336+
337+
return $clone;
338+
}
339+
340+
/**
341+
* Sets conversion options for idn_to_utf8.
342+
*
343+
* combination of IDNA_* constants (except IDNA_ERROR_* constants).
344+
*
315345
* @see https://www.php.net/manual/en/intl.constants.php
316346
*
317-
* @param int $asciiIDNAOption
318-
* @param int $unicodeIDNAOption
347+
* @param int $option
319348
*
320349
* @return self
321350
*/
322-
public function withIDNAOptions(int $asciiIDNAOption, int $unicodeIDNAOption): self
351+
public function withUnicodeIDNAOption(int $option): self
323352
{
324-
if ($asciiIDNAOption === $this->asciiIDNAOption
325-
&& $unicodeIDNAOption === $this->unicodeIDNAOption
326-
) {
353+
if ($option === $this->unicodeIDNAOption) {
327354
return $this;
328355
}
329356

330357
$clone = clone $this;
331-
$clone->asciiIDNAOption = $asciiIDNAOption;
332-
$clone->unicodeIDNAOption = $unicodeIDNAOption;
358+
$clone->unicodeIDNAOption = $option;
333359

334360
return $clone;
335361
}

0 commit comments

Comments
 (0)