37
37
use function strlen ;
38
38
use function strpos ;
39
39
use function substr ;
40
+ use const IDNA_DEFAULT ;
40
41
41
42
/**
42
43
* Domain Value Object.
@@ -326,6 +327,42 @@ public function keys(string $label): array
326
327
return array_keys ($ this ->labels , $ label , true );
327
328
}
328
329
330
+ /**
331
+ * Set IDNA_* options for functions idn_to_ascii.
332
+ *
333
+ * @see https://www.php.net/manual/en/intl.constants.php
334
+ *
335
+ * @return int
336
+ */
337
+ public function getAsciiIDNAOption (): int
338
+ {
339
+ return $ this ->asciiIDNAOption ;
340
+ }
341
+
342
+ /**
343
+ * Set IDNA_* options for functions idn_to_utf8.
344
+ *
345
+ * @see https://www.php.net/manual/en/intl.constants.php
346
+ *
347
+ * @return int
348
+ */
349
+ public function getUnicodeIDNAOption (): int
350
+ {
351
+ return $ this ->unicodeIDNAOption ;
352
+ }
353
+
354
+ /**
355
+ * return true if domain contains deviation characters.
356
+ *
357
+ * @see http://unicode.org/reports/tr46/#Transition_Considerations
358
+ *
359
+ * @return bool
360
+ */
361
+ public function isTransitionalDifferent (): bool
362
+ {
363
+ return $ this ->isTransitionalDifferent ;
364
+ }
365
+
329
366
/**
330
367
* Returns the registrable domain.
331
368
*
@@ -423,7 +460,7 @@ public function toAscii()
423
460
return $ this ;
424
461
}
425
462
426
- return new self ($ domain , $ this ->publicSuffix , $ this ->getAsciiIDNAOption () , $ this ->getUnicodeIDNAOption () );
463
+ return new self ($ domain , $ this ->publicSuffix , $ this ->asciiIDNAOption , $ this ->unicodeIDNAOption );
427
464
}
428
465
429
466
/**
@@ -438,8 +475,8 @@ public function toUnicode()
438
475
return new self (
439
476
$ this ->idnToUnicode ($ this ->domain , $ this ->unicodeIDNAOption ),
440
477
$ this ->publicSuffix ,
441
- $ this ->getAsciiIDNAOption () ,
442
- $ this ->getUnicodeIDNAOption ()
478
+ $ this ->asciiIDNAOption ,
479
+ $ this ->unicodeIDNAOption
443
480
);
444
481
}
445
482
@@ -464,8 +501,8 @@ public function resolve($publicSuffix): self
464
501
$ publicSuffix = new PublicSuffix (
465
502
$ publicSuffix ,
466
503
'' ,
467
- $ this ->getAsciiIDNAOption () ,
468
- $ this ->getUnicodeIDNAOption ()
504
+ $ this ->asciiIDNAOption ,
505
+ $ this ->unicodeIDNAOption
469
506
);
470
507
}
471
508
@@ -474,7 +511,7 @@ public function resolve($publicSuffix): self
474
511
return $ this ;
475
512
}
476
513
477
- return new self ($ this ->domain , $ publicSuffix , $ this ->getAsciiIDNAOption () , $ this ->getUnicodeIDNAOption () );
514
+ return new self ($ this ->domain , $ publicSuffix , $ this ->asciiIDNAOption , $ this ->unicodeIDNAOption );
478
515
}
479
516
480
517
/**
@@ -496,8 +533,8 @@ public function withPublicSuffix($publicSuffix): self
496
533
$ publicSuffix = new PublicSuffix (
497
534
$ publicSuffix ,
498
535
'' ,
499
- $ this ->getAsciiIDNAOption () ,
500
- $ this ->getUnicodeIDNAOption ()
536
+ $ this ->asciiIDNAOption ,
537
+ $ this ->unicodeIDNAOption
501
538
);
502
539
}
503
540
@@ -508,14 +545,14 @@ public function withPublicSuffix($publicSuffix): self
508
545
509
546
$ domain = implode ('. ' , array_reverse (array_slice ($ this ->labels , count ($ this ->publicSuffix ))));
510
547
if (null === $ publicSuffix ->getContent ()) {
511
- return new self ($ domain , null , $ this ->getAsciiIDNAOption () , $ this ->getUnicodeIDNAOption () );
548
+ return new self ($ domain , null , $ this ->asciiIDNAOption , $ this ->unicodeIDNAOption );
512
549
}
513
550
514
551
return new self (
515
552
$ domain .'. ' .$ publicSuffix ->getContent (),
516
553
$ publicSuffix ,
517
- $ this ->getAsciiIDNAOption () ,
518
- $ this ->getUnicodeIDNAOption ()
554
+ $ this ->asciiIDNAOption ,
555
+ $ this ->unicodeIDNAOption
519
556
);
520
557
}
521
558
@@ -547,16 +584,16 @@ public function withSubDomain($subDomain): self
547
584
return new self (
548
585
$ this ->registrableDomain ,
549
586
$ this ->publicSuffix ,
550
- $ this ->getAsciiIDNAOption () ,
551
- $ this ->getUnicodeIDNAOption ()
587
+ $ this ->asciiIDNAOption ,
588
+ $ this ->unicodeIDNAOption
552
589
);
553
590
}
554
591
555
592
return new self (
556
593
$ subDomain .'. ' .$ this ->registrableDomain ,
557
594
$ this ->publicSuffix ,
558
- $ this ->getAsciiIDNAOption () ,
559
- $ this ->getUnicodeIDNAOption ()
595
+ $ this ->asciiIDNAOption ,
596
+ $ this ->unicodeIDNAOption
560
597
);
561
598
}
562
599
@@ -668,16 +705,16 @@ public function withLabel(int $key, $label): self
668
705
return new self (
669
706
implode ('. ' , array_reverse ($ labels )),
670
707
null ,
671
- $ this ->getAsciiIDNAOption () ,
672
- $ this ->getUnicodeIDNAOption ()
708
+ $ this ->asciiIDNAOption ,
709
+ $ this ->unicodeIDNAOption
673
710
);
674
711
}
675
712
676
713
return new self (
677
714
implode ('. ' , array_reverse ($ labels )),
678
715
$ this ->publicSuffix ,
679
- $ this ->getAsciiIDNAOption () ,
680
- $ this ->getUnicodeIDNAOption ()
716
+ $ this ->asciiIDNAOption ,
717
+ $ this ->unicodeIDNAOption
681
718
);
682
719
}
683
720
@@ -721,47 +758,35 @@ public function withoutLabel(int $key, int ...$keys): self
721
758
}
722
759
723
760
if ([] === $ labels ) {
724
- return new self (null , null , $ this ->getAsciiIDNAOption () , $ this ->getUnicodeIDNAOption () );
761
+ return new self (null , null , $ this ->asciiIDNAOption , $ this ->unicodeIDNAOption );
725
762
}
726
763
727
764
$ domain = implode ('. ' , array_reverse ($ labels ));
728
765
$ psContent = $ this ->publicSuffix ->getContent ();
729
766
if (null === $ psContent || '. ' .$ psContent !== substr ($ domain , - strlen ($ psContent ) - 1 )) {
730
- return new self ($ domain , null , $ this ->getAsciiIDNAOption () , $ this ->getUnicodeIDNAOption () );
767
+ return new self ($ domain , null , $ this ->asciiIDNAOption , $ this ->unicodeIDNAOption );
731
768
}
732
769
733
- return new self ($ domain , $ this ->publicSuffix , $ this ->getAsciiIDNAOption (), $ this ->getUnicodeIDNAOption ());
734
- }
735
-
736
-
737
- public function getAsciiIDNAOption (): int
738
- {
739
- return $ this ->asciiIDNAOption ;
770
+ return new self ($ domain , $ this ->publicSuffix , $ this ->asciiIDNAOption , $ this ->unicodeIDNAOption );
740
771
}
741
772
742
- public function getUnicodeIDNAOption (): int
743
- {
744
- return $ this ->unicodeIDNAOption ;
745
- }
746
773
/**
747
- * Set IDNA_* options for functions idn_to_ascii, idn_to_utf .
774
+ * Set IDNA_* options for functions idn_to_ascii, idn_to_utf8 .
748
775
* @see https://www.php.net/manual/en/intl.constants.php
749
- * @param int $forAscii
750
- * @param int $forUnicode
751
- * @return $this
776
+ *
777
+ * @param int $asciiIDNAOption
778
+ * @param int $unicodeIDNAOption
779
+ *
780
+ * @return self
752
781
*/
753
- public function withIDNAOptions (int $ forAscii , int $ forUnicode )
754
- {
755
- return new self ($ this ->domain , $ this ->publicSuffix , $ forAscii , $ forUnicode );
756
- }
757
-
758
- /**
759
- * return true if domain contains deviation characters.
760
- * @see http://unicode.org/reports/tr46/#Transition_Considerations
761
- * @return bool
762
- **/
763
- public function isTransitionalDifferent (): bool
782
+ public function withIDNAOptions (int $ asciiIDNAOption , int $ unicodeIDNAOption ): self
764
783
{
765
- return $ this ->isTransitionalDifferent ;
784
+ if ($ asciiIDNAOption === $ this ->asciiIDNAOption
785
+ && $ unicodeIDNAOption === $ this ->unicodeIDNAOption
786
+ ) {
787
+ return $ this ;
788
+ }
789
+
790
+ return new self ($ this ->domain , $ this ->publicSuffix , $ asciiIDNAOption , $ unicodeIDNAOption );
766
791
}
767
792
}
0 commit comments