SpecificConstraint.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\Package\LinkConstraint;
  12. /**
  13. * Provides a common basis for specific package link constraints
  14. *
  15. * @author Nils Adermann <naderman@naderman.de>
  16. */
  17. abstract class SpecificConstraint implements LinkConstraintInterface
  18. {
  19. protected $prettyString;
  20. public function matches(LinkConstraintInterface $provider)
  21. {
  22. if ($provider instanceof MultiConstraint) {
  23. // turn matching around to find a match
  24. return $provider->matches($this);
  25. } elseif ($provider instanceof $this) {
  26. return $this->matchSpecific($provider);
  27. }
  28. return true;
  29. }
  30. public function setPrettyString($prettyString)
  31. {
  32. $this->prettyString = $prettyString;
  33. }
  34. public function getPrettyString()
  35. {
  36. if ($this->prettyString) {
  37. return $this->prettyString;
  38. }
  39. return $this->__toString();
  40. }
  41. // implementations must implement a method of this format:
  42. // not declared abstract here because type hinting violates parameter coherence (TODO right word?)
  43. // public function matchSpecific(<SpecificConstraintType> $provider);
  44. }