/
Factory.php
343 lines (319 loc) · 8.89 KB
/
Factory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php
/**
* Components_Component_Factory:: generates component instances.
*
* PHP version 5
*
* @category Horde
* @package Components
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Components
*/
/**
* Components_Component_Factory:: generates component instances.
*
* Copyright 2011-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Components
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Components
*/
class Components_Component_Factory
{
/**
* The configuration for the current job.
*
* @var Components_Config
*/
protected $_config;
/**
* The factory for PEAR handlers.
*
* @var Components_Factory
*/
protected $_factory;
/**
* The HTTP client for remote access.
*
* @var Horde_Http_Client
*/
protected $_client;
/**
* The first source component generated
*
* @var Components_Component
*/
protected $_first_source;
/**
* The git root path.
*
* @var Components_Helper_Root
*/
protected $_git_root;
/**
* The resolver instance.
*
* @var Components_Component_Resolver
*/
protected $_resolver;
/**
* Constructor.
*
* @param Components_Config $config The configuration for the current job.
* @param Components_Pear_Factory $factory Generator for all
* required PEAR components.
* @param Horde_Http_Client $client The HTTP client for remote access.
*/
public function __construct(
Components_Config $config,
Components_Pear_Factory $factory,
Horde_Http_Client $client
)
{
$this->_config = $config;
$this->_factory = $factory;
$this->_client = $client;
}
/**
* Create a representation for a source component.
*
* @param string $directory The directory of the component.
*
* @return Components_Component_Source The source component.
*/
public function createSource($directory)
{
$component = new Components_Component_Source(
$directory,
$this->_config,
$this
);
if ($this->_first_source === null) {
$this->_first_source = $component;
}
return $component;
}
/**
* Create a representation for a component archive.
*
* @param string $archive The path to the component archive.
*
* @return Components_Component_Archive The archive component.
*/
public function createArchive($archive)
{
$component = new Components_Component_Archive(
$archive,
$this->_config,
$this
);
return $component;
}
/**
* Create a representation for a remote component.
*
* @param string $name The name of the component.
* @param string $stability The stability of the component.
* @param string $channel The component channel.
* @param Horde_Pear_Remote $remote The remote server handler.
*
* @return Components_Component_Remote The remote component.
*/
public function createRemote(
$name, $stability, $channel, Horde_Pear_Remote $remote
)
{
return new Components_Component_Remote(
$name,
$stability,
$channel,
$remote,
$this->_client,
$this->_config,
$this
);
}
/**
* Provide access to the PEAR helper factory.
*
* @return Components_Pear_Factory The PEAR factory.
*/
public function pear()
{
return $this->_factory;
}
/**
* Create a component dependency list.
*
* @param Components_Component $component The component.
*
* @return Components_Component_DependencyList The dependency list.
*/
public function createDependencyList(Components_Component $component)
{
return new Components_Component_DependencyList($component, $this);
}
/**
* Create a component dependency representation.
*
* @param array $dependencies The dependency information.
* @param Components_Component $parent The parent component.
*
* @return Components_Component_Dependency The dependency.
*/
public function createDependency($dependencies)
{
return new Components_Component_Dependency(
$dependencies, $this
);
}
/**
* Get the component resolver.
*
* @return Components_Component_Resolver The component resolver.
*/
public function getResolver()
{
if (!isset($this->_resolver)) {
$this->_resolver = $this->createResolver();
}
return $this->_resolver;
}
/**
* Create a component resolver.
*
* @return Components_Component_Resolver The component resolver.
*/
public function createResolver()
{
return new Components_Component_Resolver(
$this->getGitRoot(),
$this
);
}
/**
* Create a remote PEAR server handler for a specific channel.
*
* @param string $channel The channel name.
*
* @return Horde_Pear_Remote The remote handler.
*/
public function createRemoteChannel($channel)
{
return new Horde_Pear_Remote($channel);
}
/**
* Create the sentinel helper.
*
* @param string $directory The directory the sentinel should act in.
*
* @return Horde_Release_Sentinel The sentinel helper.
*/
public function createSentinel($directory)
{
return new Horde_Release_Sentinel($directory);
}
/**
* Return the repository root helper.
*
* @return Components_Helper_Root The helper.
*/
public function getGitRoot()
{
if (!isset($this->_git_root)) {
$this->_git_root = $this->createGitRoot();
}
return $this->_git_root;
}
/**
* Create the repository root helper.
*
* @return Components_Helper_Root The helper.
*/
public function createGitRoot()
{
if (isset($this->_first_source)) {
return new Components_Helper_Root(
$this->_config->getOptions(),
$this->_first_source
);
} else {
return new Components_Helper_Root(
$this->_config->getOptions()
);
}
}
/**
* Return the package.xml handler.
*
* @param string $package_xml_path Path to the package.xml file.
*
* @return Horde_Pear_Package_Xml
*/
public function createPackageXml($package_xml_path)
{
return new Horde_Pear_Package_Xml($package_xml_path);
}
/**
* Creates a new package.xml.
*
* @param string $package_xml_dir Path to the parent directory of the
* new package.xml file.
*/
public function createPackageFile($package_xml_dir)
{
$type = new Horde_Pear_Package_Type_Horde($package_xml_dir);
$type->writePackageXmlDraft();
}
/**
* Creates a new package.xml for a theme.
*
* @param string $package_xml_dir Path to the parent directory of the
* new package.xml file.
*/
public function createThemePackageFile($package_xml_dir)
{
$type = new Horde_Pear_Package_Type_HordeTheme($package_xml_dir);
$type->writePackageXmlDraft();
}
/**
* Creates a new content listing.
*
* @param string $package_xml_dir Path to the parent directory of the
* new package.xml file.
*
* @return Horde_Pear_Package_Contents_List
*/
public function createContentList($package_xml_dir)
{
return new Horde_Pear_Package_Contents_List(
new Horde_Pear_Package_Type_Horde(
$package_xml_dir,
$this->getGitRoot()->getRoot()
)
);
}
/**
* Creates a new content listing for a theme.
*
* @param string $package_xml_dir Path to the parent directory of the
* new package.xml file.
*
* @return Horde_Pear_Package_Contents_List
*/
public function createThemeContentList($package_xml_dir)
{
return new Horde_Pear_Package_Contents_List(
new Horde_Pear_Package_Type_HordeTheme(
$package_xml_dir,
$this->getGitRoot()->getRoot()
)
);
}
}