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 array */ |
28
|
|
|
private $package; |
29
|
|
|
private $cached = false; |
30
|
|
|
|
31
|
|
|
/** @var boolean */ |
32
|
|
|
private $disabled = false; |
33
|
|
|
|
34
|
|
|
private static $pluginClasses = array( |
35
|
|
|
'BaseRequest', |
36
|
|
|
'ConfigFacade', |
37
|
|
|
'CopyRequest', |
38
|
|
|
'CurlMulti', |
39
|
|
|
'CurlRemoteFilesystem', |
40
|
2 |
|
'FetchException', |
41
|
|
|
'FetchRequest', |
42
|
|
|
'FileDownloaderDummy', |
43
|
|
|
'ParallelizedComposerRepository', |
44
|
|
|
'Plugin', |
45
|
|
|
'Prefetcher', |
46
|
|
|
'Share', |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
public function activate(Composer $composer, IO\IOInterface $io) |
50
|
2 |
|
{ |
51
|
2 |
|
// @codeCoverageIgnoreStart |
52
|
|
|
// guard for self-update problem |
53
|
|
|
if (__CLASS__ !== 'Hirak\Prestissimo\Plugin') { |
54
|
2 |
|
return $this->disable(); |
55
|
2 |
|
} |
56
|
2 |
|
// @codeCoverageIgnoreEnd |
57
|
|
|
|
58
|
1 |
|
// load all classes |
59
|
|
|
foreach (self::$pluginClasses as $class) { |
60
|
|
|
class_exists(__NAMESPACE__ . '\\' . $class); |
61
|
1 |
|
} |
62
|
1 |
|
|
63
|
|
|
$this->io = $io; |
64
|
|
|
$this->config = $composer->getConfig(); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$this->package = $composer->getPackage(); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public static function getSubscribedEvents() |
70
|
1 |
|
{ |
71
|
|
|
return array( |
72
|
1 |
|
CPlugin\PluginEvents::PRE_FILE_DOWNLOAD => 'onPreFileDownload', |
73
|
1 |
|
Installer\InstallerEvents::PRE_DEPENDENCIES_SOLVING => 'onPreDependenciesSolving', |
74
|
|
|
Installer\InstallerEvents::POST_DEPENDENCIES_SOLVING => array( |
75
|
1 |
|
array('onPostDependenciesSolving', PHP_INT_MAX), |
76
|
1 |
|
), |
77
|
1 |
|
); |
78
|
1 |
|
} |
79
|
1 |
|
|
80
|
|
|
/** |
81
|
1 |
|
* Keep-Alived file downloader |
82
|
|
|
*/ |
83
|
1 |
|
public function onPreFileDownload(CPlugin\PreFileDownloadEvent $ev) |
84
|
|
|
{ |
85
|
1 |
|
if ($this->disabled) { |
86
|
1 |
|
return; |
87
|
|
|
} |
88
|
1 |
|
$rfs = $ev->getRemoteFilesystem(); |
89
|
|
|
$curlrfs = new CurlRemoteFilesystem( |
90
|
1 |
|
$this->io, |
91
|
|
|
$this->config, |
92
|
|
|
$rfs->getOptions() |
93
|
|
|
); |
94
|
|
|
$ev->setRemoteFilesystem($curlrfs); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function onPreDependenciesSolving(Installer\InstallerEvent $ev) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
if ($this->disabled) { |
100
|
|
|
return; |
101
|
|
|
} |
102
|
|
|
if ($this->cached) { |
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
$repos = $this->package->getRepositories(); |
|
|
|
|
106
|
|
|
if (isset($repos['packagist']['type']) && $repos['packagist']['type'] === 'composer') { |
107
|
|
|
$repo = new ParallelizedComposerRepository($repos['packagist'], $this->io, $this->config); |
108
|
|
|
$repo->prefetch(); |
109
|
|
|
$this->cached = true; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* pre-fetch parallel by curl_multi |
115
|
|
|
*/ |
116
|
|
|
public function onPostDependenciesSolving(Installer\InstallerEvent $ev) |
117
|
|
|
{ |
118
|
|
|
if ($this->disabled) { |
119
|
|
|
return; |
120
|
|
|
} |
121
|
|
|
$prefetcher = new Prefetcher; |
122
|
|
|
$prefetcher->fetchAllFromOperations( |
123
|
|
|
$this->io, |
124
|
|
|
$this->config, |
125
|
|
|
$ev->getOperations() |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function disable() |
130
|
|
|
{ |
131
|
|
|
$this->disabled = true; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function isDisabled() |
135
|
|
|
{ |
136
|
|
|
return $this->disabled; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
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..