|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Drush Cerbere command line tools. |
|
5
|
|
|
* Copyright (C) 2015 - Sebastien Malot <[email protected]> |
|
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 2 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 along |
|
18
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
|
19
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace Cerbere\Model; |
|
23
|
|
|
|
|
24
|
|
|
use Cerbere\Action\ActionInterface; |
|
25
|
|
|
use Cerbere\Versioning\VersioningInterface; |
|
26
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
27
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class Job |
|
31
|
|
|
* @package Cerbere\Model |
|
32
|
|
|
*/ |
|
33
|
|
|
class Job |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @var EventDispatcherInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $dispatcher; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var VersioningInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $versioning = null; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var ActionInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $action; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $source_url; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var array |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $source_options; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $patterns = array(); |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var boolean |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $pattern_nested = false; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var string |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $workingDirectory = ''; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
*/ |
|
77
|
|
|
public function __construct() |
|
78
|
|
|
{ |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return Job |
|
83
|
|
|
*/ |
|
84
|
|
|
public function checkoutRepository() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->getVersioning()->prepare($this->source_url); |
|
87
|
|
|
$workingDirectory = $this->getVersioning()->getWorkingDirectory(); |
|
88
|
|
|
$this->getVersioning()->process($this->source_url, $workingDirectory, $this->source_options); |
|
89
|
|
|
|
|
90
|
|
|
return $workingDirectory; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return VersioningInterface |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getVersioning() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->versioning; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param VersioningInterface $versioning |
|
103
|
|
|
* |
|
104
|
|
|
* @return Job |
|
105
|
|
|
*/ |
|
106
|
|
|
public function setVersioning(VersioningInterface $versioning) |
|
107
|
|
|
{ |
|
108
|
|
|
$this->versioning = $versioning; |
|
109
|
|
|
|
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return ActionInterface |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getAction() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->action; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param ActionInterface $action |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setAction($action) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->action = $action; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Gets the dispatcher used by this library to dispatch events. |
|
131
|
|
|
* |
|
132
|
|
|
* @return EventDispatcherInterface |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getDispatcher() |
|
135
|
|
|
{ |
|
136
|
|
|
if (!isset($this->dispatcher)) { |
|
137
|
|
|
$this->dispatcher = new EventDispatcher(); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $this->dispatcher; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Sets the dispatcher used by this library to dispatch events. |
|
145
|
|
|
* |
|
146
|
|
|
* @param EventDispatcherInterface $dispatcher |
|
147
|
|
|
* The Symfony event dispatcher object. |
|
148
|
|
|
* |
|
149
|
|
|
* @return $this |
|
150
|
|
|
*/ |
|
151
|
|
|
public function setDispatcher(EventDispatcherInterface $dispatcher) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->dispatcher = $dispatcher; |
|
154
|
|
|
|
|
155
|
|
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return array |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getPatterns() |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->patterns; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @param array $patterns |
|
168
|
|
|
* @param boolean $nested |
|
169
|
|
|
* |
|
170
|
|
|
* @return Job |
|
171
|
|
|
*/ |
|
172
|
|
|
public function setPatterns($patterns, $nested = false) |
|
173
|
|
|
{ |
|
174
|
|
|
$this->patterns = $patterns; |
|
175
|
|
|
$this->pattern_nested = $nested; |
|
176
|
|
|
|
|
177
|
|
|
return $this; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @return boolean |
|
182
|
|
|
*/ |
|
183
|
|
|
public function isPatternNested() |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->pattern_nested; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @param string $url |
|
190
|
|
|
* @param array $options |
|
191
|
|
|
*/ |
|
192
|
|
|
public function setSource($url, $options = array()) |
|
193
|
|
|
{ |
|
194
|
|
|
$this->source_url = $url; |
|
195
|
|
|
$this->source_options = $options; |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|