Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Validator.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of the Fxp Composer Asset Plugin package.
  4. *
  5. * (c) François Pluchino <francois.pluchino@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. namespace Fxp\Composer\AssetPlugin\Util;
  11. use Fxp\Composer\AssetPlugin\Package\Version\VersionParser;
  12. use Fxp\Composer\AssetPlugin\Type\AssetTypeInterface;
  13. /**
  14. * Helper for validate branches and tags of the VCS repository.
  15. *
  16. * @author François Pluchino <francois.pluchino@gmail.com>
  17. */
  18. class Validator
  19. {
  20. /**
  21. * Validates the branch.
  22. *
  23. * @param string $branch
  24. * @param VersionParser|null $parser
  25. *
  26. * @return false|string
  27. */
  28. public static function validateBranch($branch, VersionParser $parser = null)
  29. {
  30. if (null === $parser) {
  31. $parser = new VersionParser();
  32. }
  33. $normalize = $parser->normalizeBranch($branch);
  34. if (false !== strpos($normalize, '.9999999-dev')) {
  35. return false;
  36. }
  37. return $normalize;
  38. }
  39. /**
  40. * Validates the tag.
  41. *
  42. * @param string $tag
  43. * @param AssetTypeInterface $assetType
  44. * @param VersionParser|null $parser
  45. *
  46. * @return false|string
  47. */
  48. public static function validateTag($tag, AssetTypeInterface $assetType, VersionParser $parser = null)
  49. {
  50. if (in_array($tag, array('master', 'trunk', 'default'))) {
  51. return false;
  52. }
  53. if (null === $parser) {
  54. $parser = new VersionParser();
  55. }
  56. try {
  57. $tag = $assetType->getVersionConverter()->convertVersion($tag);
  58. $tag = $parser->normalize($tag);
  59. } catch (\Exception $e) {
  60. $tag = false;
  61. }
  62. return $tag;
  63. }
  64. }