1 | <?php |
||
28 | class Plugin implements PluginInterface, EventSubscriberInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var string the filename of a lock file. Defaults to `composer-asset-plugin.lock` |
||
32 | */ |
||
33 | public $lockFile = 'composer-asset-plugin.lock'; |
||
34 | |||
35 | /** |
||
36 | * @var Composer instance |
||
37 | */ |
||
38 | protected $composer; |
||
39 | |||
40 | /** |
||
41 | * @var IOInterface |
||
42 | */ |
||
43 | public $io; |
||
44 | |||
45 | /** |
||
46 | * List of the available package managers/ |
||
47 | * Initialized at activate. |
||
48 | * @var array|PackageManager[] |
||
49 | * @see activate |
||
50 | */ |
||
51 | protected $managers = [ |
||
52 | 'bower' => 'hiqdev\composerassetplugin\Bower', |
||
53 | 'npm' => 'hiqdev\composerassetplugin\Npm', |
||
54 | ]; |
||
55 | |||
56 | /** |
||
57 | * @var PackageInterface[] the array of active composer packages |
||
58 | */ |
||
59 | protected $packages; |
||
60 | |||
61 | /** |
||
62 | * @var string absolute path to vendor directory. |
||
63 | */ |
||
64 | protected $vendorDir; |
||
65 | |||
66 | /** |
||
67 | * Initializes the plugin object with the passed $composer and $io. |
||
68 | * Also initializes package managers. |
||
69 | * |
||
70 | * @param Composer $composer |
||
71 | * @param IOInterface $io |
||
72 | * @void |
||
73 | */ |
||
74 | 3 | public function activate(Composer $composer, IOInterface $io) |
|
75 | { |
||
76 | 3 | $managers = []; |
|
77 | 3 | $this->composer = $composer; |
|
78 | 3 | $this->io = $io; |
|
79 | 3 | foreach ($this->managers as $name => $class) { |
|
80 | 3 | $managers[$name] = new $class($this); |
|
81 | } |
||
82 | 3 | $this->managers = $managers; |
|
83 | 3 | } |
|
84 | |||
85 | /** |
||
86 | * Returns list of events the plugin is subscribed to. |
||
87 | * |
||
88 | * @return array list of events |
||
89 | */ |
||
90 | 1 | public static function getSubscribedEvents() |
|
91 | { |
||
92 | return [ |
||
93 | 1 | ScriptEvents::POST_INSTALL_CMD => [ |
|
94 | ['onPostInstall', 0], |
||
95 | 1 | ], |
|
96 | 1 | ScriptEvents::POST_UPDATE_CMD => [ |
|
97 | ['onPostUpdate', 0], |
||
98 | ], |
||
99 | ]; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Perform install. Called by composer after install. |
||
104 | * |
||
105 | * @param Event $event |
||
106 | * @void |
||
107 | */ |
||
108 | 1 | public function onPostInstall(Event $event) |
|
|
|||
109 | { |
||
110 | 1 | $lockFile = new JsonFile($this->lockFile); |
|
111 | 1 | if ($lockFile->exists()) { |
|
112 | $this->loadPackages($lockFile); |
||
113 | } else { |
||
114 | 1 | $this->scanPackages(); |
|
115 | } |
||
116 | 1 | $this->runAction('install'); |
|
117 | 1 | } |
|
118 | |||
119 | /** |
||
120 | * Perform update. Called by composer after update. |
||
121 | * |
||
122 | * @param Event $event |
||
123 | */ |
||
124 | public function onPostUpdate(Event $event) |
||
129 | |||
130 | /** |
||
131 | * Sets [[packages]]. |
||
132 | * |
||
133 | * @param PackageInterface[] $packages |
||
134 | */ |
||
135 | 3 | public function setPackages(array $packages) |
|
139 | |||
140 | /** |
||
141 | * Gets [[packages]]. |
||
142 | * @return \Composer\Package\PackageInterface[] |
||
143 | */ |
||
144 | 2 | public function getPackages() |
|
153 | |||
154 | /** |
||
155 | * Scan packages from the composer objects. |
||
156 | * @void |
||
157 | */ |
||
158 | 1 | protected function scanPackages() |
|
168 | |||
169 | /** |
||
170 | * Load packages from given lock file. |
||
171 | * |
||
172 | * @param JsonFile $lockFile |
||
173 | * @void |
||
174 | */ |
||
175 | protected function loadPackages(JsonFile $lockFile) |
||
182 | |||
183 | /** |
||
184 | * Install packages after loading/scanning. |
||
185 | * @param string $action |
||
186 | * @void |
||
187 | */ |
||
188 | 1 | protected function runAction($action) |
|
197 | |||
198 | /** |
||
199 | * Get absolute path to composer vendor dir. |
||
200 | * @return string |
||
201 | */ |
||
202 | 1 | public function getVendorDir() |
|
214 | } |
||
215 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.