1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Pheanstalk\Structure; |
5
|
|
|
|
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
|
8
|
|
|
class Workflow |
9
|
|
|
{ |
10
|
|
|
/** @var null|string */ |
11
|
|
|
private $id; |
12
|
|
|
|
13
|
|
|
/** @var $name string */ |
|
|
|
|
14
|
|
|
private $name; |
15
|
|
|
|
16
|
|
|
/** @var string $group */ |
17
|
|
|
private $group; |
18
|
|
|
|
19
|
|
|
/** @var ArrayCollection[Job] */ |
|
|
|
|
20
|
|
|
private $jobs; |
21
|
|
|
|
22
|
|
|
/** @var null|string $comment */ |
23
|
|
|
private $comment; |
24
|
|
|
|
25
|
|
|
/** @var null|int $boundToSchedule */ |
26
|
|
|
private $boundToSchedule; |
27
|
|
|
|
28
|
|
|
/** @var null|int $lastcommit */ |
29
|
|
|
private $lastcommit; |
30
|
|
|
|
31
|
|
|
/** @var null|int $modified */ |
32
|
|
|
private $modified; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Job constructor. |
36
|
|
|
* |
37
|
|
|
* @param string $name The name of the workflow |
38
|
|
|
* @param string $group The group of the workflow |
39
|
|
|
* @param ArrayCollection[Job] $jobs The collection of jobs |
|
|
|
|
40
|
|
|
* @param null|string $comment The comment of the workflow |
41
|
|
|
*/ |
42
|
21 |
|
public function __construct(string $name, string $group, ArrayCollection $jobs, ?string $comment = null) |
43
|
|
|
{ |
44
|
21 |
|
$this->name = $name; |
45
|
21 |
|
$this->group = $group; |
46
|
21 |
|
$this->setJobs($jobs); |
47
|
21 |
|
$this->comment = $comment; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string|null |
52
|
|
|
*/ |
53
|
12 |
|
public function getId(): ?string |
54
|
|
|
{ |
55
|
12 |
|
return $this->id; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string|null $id |
60
|
|
|
* |
61
|
|
|
* @return Workflow |
62
|
|
|
*/ |
63
|
13 |
|
public function setId(?string $id): Workflow |
64
|
|
|
{ |
65
|
13 |
|
$this->id = $id; |
66
|
13 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
13 |
|
public function getName(): string |
73
|
|
|
{ |
74
|
13 |
|
return $this->name; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $name |
79
|
|
|
* |
80
|
|
|
* @return Workflow |
81
|
|
|
*/ |
82
|
1 |
|
public function setName(string $name): Workflow |
83
|
|
|
{ |
84
|
1 |
|
$this->name = $name; |
85
|
1 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
7 |
|
public function getGroup(): string |
92
|
|
|
{ |
93
|
7 |
|
return $this->group; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $group |
98
|
|
|
* |
99
|
|
|
* @return Workflow |
100
|
|
|
*/ |
101
|
1 |
|
public function setGroup(string $group): Workflow |
102
|
|
|
{ |
103
|
1 |
|
$this->group = $group; |
104
|
1 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return string|null |
109
|
|
|
*/ |
110
|
8 |
|
public function getComment(): ?string |
111
|
|
|
{ |
112
|
8 |
|
return $this->comment; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string|null $comment |
117
|
|
|
* |
118
|
|
|
* @return Workflow |
119
|
|
|
*/ |
120
|
2 |
|
public function setComment(?string $comment): Workflow |
121
|
|
|
{ |
122
|
2 |
|
$this->comment = $comment; |
123
|
2 |
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return ArrayCollection |
128
|
|
|
*/ |
129
|
8 |
|
public function getJobs(): ArrayCollection |
130
|
|
|
{ |
131
|
8 |
|
return $this->jobs; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param ArrayCollection $jobs |
136
|
|
|
* |
137
|
|
|
* @return Workflow |
138
|
|
|
*/ |
139
|
21 |
|
public function setJobs(ArrayCollection $jobs): Workflow |
140
|
|
|
{ |
141
|
|
|
$this->jobs = $jobs->filter(function(Job $job) { |
|
|
|
|
142
|
13 |
|
return true; |
143
|
21 |
|
}); |
144
|
21 |
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param Job $job |
149
|
|
|
* |
150
|
|
|
* @return Workflow |
151
|
|
|
*/ |
152
|
2 |
|
public function addJob(Job $job): Workflow |
153
|
|
|
{ |
154
|
2 |
|
$this->jobs[] = $job; |
155
|
2 |
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param Job $job |
160
|
|
|
* |
161
|
|
|
* @return Workflow |
162
|
|
|
*/ |
163
|
1 |
|
public function removeJob(Job $job): Workflow |
164
|
|
|
{ |
165
|
1 |
|
$this->jobs->removeElement($job); |
166
|
1 |
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return int|null |
171
|
|
|
*/ |
172
|
1 |
|
public function getBoundToSchedule(): ?int |
173
|
|
|
{ |
174
|
1 |
|
return $this->boundToSchedule; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param int|null $boundToSchedule |
179
|
|
|
* |
180
|
|
|
* @return Workflow |
181
|
|
|
*/ |
182
|
10 |
|
public function setBoundToSchedule(?int $boundToSchedule): Workflow |
183
|
|
|
{ |
184
|
10 |
|
$this->boundToSchedule = $boundToSchedule; |
185
|
10 |
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return int|null |
190
|
|
|
*/ |
191
|
1 |
|
public function getLastcommit(): ?int |
192
|
|
|
{ |
193
|
1 |
|
return $this->lastcommit; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param int|null $lastcommit |
198
|
|
|
* |
199
|
|
|
* @return Workflow |
200
|
|
|
*/ |
201
|
10 |
|
public function setLastcommit(?int $lastcommit): Workflow |
202
|
|
|
{ |
203
|
10 |
|
$this->lastcommit = $lastcommit; |
204
|
10 |
|
return $this; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return int|null |
209
|
|
|
*/ |
210
|
1 |
|
public function getModified(): ?int |
211
|
|
|
{ |
212
|
1 |
|
return $this->modified; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param int|null $modified |
217
|
|
|
* |
218
|
|
|
* @return Workflow |
219
|
|
|
*/ |
220
|
10 |
|
public function setModified(?int $modified): Workflow |
221
|
|
|
{ |
222
|
10 |
|
$this->modified = $modified; |
223
|
10 |
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return \DOMDocument |
228
|
|
|
* @throws \ReflectionException |
229
|
|
|
*/ |
230
|
7 |
|
public function getXml() |
231
|
|
|
{ |
232
|
7 |
|
$dom = new \DOMDocument("1.0", "utf-8"); |
233
|
7 |
|
$root = $dom->createElement("workflow"); |
234
|
7 |
|
$subjobs = $dom->createElement("subjobs"); |
235
|
|
|
/** @var Job $job*/ |
236
|
7 |
|
foreach ($this->getJobs() as $job) { |
237
|
7 |
|
$jobNode = $job->getXml()->getElementsByTagName('job')->item(0); |
238
|
7 |
|
$subjobs->appendChild($dom->importNode($jobNode, true)); |
239
|
|
|
} |
240
|
7 |
|
$root->appendChild($subjobs); |
241
|
7 |
|
$dom->appendChild($root); |
242
|
7 |
|
return $dom; |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|