This repository has been archived by the owner on Dec 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReleaseFactory.php
73 lines (62 loc) · 1.85 KB
/
ReleaseFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace Composer\Itineris\WordPress;
use Composer\Itineris\WordPress\Requirement\RequirementCollection;
use Composer\Itineris\WordPress\Util\Url;
use Composer\Util\RemoteFilesystem;
class ReleaseFactory
{
/** @var RequirementCollection */
protected $requirementCollection;
/** @var RemoteFilesystem */
protected $rfs;
public function __construct(
RequirementCollection $requirementCollection,
RemoteFilesystem $rfs
) {
$this->requirementCollection = $requirementCollection;
$this->rfs = $rfs;
}
public static function make(RemoteFilesystem $rfs): self
{
return new static(
RequirementCollection::make(),
$rfs
);
}
public function build(string $version, string $downloadUrl): ?Release
{
$shasum = $this->getShasum($downloadUrl);
if (null === $shasum) {
return null;
}
return new Release(
'itinerisltd/wordpress',
$version,
[
'type' => 'zip',
'url' => $downloadUrl,
'shasum' => $shasum,
'mirrors' => $this->getMirrors($downloadUrl),
],
$this->requirementCollection->forWordPressCore($version)
);
}
protected function getShasum(string $url): ?string
{
$shasum = $this->rfs->getContents(
Url::getHost($url),
$url . '.sha1'
);
return is_string($shasum) ? $shasum : null;
}
protected function getMirrors(string $downloadUrl): ?array
{
$mirror = str_replace(
'https://wordpress.org/wordpress-',
'https://downloads.wordpress.org/release/wordpress-',
$downloadUrl
);
return $downloadUrl === $mirror ? null : [$mirror];
}
}