1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class DNBranch |
5
|
|
|
* |
6
|
|
|
* @method string getName() |
7
|
|
|
*/ |
8
|
|
|
class DNBranch extends ViewableData { |
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @var Gitonomy\Git\Reference\Branch |
12
|
|
|
*/ |
13
|
|
|
protected $branch = null; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var DNProject |
17
|
|
|
*/ |
18
|
|
|
protected $project = null; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var DNData |
22
|
|
|
*/ |
23
|
|
|
protected $data = null; |
24
|
|
|
|
25
|
|
|
private static $casting = array( |
|
|
|
|
26
|
|
|
'Name' => 'Text', |
27
|
|
|
'SHA' => 'Text' |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var SS_Datetime |
32
|
|
|
*/ |
33
|
|
|
protected $_lastUpdatedCache = ''; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param DNProject $project |
37
|
|
|
* @param DNData $data |
38
|
|
|
*/ |
39
|
|
|
public function __construct(Gitonomy\Git\Reference\Branch $branch, DNProject $project, DNData $data) { |
40
|
|
|
$this->branch = $branch; |
41
|
|
|
$this->project = $project; |
42
|
|
|
$this->data = $data; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function __toString() { |
46
|
|
|
return $this->Name(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function Name() { |
53
|
|
|
return (string)htmlentities($this->branch->getName()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function Link() { |
57
|
|
|
// Use a get-var for branch so that it can handle unsafe chars better |
58
|
|
|
return Controller::join_links($this->project->Link(), 'branch?name=' . urlencode($this->Name())); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function SHA() { |
65
|
|
|
return (string)htmlentities($this->branch->getCommit()->getHash()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Provides a DNBuildList of builds found in this project. |
70
|
|
|
*/ |
71
|
|
|
public function DNBuildList() { |
72
|
|
|
$blockBranch = $this->branch->getName() == 'master' ? null : 'master'; |
73
|
|
|
return DNReferenceList::create($this->project, $this->data, $this->branch, $blockBranch); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return SS_Datetime |
78
|
|
|
*/ |
79
|
|
|
public function LastUpdated() { |
80
|
|
|
|
81
|
|
|
if($this->_lastUpdatedCache) { |
82
|
|
|
return $this->_lastUpdatedCache; |
83
|
|
|
} |
84
|
|
|
try { |
85
|
|
|
$created = $this->branch->getCommit()->getCommitterDate(); |
86
|
|
|
} catch(Exception $e) { |
87
|
|
|
//occasionally parsing will fail this is a fallback to make it still work |
88
|
|
|
return new SS_Datetime(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$created->setTimezone(new DateTimeZone(date_default_timezone_get())); |
92
|
|
|
|
93
|
|
|
$date = SS_Datetime::create(); |
94
|
|
|
$date->setValue($created->format('Y-m-d H:i:s')); |
95
|
|
|
$this->_lastUpdatedCache = $date; |
96
|
|
|
return $date; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function IsOpenByDefault() { |
103
|
|
|
if($this->Name() == 'master') { |
104
|
|
|
return " open"; |
105
|
|
|
} else { |
106
|
|
|
return ""; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.