ComposerPackageModifier.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. use Composer\Package\Link;
  3. use Composer\Package\Package;
  4. use Composer\Semver\Constraint\Constraint;
  5. /**
  6. * @license GPL-2.0-or-later
  7. * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  8. */
  9. class ComposerPackageModifier {
  10. const MEDIAWIKI_PACKAGE_NAME = 'mediawiki/mediawiki';
  11. protected $package;
  12. protected $versionNormalizer;
  13. protected $versionFetcher;
  14. public function __construct( Package $package,
  15. ComposerVersionNormalizer $versionNormalizer, MediaWikiVersionFetcher $versionFetcher
  16. ) {
  17. $this->package = $package;
  18. $this->versionNormalizer = $versionNormalizer;
  19. $this->versionFetcher = $versionFetcher;
  20. }
  21. public function setProvidesMediaWiki() {
  22. $this->setLinkAsProvides( $this->newMediaWikiLink() );
  23. }
  24. private function setLinkAsProvides( Link $link ) {
  25. $this->package->setProvides( [ $link ] );
  26. }
  27. private function newMediaWikiLink() {
  28. $version = $this->getMediaWikiVersionConstraint();
  29. $link = new Link(
  30. '__root__',
  31. self::MEDIAWIKI_PACKAGE_NAME,
  32. $version,
  33. 'provides',
  34. $version->getPrettyString()
  35. );
  36. return $link;
  37. }
  38. private function getMediaWikiVersionConstraint() {
  39. $mvVersion = $this->versionFetcher->fetchVersion();
  40. $mvVersion = $this->versionNormalizer->normalizeSuffix( $mvVersion );
  41. $version = new Constraint(
  42. '==',
  43. $this->versionNormalizer->normalizeLevelCount( $mvVersion )
  44. );
  45. $version->setPrettyString( $mvVersion );
  46. return $version;
  47. }
  48. }