VersionConstraint.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\DependencyResolver\RelationConstraint;
  12. /**
  13. * Constrains a package relation based on package version
  14. *
  15. * Version numbers must be compatible with version_compare
  16. *
  17. * @author Nils Adermann <naderman@naderman.de>
  18. */
  19. class VersionConstraint implements RelationConstraintInterface
  20. {
  21. private $operator;
  22. private $version;
  23. /**
  24. * Sets operator and version to compare a package with
  25. *
  26. * @param string $operator A comparison operator
  27. * @param string $version A version to compare to
  28. */
  29. public function __construct($operator, $version)
  30. {
  31. $this->operator = $operator;
  32. $this->version = $version;
  33. }
  34. public function matches($releaseType, $version)
  35. {
  36. return version_compare($version, $this->version, $this->operator);
  37. }
  38. public function __toString()
  39. {
  40. return $this->operator.' '.$this->version;
  41. }
  42. }