Result.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * League.Uri (https://uri.thephpleague.com)
  4. *
  5. * (c) Ignace Nyamagana Butera <nyamsprod@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. declare(strict_types=1);
  11. namespace League\Uri\Idna;
  12. /**
  13. * @see https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/uidna_8h.html
  14. */
  15. final class Result
  16. {
  17. private function __construct(
  18. private readonly string $domain,
  19. private readonly bool $isTransitionalDifferent,
  20. /** @var array<Error> */
  21. private readonly array $errors
  22. ) {
  23. }
  24. /**
  25. * @param array{result:string, isTransitionalDifferent:bool, errors:int} $infos
  26. */
  27. public static function fromIntl(array $infos): self
  28. {
  29. return new self($infos['result'], $infos['isTransitionalDifferent'], Error::filterByErrorBytes($infos['errors']));
  30. }
  31. public function domain(): string
  32. {
  33. return $this->domain;
  34. }
  35. public function isTransitionalDifferent(): bool
  36. {
  37. return $this->isTransitionalDifferent;
  38. }
  39. /**
  40. * @return array<Error>
  41. */
  42. public function errors(): array
  43. {
  44. return $this->errors;
  45. }
  46. public function hasErrors(): bool
  47. {
  48. return [] !== $this->errors;
  49. }
  50. public function hasError(Error $error): bool
  51. {
  52. return in_array($error, $this->errors, true);
  53. }
  54. }