Request.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. $this->jobs = array();
  24. }
  25. public function install($packageName, LinkConstraintInterface $constraint = null)
  26. {
  27. $this->addJob($packageName, 'install', $constraint);
  28. }
  29. public function update($packageName, LinkConstraintInterface $constraint = null)
  30. {
  31. $this->addJob($packageName, 'update', $constraint);
  32. }
  33. public function remove($packageName, LinkConstraintInterface $constraint = null)
  34. {
  35. $this->addJob($packageName, 'remove', $constraint);
  36. }
  37. protected function addJob($packageName, $cmd, LinkConstraintInterface $constraint = null)
  38. {
  39. $packageName = strtolower($packageName);
  40. $packages = $this->pool->whatProvides($packageName, $constraint);
  41. $this->jobs[] = array(
  42. 'packages' => $packages,
  43. 'cmd' => $cmd,
  44. 'packageName' => $packageName,
  45. );
  46. }
  47. public function getJobs()
  48. {
  49. return $this->jobs;
  50. }
  51. }