Literal.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 $package;
  19. protected $wanted;
  20. protected $id;
  21. public function __construct(PackageInterface $package, $wanted)
  22. {
  23. $this->package = $package;
  24. $this->wanted = $wanted;
  25. $this->id = ($this->wanted ? '' : '-') . $this->package->getId();
  26. }
  27. public function isWanted()
  28. {
  29. return $this->wanted;
  30. }
  31. public function getPackage()
  32. {
  33. return $this->package;
  34. }
  35. public function getPackageId()
  36. {
  37. return $this->package->getId();
  38. }
  39. public function getId()
  40. {
  41. return $this->id;
  42. }
  43. public function __toString()
  44. {
  45. return ($this->wanted ? '+' : '-') . $this->getPackage();
  46. }
  47. public function inverted()
  48. {
  49. return new Literal($this->getPackage(), !$this->isWanted());
  50. }
  51. public function equals(Literal $b)
  52. {
  53. return $this->id === $b->id;
  54. }
  55. }