DomainInfo.php 906 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
  4. * SPDX-License-Identifier: MIT
  5. */
  6. declare(strict_types=1);
  7. namespace Respect\Validation\Helpers;
  8. use function file_exists;
  9. use function mb_strtoupper;
  10. final class DomainInfo
  11. {
  12. /**
  13. * @var mixed[]
  14. */
  15. private $data;
  16. /**
  17. * @var mixed[]
  18. */
  19. private static $runtimeCache = [];
  20. public function __construct(string $tld)
  21. {
  22. $tld = mb_strtoupper($tld);
  23. if (!isset(static::$runtimeCache[$tld])) {
  24. $filename = __DIR__ . '/../../data/domain/public-suffix/' . $tld . '.php';
  25. static::$runtimeCache[$tld] = file_exists($filename) ? require $filename : [];
  26. }
  27. $this->data = static::$runtimeCache[$tld];
  28. }
  29. /**
  30. * @return array<string>
  31. */
  32. public function getPublicSuffixes(): array
  33. {
  34. return $this->data;
  35. }
  36. }