This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
ComposerPlugin.php
72 lines (61 loc) · 2.05 KB
/
ComposerPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/**************************************/
/***** THIS FILE IS PHP, NOT HACK *****/
/**************************************/
namespace Facebook\AutoloadMap;
use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Process\ExecutableFinder;
/** Plugin for PHP composer to automatically update the autoload map whenever
* dependencies are changed or updated.
*/
final class ComposerPlugin
implements PluginInterface, EventSubscriberInterface {
private $vendor;
private $root;
private $io;
/** Initialize members */
public function activate(Composer $composer, IOInterface $io) {
$this->io = $io;
$vendor = $composer->getConfig()->get('vendor-dir');
$this->vendor = $vendor;
$this->root = dirname($vendor);
}
/** Tell composer what events we're interested in.
*
* In this case, we want to run whenever composer's own autoload map is updated.
*/
public static function getSubscribedEvents() {
return [ScriptEvents::POST_AUTOLOAD_DUMP => [['onPostAutoloadDump', 0]]];
}
/** Callback for after the main composer autoload map has been updated.
*
* Here we update our autoload map.
*/
public function onPostAutoloadDump(Event $event) {
$args = $event->isDevMode() ? '' : ' --no-dev';
$executor = new ProcessExecutor($this->io);
$command = ProcessExecutor::escape($this->vendor.'/bin/hh-autoload.hack').
$args;
$executor->execute($command);
}
/** Does nothing but required by Composer 2.0 */
public function deactivate(Composer $composer, IOInterface $io) {
}
/** Does nothing but required by Composer 2.0 */
public function uninstall(Composer $composer, IOInterface $io) {
}
}