1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* GitElephant - An abstraction layer for git written in PHP |
5
|
|
|
* Copyright (C) 2013 Matteo Giachino |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program. If not, see [http://www.gnu.org/licenses/]. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace GitElephant\Objects\Commit; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Represents a commit message |
25
|
|
|
* |
26
|
|
|
* @author Mathias Geat <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class Message |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* the message |
32
|
|
|
* |
33
|
|
|
* @var array|string |
34
|
|
|
*/ |
35
|
|
|
private $message; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Class constructor |
39
|
|
|
* |
40
|
|
|
* @param array|string $message Message lines |
41
|
|
|
*/ |
42
|
37 |
|
public function __construct($message) |
43
|
|
|
{ |
44
|
37 |
|
if (is_array($message)) { |
45
|
37 |
|
$this->message = $message; |
46
|
|
|
} else { |
47
|
|
|
$this->message = []; |
48
|
|
|
$this->message = (string)$message; |
49
|
|
|
} |
50
|
37 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Short message equals first message line |
54
|
|
|
* |
55
|
|
|
* @return string|null |
56
|
|
|
*/ |
57
|
4 |
|
public function getShortMessage(): ?string |
58
|
|
|
{ |
59
|
4 |
|
return $this->toString(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Full commit message |
64
|
|
|
* |
65
|
|
|
* @return string|null |
66
|
|
|
*/ |
67
|
2 |
|
public function getFullMessage(): ?string |
68
|
|
|
{ |
69
|
2 |
|
return $this->toString(true); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Return message string |
74
|
|
|
* |
75
|
|
|
* @param bool $full get the full message |
76
|
|
|
* |
77
|
|
|
* @return string|null |
78
|
|
|
*/ |
79
|
11 |
|
public function toString(bool $full = false) |
80
|
|
|
{ |
81
|
11 |
|
if (empty($this->message)) { |
82
|
|
|
return null; |
83
|
|
|
} |
84
|
|
|
|
85
|
11 |
|
if ($full) { |
86
|
2 |
|
return implode(PHP_EOL, $this->message); |
87
|
|
|
} else { |
88
|
10 |
|
return $this->message[0]; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* String representation equals short message |
94
|
|
|
* |
95
|
|
|
* @return string|null |
96
|
|
|
*/ |
97
|
4 |
|
public function __toString(): ?string |
98
|
|
|
{ |
99
|
4 |
|
return $this->toString(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|