1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Changelog keeper |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/chkipper |
6
|
|
|
* @package chkipper |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\chkipper\history; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Note class. |
15
|
|
|
* |
16
|
|
|
* @property string $note |
17
|
|
|
* @property Commit[] $commits |
18
|
|
|
* |
19
|
|
|
* @author Andrii Vasyliev <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Note |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string note |
25
|
|
|
*/ |
26
|
|
|
protected $_note; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Commit[] array of commits |
30
|
|
|
*/ |
31
|
|
|
protected $_commits = []; |
32
|
|
|
|
33
|
|
|
public function __construct($note, $commits = []) |
34
|
|
|
{ |
35
|
|
|
$this->_note = $note; |
36
|
|
|
$this->_commits = $commits; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function findCommit($hash) |
40
|
|
|
{ |
41
|
|
|
if (!isset($this->_commits[$hash])) { |
42
|
|
|
$this->_commits[$hash] = new Commit($hash); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $this->_commits[$hash]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function removeCommit($hash) |
49
|
|
|
{ |
50
|
|
|
unset($this->_commits[$hash]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function removeCommits($hashes) |
54
|
|
|
{ |
55
|
|
|
foreach ($hashes as $hash) { |
56
|
|
|
$this->removeCommit($hash); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Appends commit along with comments. |
62
|
|
|
* @param Commit commit object |
63
|
|
|
*/ |
64
|
|
|
public function addCommit(Commit $commit) |
65
|
|
|
{ |
66
|
|
|
$new = $this->findCommit($commit->getHash()); |
67
|
|
|
$new->setLabel($commit->getLabel()); |
68
|
|
|
$new->addComments($commit->getComments()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Appends commits along with comments. |
73
|
|
|
* @param Commit[] array of commits |
74
|
|
|
*/ |
75
|
|
|
public function addCommits(array $commits) |
76
|
|
|
{ |
77
|
|
|
foreach ($commits as $commit) { |
78
|
|
|
$this->addCommit($commit); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns commits. |
84
|
|
|
* @return Commit[] |
85
|
|
|
*/ |
86
|
|
|
public function getCommits() |
87
|
|
|
{ |
88
|
|
|
return $this->_commits; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function setNote($value) |
92
|
|
|
{ |
93
|
|
|
$this->_note = $value; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getNote() |
97
|
|
|
{ |
98
|
|
|
return $this->_note; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|