Request.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\Semver\Constraint\ConstraintInterface;
  13. /**
  14. * @author Nils Adermann <naderman@naderman.de>
  15. */
  16. class Request
  17. {
  18. protected $jobs;
  19. public function __construct()
  20. {
  21. $this->jobs = array();
  22. }
  23. public function install($packageName, ConstraintInterface $constraint = null)
  24. {
  25. $this->addJob($packageName, 'install', $constraint);
  26. }
  27. public function update($packageName, ConstraintInterface $constraint = null)
  28. {
  29. $this->addJob($packageName, 'update', $constraint);
  30. }
  31. public function remove($packageName, ConstraintInterface $constraint = null)
  32. {
  33. $this->addJob($packageName, 'remove', $constraint);
  34. }
  35. /**
  36. * Mark an existing package as being installed and having to remain installed
  37. *
  38. * These jobs will not be tempered with by the solver
  39. *
  40. * @param string $packageName
  41. * @param ConstraintInterface|null $constraint
  42. */
  43. public function fix($packageName, ConstraintInterface $constraint = null)
  44. {
  45. $this->addJob($packageName, 'install', $constraint, true);
  46. }
  47. protected function addJob($packageName, $cmd, ConstraintInterface $constraint = null, $fixed = false)
  48. {
  49. $packageName = strtolower($packageName);
  50. $this->jobs[] = array(
  51. 'cmd' => $cmd,
  52. 'packageName' => $packageName,
  53. 'constraint' => $constraint,
  54. 'fixed' => $fixed,
  55. );
  56. }
  57. public function updateAll()
  58. {
  59. $this->jobs[] = array('cmd' => 'update-all');
  60. }
  61. public function getJobs()
  62. {
  63. return $this->jobs;
  64. }
  65. }