DomainHostInterface.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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\Contracts;
  12. use BackedEnum;
  13. use Countable;
  14. use Iterator;
  15. use IteratorAggregate;
  16. use League\Uri\Exceptions\SyntaxError;
  17. use Stringable;
  18. /**
  19. * @extends IteratorAggregate<int, string>
  20. *
  21. * @method bool isSubdomainOf(BackedEnum|Stringable|string|null $parentHost) Tells whether the current domain instance is a subdomain of the parent host.
  22. * @method bool hasSubdomain(BackedEnum|Stringable|string|null $childHost) Tells whether the submitted host is a subdomain of the current instance.
  23. * @method bool isSiblingOf(BackedEnum|Stringable|string|null $siblingHost) Tells whether the submitted host share the same parent domain as the current instance.
  24. * @method static commonAncestorWith(BackedEnum|Stringable|string|null $other) Returns the common longest ancestor between 2 domain. The returned domain is empty if no ancestor is found
  25. * @method static parentHost() Returns the current parent domain for the current instance. The returned domain is empty if no ancestor is found
  26. * @method bool isEmpty() Tells whether the domain contains any label.
  27. */
  28. interface DomainHostInterface extends Countable, HostInterface, IteratorAggregate
  29. {
  30. /**
  31. * Returns the labels total number.
  32. */
  33. public function count(): int;
  34. /**
  35. * Iterate over the Domain labels.
  36. *
  37. * @return Iterator<string>
  38. */
  39. public function getIterator(): Iterator;
  40. /**
  41. * Retrieves a single host label.
  42. *
  43. * If the label offset has not been set, returns the null value.
  44. */
  45. public function get(int $offset): ?string;
  46. /**
  47. * Returns the associated key for a specific label or all the keys.
  48. *
  49. * @return int[]
  50. */
  51. public function keys(?string $label = null): array;
  52. /**
  53. * Tells whether the domain is absolute.
  54. */
  55. public function isAbsolute(): bool;
  56. /**
  57. * Prepends a label to the host.
  58. */
  59. public function prepend(Stringable|string $label): self;
  60. /**
  61. * Appends a label to the host.
  62. */
  63. public function append(Stringable|string $label): self;
  64. /**
  65. * Extracts a slice of $length elements starting at position $offset from the host.
  66. *
  67. * This method MUST retain the state of the current instance, and return
  68. * an instance that contains the selected slice.
  69. *
  70. * If $length is null it returns all elements from $offset to the end of the Domain.
  71. */
  72. public function slice(int $offset, ?int $length = null): self;
  73. /**
  74. * Returns an instance with its Root label.
  75. *
  76. * @see https://tools.ietf.org/html/rfc3986#section-3.2.2
  77. */
  78. public function withRootLabel(): self;
  79. /**
  80. * Returns an instance without its Root label.
  81. *
  82. * @see https://tools.ietf.org/html/rfc3986#section-3.2.2
  83. */
  84. public function withoutRootLabel(): self;
  85. /**
  86. * Returns an instance with the modified label.
  87. *
  88. * This method MUST retain the state of the current instance, and return
  89. * an instance that contains the new label
  90. *
  91. * If $key is non-negative, the added label will be the label at $key position from the start.
  92. * If $key is negative, the added label will be the label at $key position from the end.
  93. *
  94. * @throws SyntaxError If the key is invalid
  95. */
  96. public function withLabel(int $key, Stringable|string $label): self;
  97. /**
  98. * Returns an instance without the specified label.
  99. *
  100. * This method MUST retain the state of the current instance, and return
  101. * an instance that contains the modified component
  102. *
  103. * If $key is non-negative, the removed label will be the label at $key position from the start.
  104. * If $key is negative, the removed label will be the label at $key position from the end.
  105. *
  106. * @throws SyntaxError If the key is invalid
  107. */
  108. public function withoutLabel(int ...$keys): self;
  109. }