Request.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\LinkConstraint\LinkConstraintInterface;
  13. /**
  14. * @author Nils Adermann <naderman@naderman.de>
  15. */
  16. class Request
  17. {
  18. protected $jobs;
  19. protected $pool;
  20. public function __construct(Pool $pool)
  21. {
  22. $this->pool = $pool;
  23. }
  24. public function install($packageName, LinkConstraintInterface $constraint = null)
  25. {
  26. $this->addJob($packageName, 'install', $constraint);
  27. }
  28. public function update($packageName, LinkConstraintInterface $constraint = null)
  29. {
  30. $this->addJob($packageName, 'update', $constraint);
  31. }
  32. public function remove($packageName, LinkConstraintInterface $constraint = null)
  33. {
  34. $this->addJob($packageName, 'remove', $constraint);
  35. }
  36. protected function addJob($packageName, $cmd, LinkConstraintInterface $constraint = null)
  37. {
  38. $packageName = strtolower($packageName);
  39. $packages = $this->pool->whatProvides($packageName, $constraint);
  40. $this->jobs[] = array(
  41. 'packages' => $packages,
  42. 'cmd' => $cmd,
  43. 'packageName' => $packageName,
  44. );
  45. }
  46. public function getJobs()
  47. {
  48. return $this->jobs;
  49. }
  50. }