Version.php 725 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
  4. * SPDX-License-Identifier: MIT
  5. */
  6. declare(strict_types=1);
  7. namespace Respect\Validation\Rules;
  8. use function is_string;
  9. use function preg_match;
  10. /**
  11. * Validates version numbers using Semantic Versioning.
  12. *
  13. * @see http://semver.org/
  14. *
  15. * @author Danilo Correa <danilosilva87@gmail.com>
  16. * @author Henrique Moody <henriquemoody@gmail.com>
  17. */
  18. final class Version extends AbstractRule
  19. {
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function validate($input): bool
  24. {
  25. if (!is_string($input)) {
  26. return false;
  27. }
  28. return preg_match('/^[0-9]+\.[0-9]+\.[0-9]+([+-][^+-][0-9A-Za-z-.]*)?$/', $input) > 0;
  29. }
  30. }