|
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\Repository\ComposerRepository; |
|
10
|
|
|
|
|
11
|
|
|
class ParallelizedComposerRepository extends ComposerRepository |
|
12
|
|
|
{ |
|
13
|
|
|
protected function preloadProviderListings($data) |
|
14
|
|
|
{ |
|
15
|
|
|
if ($this->providersUrl && isset($data['provider-includes'])) { |
|
16
|
|
|
$includes = $data['provider-includes']; |
|
17
|
|
|
|
|
18
|
|
|
$requests = array(); |
|
19
|
|
|
$cachedir = $this->config->get('cache-repo-dir'); |
|
20
|
|
|
$cacheBase = $cachedir . DIRECTORY_SEPARATOR . str_replace('://', '---', $this->baseUrl); |
|
21
|
|
|
foreach ($includes as $include => $metadata) { |
|
22
|
|
|
$url = $this->baseUrl . '/' . str_replace('%hash%', $metadata['sha256'], $include); |
|
23
|
|
|
$cacheKey = str_replace(array('%hash%','$'), '', $include); |
|
24
|
|
|
if ($this->cache->sha256($cacheKey) !== $metadata['sha256']) { |
|
25
|
|
|
$dest = $cacheBase . DIRECTORY_SEPARATOR . str_replace('/', '-', $cacheKey); |
|
26
|
|
|
$requests[] = new CopyRequest($url, $dest, false, $this->io, $this->config); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
if ($requests) { |
|
|
|
|
|
|
30
|
|
|
$prefetcher = new Prefetcher; |
|
31
|
|
|
$prefetcher->fetchAll($this->io, $requests); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function prefetch() |
|
37
|
|
|
{ |
|
38
|
|
|
if (null === $this->providerListing) { |
|
39
|
|
|
$this->preloadProviderListings($this->loadRootServerFile()); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function __debugInfo() |
|
44
|
|
|
{ |
|
45
|
|
|
return array( |
|
46
|
|
|
'url' => $this->url, |
|
47
|
|
|
'repoConfig' => $this->repoConfig, |
|
48
|
|
|
'options' => $this->options, |
|
49
|
|
|
'baseUrl' => $this->baseUrl, |
|
50
|
|
|
'notifyUrl' => $this->notifyUrl, |
|
51
|
|
|
'searchUrl' => $this->searchUrl, |
|
52
|
|
|
'hasProviders' => $this->hasProviders, |
|
53
|
|
|
'providersUrl' => $this->providersUrl, |
|
54
|
|
|
'lazyProvidersUrl' => $this->lazyProvidersUrl, |
|
55
|
|
|
'providerListing' => $this->providerListing, |
|
56
|
|
|
'providers' => $this->providers, |
|
57
|
|
|
'providersByUid' => $this->providersByUid, |
|
58
|
|
|
'rootAliases' => $this->rootAliases, |
|
59
|
|
|
'allowSslDowngrade' => $this->allowSslDowngrade, |
|
60
|
|
|
'sourceMirrors' => $this->sourceMirrors, |
|
61
|
|
|
'distMirrors' => $this->distMirrors, |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.