-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVersionedPackage.php
More file actions
106 lines (90 loc) · 3.03 KB
/
VersionedPackage.php
File metadata and controls
106 lines (90 loc) · 3.03 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace Winter\Packager\Package;
use Composer\Semver\VersionParser;
use Winter\Packager\Composer;
use Winter\Packager\Enums\VersionStatus;
/**
* @author Ben Thomson <git@alfreido.com>
* @since 0.3.0
*/
class VersionedPackage extends Package
{
protected string $versionNormalized;
protected string $latestVersionNormalized;
public function __construct(
string $namespace,
string $name,
string $description = '',
string $type = '',
string $path = '',
protected string $version = '',
protected string $latestVersion = '',
protected VersionStatus $updateStatus = VersionStatus::UP_TO_DATE,
) {
parent::__construct($namespace, $name, $description, $type, $path);
$this->versionNormalized = $this->normalizeVersion($this->version);
}
public function setVersion(string $version): void
{
$this->version = $version;
$this->versionNormalized = $this->normalizeVersion($version);
}
public function getVersion(): string
{
return $this->version;
}
public function getVersionNormalized(): string
{
return $this->versionNormalized;
}
public function setLatestVersion(string $latestVersion): void
{
$this->latestVersion = $latestVersion;
$this->latestVersionNormalized = $this->normalizeVersion($latestVersion);
}
public function getLatestVersion(): string
{
return $this->latestVersion;
}
public function getLatestVersionNormalized(): string
{
return $this->latestVersionNormalized;
}
public function setUpdateStatus(VersionStatus $updateStatus): void
{
$this->updateStatus = $updateStatus;
}
public function getUpdateStatus(): VersionStatus
{
return $this->updateStatus;
}
protected function normalizeVersion(string $version): string
{
$parser = new VersionParser;
return $parser->normalize($version);
}
public function toDetailed(): DetailedVersionedPackage
{
$details = Packagist::getPackage($this->namespace, $this->name, $this->version);
return Composer::newDetailedVersionedPackage(
namespace: $this->namespace,
name: $this->name,
description: $this->description ?? '',
type: $details['type'] ?? 'library',
keywords: $details['keywords'] ?? [],
homepage: $details['homepage'] ?? '',
authors: $details['authors'] ?? [],
licenses: $details['licenses'] ?? [],
support: $details['support'] ?? [],
funding: $details['funding'] ?? [],
requires: $details['require'] ?? [],
devRequires: $details['require-dev'] ?? [],
extras: $details['extra'] ?? [],
suggests: $details['suggest'] ?? [],
conflicts: $details['conflict'] ?? [],
replaces: $details['replace'] ?? [],
readme: $details['readme'] ?? '',
version: $details['version'],
);
}
}