AbstractConstraint.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of composer/semver.
  4. *
  5. * (c) Composer <https://github.com/composer>
  6. *
  7. * For the full copyright and license information, please view
  8. * the LICENSE file that was distributed with this source code.
  9. */
  10. namespace Composer\Semver\Constraint;
  11. trigger_error('The ' . __NAMESPACE__ . '\AbstractConstraint abstract class is deprecated, there is no replacement for it, it will be removed in the next major version.', E_USER_DEPRECATED);
  12. /**
  13. * Base constraint class.
  14. */
  15. abstract class AbstractConstraint implements ConstraintInterface
  16. {
  17. /** @var string */
  18. protected $prettyString;
  19. /**
  20. * @param ConstraintInterface $provider
  21. *
  22. * @return bool
  23. */
  24. public function matches(ConstraintInterface $provider)
  25. {
  26. if ($provider instanceof $this) {
  27. // see note at bottom of this class declaration
  28. return $this->matchSpecific($provider);
  29. }
  30. // turn matching around to find a match
  31. return $provider->matches($this);
  32. }
  33. /**
  34. * @param string $prettyString
  35. */
  36. public function setPrettyString($prettyString)
  37. {
  38. $this->prettyString = $prettyString;
  39. }
  40. /**
  41. * @return string
  42. */
  43. public function getPrettyString()
  44. {
  45. if ($this->prettyString) {
  46. return $this->prettyString;
  47. }
  48. return $this->__toString();
  49. }
  50. // implementations must implement a method of this format:
  51. // not declared abstract here because type hinting violates parameter coherence (TODO right word?)
  52. // public function matchSpecific(<SpecificConstraintType> $provider);
  53. }