MediaWiki  1.34.0
ComposerPackageModifier.php
Go to the documentation of this file.
1 <?php
2 
3 use Composer\Package\Link;
4 use Composer\Package\Package;
5 use Composer\Semver\Constraint\Constraint;
6 
12 
13  const MEDIAWIKI_PACKAGE_NAME = 'mediawiki/mediawiki';
14 
15  protected $package;
16  protected $versionNormalizer;
17  protected $versionFetcher;
18 
19  public function __construct( Package $package,
21  ) {
22  $this->package = $package;
23  $this->versionNormalizer = $versionNormalizer;
24  $this->versionFetcher = $versionFetcher;
25  }
26 
27  public function setProvidesMediaWiki() {
28  $this->setLinkAsProvides( $this->newMediaWikiLink() );
29  }
30 
31  private function setLinkAsProvides( Link $link ) {
32  $this->package->setProvides( [ $link ] );
33  }
34 
35  private function newMediaWikiLink() {
36  $version = $this->getMediaWikiVersionConstraint();
37 
38  $link = new Link(
39  '__root__',
40  self::MEDIAWIKI_PACKAGE_NAME,
41  $version,
42  'provides',
43  $version->getPrettyString()
44  );
45 
46  return $link;
47  }
48 
49  private function getMediaWikiVersionConstraint() {
50  $mvVersion = $this->versionFetcher->fetchVersion();
51  $mvVersion = $this->versionNormalizer->normalizeSuffix( $mvVersion );
52 
53  $version = new Constraint(
54  '==',
55  $this->versionNormalizer->normalizeLevelCount( $mvVersion )
56  );
57  $version->setPrettyString( $mvVersion );
58 
59  return $version;
60  }
61 
62 }
ComposerPackageModifier\setProvidesMediaWiki
setProvidesMediaWiki()
Definition: ComposerPackageModifier.php:27
ComposerPackageModifier\setLinkAsProvides
setLinkAsProvides(Link $link)
Definition: ComposerPackageModifier.php:31
ComposerPackageModifier\$versionFetcher
$versionFetcher
Definition: ComposerPackageModifier.php:17
ComposerPackageModifier
Definition: ComposerPackageModifier.php:11
ComposerPackageModifier\$package
$package
Definition: ComposerPackageModifier.php:15
ComposerPackageModifier\MEDIAWIKI_PACKAGE_NAME
const MEDIAWIKI_PACKAGE_NAME
Definition: ComposerPackageModifier.php:13
ComposerPackageModifier\__construct
__construct(Package $package, ComposerVersionNormalizer $versionNormalizer, MediaWikiVersionFetcher $versionFetcher)
Definition: ComposerPackageModifier.php:19
MediaWikiVersionFetcher
Provides access to MediaWiki's version without requiring MediaWiki (or anything else) being loaded fi...
Definition: MediaWikiVersionFetcher.php:9
ComposerPackageModifier\getMediaWikiVersionConstraint
getMediaWikiVersionConstraint()
Definition: ComposerPackageModifier.php:49
ComposerPackageModifier\$versionNormalizer
$versionNormalizer
Definition: ComposerPackageModifier.php:16
ComposerVersionNormalizer
Definition: ComposerVersionNormalizer.php:7
ComposerPackageModifier\newMediaWikiLink
newMediaWikiLink()
Definition: ComposerPackageModifier.php:35