1 | <?php |
||
17 | class Plugin implements |
||
18 | CPlugin\PluginInterface, |
||
19 | EventDispatcher\EventSubscriberInterface |
||
20 | { |
||
21 | /** @var Composer */ |
||
22 | private $composer; |
||
23 | |||
24 | /** @var IO\IOInterface */ |
||
25 | private $io; |
||
26 | |||
27 | /** @var Composer\Config */ |
||
28 | private $config; |
||
29 | |||
30 | /** @var Config */ |
||
31 | private $pluginConfig; |
||
32 | |||
33 | /** @var boolean */ |
||
34 | private $disabled = false; |
||
35 | |||
36 | private static $pluginClasses = array( |
||
37 | 'Aspects\AspectAuth', |
||
38 | 'Aspects\AspectProxy', |
||
39 | 'Aspects\AspectRedirect', |
||
40 | 'Aspects\GitHubRequest', |
||
41 | 'Aspects\GitLabRequest', |
||
42 | 'Aspects\HttpGetRequest', |
||
43 | 'Aspects\HttpGetResponse', |
||
44 | 'Aspects\JoinPoint', |
||
45 | 'Config', |
||
46 | 'CurlRemoteFilesystem', |
||
47 | 'Factory', |
||
48 | 'OutputFile', |
||
49 | 'ParallelDownloader', |
||
50 | 'Plugin', |
||
51 | ); |
||
52 | |||
53 | 3 | public function activate(Composer $composer, IO\IOInterface $io) |
|
54 | { |
||
55 | // @codeCoverageIgnoreStart |
||
56 | // guard for self-update problem |
||
57 | if (__CLASS__ !== 'Hirak\Prestissimo\Plugin') { |
||
58 | return $this->disable(); |
||
59 | } |
||
60 | // @codeCoverageIgnoreEnd |
||
61 | |||
62 | // load all classes |
||
63 | 3 | foreach (self::$pluginClasses as $class) { |
|
64 | 3 | class_exists(__NAMESPACE__ . '\\' . $class); |
|
65 | } |
||
66 | |||
67 | 3 | $this->composer = $composer; |
|
68 | 3 | $this->config = $composer->getConfig(); |
|
|
|||
69 | 3 | $this->io = $io; |
|
70 | 3 | $this->pluginConfig = $this->setPluginConfig(); |
|
71 | 3 | } |
|
72 | |||
73 | 1 | public static function getSubscribedEvents() |
|
74 | { |
||
75 | return array( |
||
76 | 1 | CPlugin\PluginEvents::PRE_FILE_DOWNLOAD => array( |
|
77 | array('onPreFileDownload', 0), |
||
78 | 1 | ), |
|
79 | 1 | Installer\InstallerEvents::POST_DEPENDENCIES_SOLVING => array( |
|
80 | 1 | array('onPostDependenciesSolving', PHP_INT_MAX), |
|
81 | ), |
||
82 | ); |
||
83 | } |
||
84 | |||
85 | 1 | public function onPreFileDownload(CPlugin\PreFileDownloadEvent $ev) |
|
86 | { |
||
87 | 1 | if ($this->disabled) { |
|
88 | 1 | return; |
|
89 | } |
||
90 | 1 | $scheme = parse_url($ev->getProcessedUrl(), PHP_URL_SCHEME); |
|
91 | 1 | if ($scheme === 'http' || $scheme === 'https') { |
|
92 | 1 | $rfs = $ev->getRemoteFilesystem(); |
|
93 | |||
94 | 1 | $curlrfs = new CurlRemoteFilesystem( |
|
95 | 1 | $this->io, |
|
96 | 1 | $this->config, |
|
97 | 1 | $rfs->getOptions() |
|
98 | ); |
||
99 | 1 | $curlrfs->setPluginConfig($this->pluginConfig->get()); |
|
100 | 1 | $ev->setRemoteFilesystem($curlrfs); |
|
101 | } |
||
102 | 1 | } |
|
103 | |||
104 | /** |
||
105 | * pre-fetch parallel by curl_multi |
||
106 | */ |
||
107 | 1 | public function onPostDependenciesSolving(Installer\InstallerEvent $ev) |
|
108 | { |
||
109 | 1 | if ($this->disabled) { |
|
110 | 1 | return; |
|
111 | } |
||
112 | 1 | $ops = $ev->getOperations(); |
|
113 | 1 | $packages = $this->filterPackages($ops); |
|
114 | 1 | $pluginConfig = $this->pluginConfig->get(); |
|
115 | 1 | if (count($packages) >= $pluginConfig['minConnections']) { |
|
116 | $downloader = new ParallelDownloader($this->io, $this->config); |
||
117 | $downloader->download($packages, $pluginConfig); |
||
118 | } |
||
119 | 1 | } |
|
120 | |||
121 | /** |
||
122 | * @param DependencyResolver\Operation\OperationInterface[] |
||
123 | * @return Package\PackageInterface[] |
||
124 | */ |
||
125 | 1 | private static function filterPackages(array $operations) |
|
126 | { |
||
127 | 1 | $packs = array(); |
|
128 | 1 | foreach ($operations as $op) { |
|
129 | switch ($op->getJobType()) { |
||
130 | case 'install': |
||
131 | $packs[] = $op->getPackage(); |
||
132 | break; |
||
133 | case 'update': |
||
134 | $packs[] = $op->getTargetPackage(); |
||
135 | break; |
||
136 | } |
||
137 | } |
||
138 | 1 | return $packs; |
|
139 | } |
||
140 | |||
141 | 3 | private function setPluginConfig() |
|
142 | { |
||
143 | 3 | $config = $this->config->get('prestissimo'); |
|
144 | 3 | if (!is_array($config)) { |
|
145 | 3 | $config = array(); |
|
146 | } |
||
147 | 3 | return new Config($config); |
|
148 | } |
||
149 | |||
150 | 2 | public function disable() |
|
154 | |||
155 | 1 | public function isDisabled() |
|
159 | } |
||
160 |
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..