ApplicationName.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 ApplicationName {
  12. /** @var string */
  13. private $name;
  14. public function __construct(string $name) {
  15. $this->ensureValidFormat($name);
  16. $this->name = $name;
  17. }
  18. public function asString(): string {
  19. return $this->name;
  20. }
  21. public function isEqual(ApplicationName $name): bool {
  22. return $this->name === $name->name;
  23. }
  24. private function ensureValidFormat(string $name): void {
  25. if (!\preg_match('#\w/\w#', $name)) {
  26. throw new InvalidApplicationNameException(
  27. \sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name),
  28. InvalidApplicationNameException::InvalidFormat
  29. );
  30. }
  31. }
  32. }