|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the puli/composer-plugin package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Puli\ComposerPlugin; |
|
13
|
|
|
|
|
14
|
|
|
use Composer\Composer; |
|
15
|
|
|
use Composer\EventDispatcher\EventSubscriberInterface; |
|
16
|
|
|
use Composer\IO\IOInterface; |
|
17
|
|
|
use Composer\Plugin\PluginInterface; |
|
18
|
|
|
use Composer\Script\Event; |
|
19
|
|
|
use Composer\Script\ScriptEvents; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* A Puli plugin for Composer. |
|
23
|
|
|
* |
|
24
|
|
|
* The plugin updates the Puli package repository based on the Composer |
|
25
|
|
|
* packages whenever `composer install` or `composer update` is executed. |
|
26
|
|
|
* |
|
27
|
|
|
* @since 1.0 |
|
28
|
|
|
* |
|
29
|
|
|
* @author Bernhard Schussek <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
|
|
class PuliPlugin implements PluginInterface, EventSubscriberInterface |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var PuliPluginImpl |
|
35
|
|
|
*/ |
|
36
|
|
|
private $impl; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function getSubscribedEvents() |
|
42
|
|
|
{ |
|
43
|
|
|
return array( |
|
44
|
|
|
ScriptEvents::POST_INSTALL_CMD => 'listen', |
|
45
|
|
|
ScriptEvents::POST_UPDATE_CMD => 'listen', |
|
46
|
|
|
ScriptEvents::PRE_AUTOLOAD_DUMP => 'listen', |
|
47
|
|
|
ScriptEvents::POST_AUTOLOAD_DUMP => 'listen', |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
public function activate(Composer $composer, IOInterface $io) |
|
55
|
|
|
{ |
|
56
|
|
|
$composer->getEventDispatcher()->addSubscriber($this); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Listens to Composer events. |
|
61
|
|
|
* |
|
62
|
|
|
* This method is very minimalist on purpose. We want to load the actual |
|
63
|
|
|
* implementation only after updating the Composer packages so that we get |
|
64
|
|
|
* the updated version (if available). |
|
65
|
|
|
* |
|
66
|
|
|
* @param Event $event The Composer event. |
|
67
|
|
|
*/ |
|
68
|
|
|
public function listen(Event $event) |
|
69
|
|
|
{ |
|
70
|
|
|
// Plugin has been uninstalled |
|
71
|
|
|
if (!file_exists(__FILE__) || !file_exists(__DIR__.'/PuliPluginImpl.php')) { |
|
72
|
|
|
return; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
// Load the implementation only after updating Composer so that we get |
|
76
|
|
|
// the new version of the plugin when a new one was installed |
|
77
|
|
|
if (null === $this->impl) { |
|
78
|
|
|
$this->impl = new PuliPluginImpl($event); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
switch ($event->getName()) { |
|
82
|
|
|
case ScriptEvents::PRE_AUTOLOAD_DUMP: |
|
83
|
|
|
$this->impl->preAutoloadDump(); |
|
84
|
|
|
break; |
|
85
|
|
|
case ScriptEvents::POST_AUTOLOAD_DUMP: |
|
86
|
|
|
$this->impl->postAutoloadDump(); |
|
87
|
|
|
break; |
|
88
|
|
|
|
|
89
|
|
|
case ScriptEvents::POST_INSTALL_CMD: |
|
90
|
|
|
case ScriptEvents::POST_UPDATE_CMD: |
|
91
|
|
|
$this->impl->postInstall(); |
|
92
|
|
|
break; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function setPluginImpl(PuliPluginImpl $impl) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->impl = $impl; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|