UpdateOperation.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Operation;
  12. use Composer\Package\PackageInterface;
  13. /**
  14. * Solver update operation.
  15. *
  16. * @author Konstantin Kudryashov <ever.zet@gmail.com>
  17. */
  18. class UpdateOperation extends SolverOperation
  19. {
  20. protected $initialPackage;
  21. protected $targetPackage;
  22. /**
  23. * Initializes update operation.
  24. *
  25. * @param PackageInterface $initial initial package
  26. * @param PackageInterface $target target package (updated)
  27. * @param string $reason update reason
  28. */
  29. public function __construct(PackageInterface $initial, PackageInterface $target, $reason = null)
  30. {
  31. parent::__construct($reason);
  32. $this->initialPackage = $initial;
  33. $this->targetPackage = $target;
  34. }
  35. /**
  36. * Returns initial package.
  37. *
  38. * @return PackageInterface
  39. */
  40. public function getInitialPackage()
  41. {
  42. return $this->initialPackage;
  43. }
  44. /**
  45. * Returns target package.
  46. *
  47. * @return PackageInterface
  48. */
  49. public function getTargetPackage()
  50. {
  51. return $this->targetPackage;
  52. }
  53. /**
  54. * Returns job type.
  55. *
  56. * @return string
  57. */
  58. public function getJobType()
  59. {
  60. return 'update';
  61. }
  62. /**
  63. * {@inheritDoc}
  64. */
  65. public function __toString()
  66. {
  67. return 'Updating '.$this->initialPackage->getPrettyName().' ('.$this->formatVersion($this->initialPackage).') to '.
  68. $this->targetPackage->getPrettyName(). ' ('.$this->formatVersion($this->targetPackage).')';
  69. }
  70. }