Error.php 2.8 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. namespace League\Uri\Idna;
  11. enum Error: int
  12. {
  13. case NONE = 0;
  14. case EMPTY_LABEL = 1;
  15. case LABEL_TOO_LONG = 2;
  16. case DOMAIN_NAME_TOO_LONG = 4;
  17. case LEADING_HYPHEN = 8;
  18. case TRAILING_HYPHEN = 0x10;
  19. case HYPHEN_3_4 = 0x20;
  20. case LEADING_COMBINING_MARK = 0x40;
  21. case DISALLOWED = 0x80;
  22. case PUNYCODE = 0x100;
  23. case LABEL_HAS_DOT = 0x200;
  24. case INVALID_ACE_LABEL = 0x400;
  25. case BIDI = 0x800;
  26. case CONTEXTJ = 0x1000;
  27. case CONTEXTO_PUNCTUATION = 0x2000;
  28. case CONTEXTO_DIGITS = 0x4000;
  29. public function description(): string
  30. {
  31. return match ($this) {
  32. self::NONE => 'No error has occurred',
  33. self::EMPTY_LABEL => 'a non-final domain name label (or the whole domain name) is empty',
  34. self::LABEL_TOO_LONG => 'a domain name label is longer than 63 bytes',
  35. self::DOMAIN_NAME_TOO_LONG => 'a domain name is longer than 255 bytes in its storage form',
  36. self::LEADING_HYPHEN => 'a label starts with a hyphen-minus ("-")',
  37. self::TRAILING_HYPHEN => 'a label ends with a hyphen-minus ("-")',
  38. self::HYPHEN_3_4 => 'a label contains hyphen-minus ("-") in the third and fourth positions',
  39. self::LEADING_COMBINING_MARK => 'a label starts with a combining mark',
  40. self::DISALLOWED => 'a label or domain name contains disallowed characters',
  41. self::PUNYCODE => 'a label starts with "xn--" but does not contain valid Punycode',
  42. self::LABEL_HAS_DOT => 'a label contains a dot=full stop',
  43. self::INVALID_ACE_LABEL => 'An ACE label does not contain a valid label string',
  44. self::BIDI => 'a label does not meet the IDNA BiDi requirements (for right-to-left characters)',
  45. self::CONTEXTJ => 'a label does not meet the IDNA CONTEXTJ requirements',
  46. self::CONTEXTO_DIGITS => 'a label does not meet the IDNA CONTEXTO requirements for digits',
  47. self::CONTEXTO_PUNCTUATION => 'a label does not meet the IDNA CONTEXTO requirements for punctuation characters. Some punctuation characters "Would otherwise have been DISALLOWED" but are allowed in certain contexts',
  48. };
  49. }
  50. public static function filterByErrorBytes(int $errors): array
  51. {
  52. return array_values(
  53. array_filter(
  54. self::cases(),
  55. fn (self $error): bool => 0 !== ($error->value & $errors)
  56. )
  57. );
  58. }
  59. }