MediaWiki REL1_39
ComposerHookHandler.php
Go to the documentation of this file.
1<?php
2
3use Composer\Package\Package;
4use Composer\Plugin\PluginInterface;
5use Composer\Script\Event;
6
12
13 private static function startAutoloader() {
14 $GLOBALS['IP'] = __DIR__ . '/../../';
15 require_once __DIR__ . '/../AutoLoader.php';
16 }
17
18 public static function onPreUpdate( Event $event ) {
19 self::checkMergePluginActive( $event );
20 self::startAutoloader();
21 self::handleChangeEvent( $event );
22 }
23
32 private static function checkMergePluginActive( Event $event ) {
33 if ( version_compare( PluginInterface::PLUGIN_API_VERSION, '2.0.0', '>=' ) ) {
34 foreach ( $event->getComposer()->getPluginManager()->getPlugins() as $plugin ) {
35 if ( $plugin instanceof \Wikimedia\Composer\Merge\V2\MergePlugin ) {
36 // If v2 of wikimedia/composer-merge-plugin is already installed,
37 // nothing needs doing
38 return;
39 }
40
41 // Check if v1 of wikimedia/composer-merge-plugin is still installed
42 if ( $plugin instanceof \Wikimedia\Composer\MergePlugin ) {
43 throw new \Exception( "wikimedia/composer-merge-plugin 2.x is not activated. " .
44 "Use Composer 1.x to update wikimedia/composer-merge-plugin to version " .
45 "2.x before running Composer 2.x." );
46 }
47 }
48 }
49 }
50
51 public static function onPreInstall( Event $event ) {
52 self::startAutoloader();
53 self::handleChangeEvent( $event );
54 }
55
56 private static function handleChangeEvent( Event $event ) {
57 $package = $event->getComposer()->getPackage();
58
59 if ( $package instanceof Package ) {
60 $packageModifier = new ComposerPackageModifier(
61 $package,
64 );
65
66 $packageModifier->setProvidesMediaWiki();
67 }
68 }
69}
static onPreInstall(Event $event)
static onPreUpdate(Event $event)
Provides access to MediaWiki's version without requiring MediaWiki (or anything else) being loaded fi...
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...