-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVersion.php
More file actions
182 lines (139 loc) · 4.25 KB
/
Copy pathVersion.php
File metadata and controls
182 lines (139 loc) · 4.25 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
namespace CodedMonkey\Dirigent\Doctrine\Entity;
use CodedMonkey\Dirigent\Doctrine\Repository\VersionRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: VersionRepository::class)]
#[ORM\UniqueConstraint(name: 'package_version_idx', columns: ['package_id', 'normalized_name'])]
class Version extends TrackedEntity implements \Stringable
{
#[ORM\Id]
#[ORM\Column]
#[ORM\GeneratedValue]
private ?int $id = null;
#[ORM\Column]
private string $name;
#[ORM\Column(length: 191)]
private string $normalizedName;
#[ORM\Column]
private bool $development;
#[ORM\Column]
private bool $pruned = false;
#[ORM\Column]
private bool $defaultBranch = false;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\ManyToOne(targetEntity: Package::class, inversedBy: 'versions')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private Package $package;
#[ORM\OneToOne(fetch: 'EAGER')]
private ?Metadata $currentMetadata = null;
#[ORM\OneToOne(inversedBy: 'version', cascade: ['persist', 'detach', 'remove'])]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private VersionInstallations $installations;
public function __construct(Package $package)
{
$this->package = $package;
$this->installations = new VersionInstallations($this);
$package->getVersions()->add($this);
}
public function __toString(): string
{
$packageName = $this->package->getName();
return "$packageName $this->name ($this->normalizedName)";
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getNormalizedName(): string
{
return $this->normalizedName;
}
public function setNormalizedName(string $normalizedName): void
{
$this->normalizedName = $normalizedName;
}
public function isDevelopment(): bool
{
return $this->development;
}
public function setDevelopment(bool $development): void
{
$this->development = $development;
}
public function isPruned(): bool
{
return $this->pruned;
}
public function setPruned(bool $pruned): void
{
$this->pruned = $pruned;
}
public function isDefaultBranch(): bool
{
return $this->defaultBranch;
}
public function setDefaultBranch(bool $defaultBranch): void
{
$this->defaultBranch = $defaultBranch;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): void
{
$this->updatedAt = $updatedAt;
}
public function getPackage(): Package
{
return $this->package;
}
public function hasCurrentMetadata(): bool
{
return null !== $this->currentMetadata;
}
public function getCurrentMetadata(): Metadata
{
if (null === $this->currentMetadata) {
// Packages are only allowed to have no current metadata during import
throw new \RuntimeException(sprintf('No current metadata found for package: %s %s', $this->package->getName(), $this->name));
}
return $this->currentMetadata;
}
public function setCurrentMetadata(Metadata $metadata): void
{
$this->currentMetadata = $metadata;
}
public function getInstallations(): VersionInstallations
{
return $this->installations;
}
public function getExtendedName(): string
{
return $this->name . ($this->getCurrentMetadata()->hasVersionAlias() ? ' / ' . $this->getCurrentMetadata()->getVersionAlias() : '');
}
public function getMajorVersion(): int
{
$split = explode('.', $this->name);
return (int) $split[0];
}
public function getMinorVersion(): int
{
$split = explode('.', $this->name);
return (int) $split[1];
}
public function getPatchVersion(): int
{
$split = explode('.', $this->name);
return (int) $split[2];
}
}