1
|
|
|
<?php |
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
3
|
|
|
* |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Deployer\Support\Changelog; |
9
|
|
|
|
10
|
|
|
class Changelog |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $title; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var Version[] |
19
|
|
|
*/ |
20
|
|
|
private $versions = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private $references = []; |
26
|
|
|
|
27
|
1 |
|
public function __toString() |
28
|
|
|
{ |
29
|
1 |
|
$versions = join("\n", $this->versions); |
30
|
|
|
|
31
|
1 |
|
krsort($this->references, SORT_NUMERIC); |
32
|
|
|
|
33
|
|
|
$references = join("\n", array_map(function ($link, $ref) { |
34
|
1 |
|
return "[#$ref]: $link"; |
35
|
1 |
|
}, $this->references, array_keys($this->references))); |
36
|
|
|
|
37
|
|
|
return <<<MD |
38
|
1 |
|
# {$this->title} |
39
|
|
|
|
40
|
|
|
|
41
|
1 |
|
{$versions} |
42
|
1 |
|
{$references} |
43
|
|
|
|
44
|
|
|
MD; |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
public function setTitle(string $title) |
48
|
|
|
{ |
49
|
2 |
|
$this->title = $title; |
50
|
2 |
|
} |
51
|
|
|
|
52
|
2 |
|
public function addVersion(Version $version) |
53
|
|
|
{ |
54
|
2 |
|
$this->versions[] = $version; |
55
|
2 |
|
} |
56
|
|
|
|
57
|
|
|
public function prependVersion(Version $version) |
58
|
|
|
{ |
59
|
|
|
array_unshift($this->versions, $version); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function findMaster(): Version |
63
|
|
|
{ |
64
|
|
|
foreach ($this->versions as $version) { |
65
|
|
|
if ($version->getVersion() === 'master') { |
66
|
|
|
return $version; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$version = new Version(); |
71
|
|
|
$version->setVersion('master'); |
72
|
|
|
$version->setPrevious($this->findLatest()->getVersion()); |
73
|
|
|
$this->prependVersion($version); |
74
|
|
|
|
75
|
|
|
return $version; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function findLatest(): Version |
79
|
|
|
{ |
80
|
|
|
foreach ($this->versions as $version) { |
81
|
|
|
if ($version->getVersion() === 'master') { |
82
|
|
|
continue; |
83
|
|
|
} |
84
|
|
|
return $version; |
85
|
|
|
} |
86
|
|
|
throw new \RuntimeException('There no versions.'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param array $references |
91
|
|
|
*/ |
92
|
2 |
|
public function setReferences(array $references) |
93
|
|
|
{ |
94
|
2 |
|
$this->references = $references; |
95
|
2 |
|
} |
96
|
|
|
|
97
|
|
|
public function addReferences(int $ref, string $url) |
98
|
|
|
{ |
99
|
|
|
$this->references[$ref] = $url; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|