1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* hirak/prestissimo |
4
|
|
|
* @author Hiraku NAKANO |
5
|
|
|
* @license MIT https://github.com/hirak/prestissimo |
6
|
|
|
*/ |
7
|
|
|
namespace Hirak\Prestissimo; |
8
|
|
|
|
9
|
|
|
use Composer\Composer; |
10
|
|
|
use Composer\IO; |
11
|
|
|
use Composer\Plugin as CPlugin; |
12
|
|
|
use Composer\EventDispatcher; |
13
|
|
|
use Composer\Package; |
14
|
|
|
use Composer\Installer; |
15
|
|
|
use Composer\DependencyResolver; |
16
|
|
|
|
17
|
|
|
class Plugin implements |
18
|
|
|
CPlugin\PluginInterface, |
19
|
|
|
EventDispatcher\EventSubscriberInterface |
20
|
|
|
{ |
21
|
|
|
/** @var IO\IOInterface */ |
22
|
|
|
private $io; |
23
|
|
|
|
24
|
|
|
/** @var Composer\Config */ |
25
|
|
|
private $config; |
26
|
|
|
|
27
|
|
|
/** @var Config */ |
28
|
|
|
private $pluginConfig; |
29
|
|
|
|
30
|
|
|
/** @var boolean */ |
31
|
|
|
private $disabled = false; |
32
|
|
|
|
33
|
|
|
private static $pluginClasses = array( |
34
|
|
|
'GitHubRequest', |
35
|
|
|
'GitLabRequest', |
36
|
|
|
'HttpGetRequest', |
37
|
|
|
'HttpGetResponse', |
38
|
|
|
'Config', |
39
|
|
|
'CurlMulti', |
40
|
|
|
'Factory', |
41
|
|
|
'FileDownloaderDummy', |
42
|
|
|
'OutputFile', |
43
|
|
|
'ParallelDownloader', |
44
|
|
|
'Plugin', |
45
|
|
|
); |
46
|
|
|
|
47
|
2 |
|
public function activate(Composer $composer, IO\IOInterface $io) |
48
|
|
|
{ |
49
|
|
|
// @codeCoverageIgnoreStart |
50
|
|
|
// guard for self-update problem |
51
|
|
|
if (__CLASS__ !== 'Hirak\Prestissimo\Plugin') { |
52
|
|
|
return $this->disable(); |
53
|
|
|
} |
54
|
|
|
// @codeCoverageIgnoreEnd |
55
|
|
|
|
56
|
|
|
// load all classes |
57
|
2 |
|
foreach (self::$pluginClasses as $class) { |
58
|
2 |
|
class_exists(__NAMESPACE__ . '\\' . $class); |
59
|
2 |
|
} |
60
|
|
|
|
61
|
2 |
|
$this->config = $composer->getConfig(); |
|
|
|
|
62
|
2 |
|
$this->io = $io; |
63
|
2 |
|
$this->pluginConfig = $this->setPluginConfig(); |
64
|
2 |
|
} |
65
|
|
|
|
66
|
1 |
|
public static function getSubscribedEvents() |
67
|
|
|
{ |
68
|
|
|
return array( |
69
|
1 |
|
Installer\InstallerEvents::POST_DEPENDENCIES_SOLVING => array( |
70
|
1 |
|
array('onPostDependenciesSolving', PHP_INT_MAX), |
71
|
1 |
|
), |
72
|
1 |
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* pre-fetch parallel by curl_multi |
77
|
|
|
*/ |
78
|
1 |
|
public function onPostDependenciesSolving(Installer\InstallerEvent $ev) |
79
|
|
|
{ |
80
|
1 |
|
if ($this->disabled) { |
81
|
1 |
|
return; |
82
|
|
|
} |
83
|
1 |
|
$ops = $ev->getOperations(); |
84
|
1 |
|
$packages = $this->filterPackages($ops); |
85
|
1 |
|
$pluginConfig = $this->pluginConfig->get(); |
86
|
1 |
|
$downloader = new ParallelDownloader($this->io, $this->config); |
87
|
1 |
|
$downloader->download($packages, $pluginConfig); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param DependencyResolver\Operation\OperationInterface[] |
92
|
|
|
* @return Package\PackageInterface[] |
93
|
|
|
*/ |
94
|
1 |
|
private static function filterPackages(array $operations) |
95
|
|
|
{ |
96
|
1 |
|
$packs = array(); |
97
|
1 |
|
foreach ($operations as $op) { |
98
|
1 |
|
$type = $op->getJobType(); |
99
|
1 |
|
if ('install' === $type) { |
100
|
1 |
|
$packs[] = $op->getPackage(); |
101
|
1 |
|
continue; |
102
|
|
|
} |
103
|
|
|
|
104
|
1 |
|
if ('update' === $type) { |
105
|
1 |
|
$packs[] = $op->getTargetPackage(); |
106
|
1 |
|
continue; |
107
|
|
|
} |
108
|
1 |
|
} |
109
|
1 |
|
return $packs; |
110
|
|
|
} |
111
|
|
|
|
112
|
2 |
|
private function setPluginConfig() |
113
|
|
|
{ |
114
|
2 |
|
$config = $this->config->get('prestissimo'); |
115
|
2 |
|
if (!is_array($config)) { |
116
|
2 |
|
$config = array(); |
117
|
2 |
|
} |
118
|
2 |
|
return new Config($config); |
119
|
|
|
} |
120
|
|
|
|
121
|
1 |
|
public function disable() |
122
|
|
|
{ |
123
|
1 |
|
$this->disabled = true; |
124
|
1 |
|
} |
125
|
|
|
|
126
|
1 |
|
public function isDisabled() |
127
|
|
|
{ |
128
|
1 |
|
return $this->disabled; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..