NamespaceUri.php 631 B

12345678910111213141516171819202122232425262728
  1. <?php declare(strict_types = 1);
  2. namespace TheSeer\Tokenizer;
  3. class NamespaceUri {
  4. /** @var string */
  5. private $value;
  6. /**
  7. * @param string $value
  8. */
  9. public function __construct(string $value) {
  10. $this->ensureValidUri($value);
  11. $this->value = $value;
  12. }
  13. public function asString(): string {
  14. return $this->value;
  15. }
  16. private function ensureValidUri($value) {
  17. if (strpos($value, ':') === false) {
  18. throw new NamespaceUriException(
  19. sprintf("Namespace URI '%s' must contain at least one colon", $value)
  20. );
  21. }
  22. }
  23. }