Url.php 880 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php declare(strict_types = 1);
  2. /*
  3. * This file is part of PharIo\Manifest.
  4. *
  5. * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
  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 PharIo\Manifest;
  11. class Url {
  12. /** @var string */
  13. private $url;
  14. public function __construct(string $url) {
  15. $this->ensureUrlIsValid($url);
  16. $this->url = $url;
  17. }
  18. public function asString(): string {
  19. return $this->url;
  20. }
  21. /**
  22. * @param string $url
  23. *
  24. * @throws InvalidUrlException
  25. */
  26. private function ensureUrlIsValid($url): void {
  27. if (\filter_var($url, \FILTER_VALIDATE_URL) === false) {
  28. throw new InvalidUrlException;
  29. }
  30. }
  31. }