Literal.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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;
  12. use Composer\Package\PackageInterface;
  13. /**
  14. * @author Nils Adermann <naderman@naderman.de>
  15. */
  16. class Literal
  17. {
  18. protected $wanted;
  19. public function __construct(PackageInterface $package, $wanted)
  20. {
  21. $this->package = $package;
  22. $this->wanted = $wanted;
  23. }
  24. public function isWanted()
  25. {
  26. return $this->wanted;
  27. }
  28. public function getPackage()
  29. {
  30. return $this->package;
  31. }
  32. public function getPackageId()
  33. {
  34. return $this->package->getId();
  35. }
  36. public function getId()
  37. {
  38. return ($this->wanted ? '' : '-') . $this->package->getId();
  39. }
  40. public function __toString()
  41. {
  42. return ($this->wanted ? '+' : '-') . $this->getPackage();
  43. }
  44. public function inverted()
  45. {
  46. return new Literal($this->getPackage(), !$this->isWanted());
  47. }
  48. public function equals(Literal $b)
  49. {
  50. return $this->getId() === $b->getId();
  51. }
  52. }