1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WsdlToPhp\PackageGenerator\Generator; |
4
|
|
|
|
5
|
|
|
use WsdlToPhp\PackageGenerator\Model\Schema; |
6
|
|
|
use WsdlToPhp\PackageGenerator\Model\Wsdl; |
7
|
|
|
use WsdlToPhp\PackageGenerator\Model\AbstractModel; |
8
|
|
|
use WsdlToPhp\PackageGenerator\Model\EmptyModel; |
9
|
|
|
use WsdlToPhp\PackageGenerator\Model\Struct; |
10
|
|
|
use WsdlToPhp\PackageGenerator\Model\Service; |
11
|
|
|
use WsdlToPhp\PackageGenerator\Model\Method; |
12
|
|
|
use WsdlToPhp\PackageGenerator\Container\Model\Service as ServiceContainer; |
13
|
|
|
use WsdlToPhp\PackageGenerator\Container\Model\Struct as StructContainer; |
14
|
|
|
use WsdlToPhp\PackageGenerator\ConfigurationReader\GeneratorOptions; |
15
|
|
|
use WsdlToPhp\PackageGenerator\WsdlHandler\Wsdl as WsdlDocument; |
16
|
|
|
|
17
|
|
|
class Generator implements \JsonSerializable |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Wsdl |
21
|
|
|
* @var Wsdl |
22
|
|
|
*/ |
23
|
|
|
private $wsdl; |
24
|
|
|
/** |
25
|
|
|
* @var GeneratorOptions |
26
|
|
|
*/ |
27
|
|
|
private $options; |
28
|
|
|
/** |
29
|
|
|
* Used parsers |
30
|
|
|
* @var GeneratorParsers |
31
|
|
|
*/ |
32
|
|
|
private $parsers; |
33
|
|
|
/** |
34
|
|
|
* Used files |
35
|
|
|
* @var GeneratorFiles |
36
|
|
|
*/ |
37
|
|
|
private $files; |
38
|
|
|
/** |
39
|
|
|
* Used containers |
40
|
|
|
* @var GeneratorContainers |
41
|
|
|
*/ |
42
|
|
|
private $containers; |
43
|
|
|
/** |
44
|
|
|
* Used SoapClient |
45
|
|
|
* @var GeneratorSoapClient |
46
|
|
|
*/ |
47
|
|
|
private $soapClient; |
48
|
|
|
/** |
49
|
|
|
* Constructor |
50
|
|
|
* @param GeneratorOptions $options |
51
|
|
|
*/ |
52
|
|
|
public function __construct(GeneratorOptions $options) |
53
|
|
|
{ |
54
|
|
|
$this->setOptions($options)->initialize(); |
55
|
|
|
} |
56
|
|
|
/** |
57
|
|
|
* @return Generator |
58
|
|
|
*/ |
59
|
|
|
protected function initialize() |
60
|
|
|
{ |
61
|
|
|
return $this->initContainers() |
62
|
|
|
->initParsers() |
63
|
|
|
->initFiles() |
64
|
|
|
->initSoapClient() |
65
|
|
|
->initWsdl(); |
66
|
|
|
} |
67
|
|
|
/** |
68
|
|
|
* @throws \InvalidArgumentException |
69
|
|
|
* @return Generator |
70
|
|
|
*/ |
71
|
|
|
protected function initSoapClient() |
72
|
|
|
{ |
73
|
|
|
if (!isset($this->soapClient)) { |
74
|
|
|
$this->soapClient = new GeneratorSoapClient($this); |
75
|
|
|
} |
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
/** |
79
|
|
|
* @return Generator |
80
|
|
|
*/ |
81
|
|
|
protected function initContainers() |
82
|
|
|
{ |
83
|
|
|
if (!isset($this->containers)) { |
84
|
|
|
$this->containers = new GeneratorContainers($this); |
85
|
|
|
} |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
/** |
89
|
|
|
* @return Generator |
90
|
|
|
*/ |
91
|
|
|
protected function initParsers() |
92
|
|
|
{ |
93
|
|
|
if (!isset($this->parsers)) { |
94
|
|
|
$this->parsers = new GeneratorParsers($this); |
95
|
|
|
} |
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
/** |
99
|
|
|
* @return GeneratorParsers |
100
|
|
|
*/ |
101
|
|
|
public function getParsers() |
102
|
|
|
{ |
103
|
|
|
return $this->parsers; |
104
|
|
|
} |
105
|
|
|
/** |
106
|
|
|
* @return Generator |
107
|
|
|
*/ |
108
|
|
|
protected function initFiles() |
109
|
|
|
{ |
110
|
|
|
if (!isset($this->files)) { |
111
|
|
|
$this->files = new GeneratorFiles($this); |
112
|
|
|
} |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
/** |
116
|
|
|
* @return GeneratorFiles |
117
|
|
|
*/ |
118
|
|
|
public function getFiles() |
119
|
|
|
{ |
120
|
|
|
return $this->files; |
121
|
|
|
} |
122
|
|
|
/** |
123
|
|
|
* @throws \InvalidArgumentException |
124
|
|
|
* @return Generator |
125
|
|
|
*/ |
126
|
|
|
protected function initDirectory() |
127
|
|
|
{ |
128
|
|
|
Utils::createDirectory($this->getOptions()->getDestination()); |
129
|
|
|
if (!is_writable($this->getOptionDestination())) { |
130
|
|
|
throw new \InvalidArgumentException(sprintf('Unable to use dir "%s" as dir does not exists, its creation has been impossible or it\'s not writable', $this->getOptionDestination()), __LINE__); |
131
|
|
|
} |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
/** |
135
|
|
|
* @return Generator |
136
|
|
|
*/ |
137
|
|
|
protected function initWsdl() |
138
|
|
|
{ |
139
|
|
|
$this->setWsdl(new Wsdl($this, $this->getOptionOrigin(), $this->getUrlContent($this->getOptionOrigin()))); |
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
/** |
143
|
|
|
* @return Generator |
144
|
|
|
*/ |
145
|
|
|
protected function doSanityChecks() |
146
|
|
|
{ |
147
|
|
|
$destination = $this->getOptionDestination(); |
148
|
|
|
if (empty($destination)) { |
149
|
|
|
throw new \InvalidArgumentException('Package\'s destination must be defined', __LINE__); |
150
|
|
|
} |
151
|
|
|
$composerName = $this->getOptionComposerName(); |
152
|
|
|
if ($this->getOptionStandalone() && empty($composerName)) { |
153
|
|
|
throw new \InvalidArgumentException('Package\'s composer name must be defined', __LINE__); |
154
|
|
|
} |
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
/** |
158
|
|
|
* @return Generator |
159
|
|
|
*/ |
160
|
|
|
protected function doParse() |
161
|
|
|
{ |
162
|
|
|
$this->parsers->doParse(); |
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
/** |
166
|
|
|
* @return Generator |
167
|
|
|
*/ |
168
|
|
|
protected function doGenerate() |
169
|
|
|
{ |
170
|
|
|
$this->files->doGenerate(); |
171
|
|
|
return $this; |
172
|
|
|
} |
173
|
|
|
/** |
174
|
|
|
* Generates all classes based on options |
175
|
|
|
* @return Generator |
176
|
|
|
*/ |
177
|
|
|
public function generatePackage() |
178
|
|
|
{ |
179
|
|
|
return $this |
180
|
|
|
->doSanityChecks() |
181
|
|
|
->parse() |
182
|
|
|
->initDirectory() |
183
|
|
|
->doGenerate(); |
184
|
|
|
} |
185
|
|
|
/** |
186
|
|
|
* Only parses what has to be parsed, called before actually generating the package |
187
|
|
|
* @return Generator |
188
|
|
|
*/ |
189
|
|
|
public function parse() |
190
|
|
|
{ |
191
|
|
|
return $this->doParse(); |
192
|
|
|
} |
193
|
|
|
/** |
194
|
|
|
* Gets the struct by its name |
195
|
|
|
* @uses Generator::getStructs() |
196
|
|
|
* @param string $structName the original struct name |
197
|
|
|
* @return Struct|null |
198
|
|
|
*/ |
199
|
|
|
public function getStruct($structName) |
200
|
|
|
{ |
201
|
|
|
return $this->getStructs()->getStructByName($structName); |
202
|
|
|
} |
203
|
|
|
/** |
204
|
|
|
* Gets a service by its name |
205
|
|
|
* @param string $serviceName the service name |
206
|
|
|
* @return Service|null |
207
|
|
|
*/ |
208
|
|
|
public function getService($serviceName) |
209
|
|
|
{ |
210
|
|
|
return $this->getServices()->getServiceByName($serviceName); |
211
|
|
|
} |
212
|
|
|
/** |
213
|
|
|
* Returns the method |
214
|
|
|
* @uses Generator::getServiceName() |
215
|
|
|
* @uses Generator::getService() |
216
|
|
|
* @uses Service::getMethod() |
217
|
|
|
* @param string $methodName the original function name |
218
|
|
|
* @return Method|null |
219
|
|
|
*/ |
220
|
|
|
public function getServiceMethod($methodName) |
221
|
|
|
{ |
222
|
|
|
return $this->getService($this->getServiceName($methodName)) instanceof Service ? $this->getService($this->getServiceName($methodName))->getMethod($methodName) : null; |
223
|
|
|
} |
224
|
|
|
/** |
225
|
|
|
* @return ServiceContainer |
226
|
|
|
*/ |
227
|
|
|
public function getServices() |
228
|
|
|
{ |
229
|
|
|
return $this->containers->getServices(); |
230
|
|
|
} |
231
|
|
|
/** |
232
|
|
|
* @return StructContainer |
233
|
|
|
*/ |
234
|
|
|
public function getStructs() |
235
|
|
|
{ |
236
|
|
|
return $this->containers->getStructs(); |
237
|
|
|
} |
238
|
|
|
/** |
239
|
|
|
* Sets the optionCategory value |
240
|
|
|
* @return string |
241
|
|
|
*/ |
242
|
|
|
public function getOptionCategory() |
243
|
|
|
{ |
244
|
|
|
return $this->options->getCategory(); |
245
|
|
|
} |
246
|
|
|
/** |
247
|
|
|
* Sets the optionCategory value |
248
|
|
|
* @param string $category |
249
|
|
|
* @return Generator |
250
|
|
|
*/ |
251
|
|
|
public function setOptionCategory($category) |
252
|
|
|
{ |
253
|
|
|
$this->options->setCategory($category); |
254
|
|
|
return $this; |
255
|
|
|
} |
256
|
|
|
/** |
257
|
|
|
* Sets the optionGatherMethods value |
258
|
|
|
* @return string |
259
|
|
|
*/ |
260
|
|
|
public function getOptionGatherMethods() |
261
|
|
|
{ |
262
|
|
|
return $this->options->getGatherMethods(); |
263
|
|
|
} |
264
|
|
|
/** |
265
|
|
|
* Sets the optionGatherMethods value |
266
|
|
|
* @param string $gatherMethods |
267
|
|
|
* @return Generator |
268
|
|
|
*/ |
269
|
|
|
public function setOptionGatherMethods($gatherMethods) |
270
|
|
|
{ |
271
|
|
|
$this->options->setGatherMethods($gatherMethods); |
272
|
|
|
return $this; |
273
|
|
|
} |
274
|
|
|
/** |
275
|
|
|
* Gets the optionGenericConstantsNames value |
276
|
|
|
* @return bool |
277
|
|
|
*/ |
278
|
|
|
public function getOptionGenericConstantsNames() |
279
|
|
|
{ |
280
|
|
|
return $this->options->getGenericConstantsName(); |
281
|
|
|
} |
282
|
|
|
/** |
283
|
|
|
* Sets the optionGenericConstantsNames value |
284
|
|
|
* @param bool $genericConstantsNames |
285
|
|
|
* @return Generator |
286
|
|
|
*/ |
287
|
|
|
public function setOptionGenericConstantsNames($genericConstantsNames) |
288
|
|
|
{ |
289
|
|
|
$this->options->setGenericConstantsName($genericConstantsNames); |
290
|
|
|
return $this; |
291
|
|
|
} |
292
|
|
|
/** |
293
|
|
|
* Gets the optionGenerateTutorialFile value |
294
|
|
|
* @return bool |
295
|
|
|
*/ |
296
|
|
|
public function getOptionGenerateTutorialFile() |
297
|
|
|
{ |
298
|
|
|
return $this->options->getGenerateTutorialFile(); |
299
|
|
|
} |
300
|
|
|
/** |
301
|
|
|
* Sets the optionGenerateTutorialFile value |
302
|
|
|
* @param bool $generateTutorialFile |
303
|
|
|
* @return Generator |
304
|
|
|
*/ |
305
|
|
|
public function setOptionGenerateTutorialFile($generateTutorialFile) |
306
|
|
|
{ |
307
|
|
|
$this->options->setGenerateTutorialFile($generateTutorialFile); |
308
|
|
|
return $this; |
309
|
|
|
} |
310
|
|
|
/** |
311
|
|
|
* Gets the optionNamespacePrefix value |
312
|
|
|
* @return string |
313
|
|
|
*/ |
314
|
|
|
public function getOptionNamespacePrefix() |
315
|
|
|
{ |
316
|
|
|
return $this->options->getNamespace(); |
317
|
|
|
} |
318
|
|
|
/** |
319
|
|
|
* Sets the optionGenerateTutorialFile value |
320
|
|
|
* @param string $namespace |
321
|
|
|
* @return Generator |
322
|
|
|
*/ |
323
|
|
|
public function setOptionNamespacePrefix($namespace) |
324
|
|
|
{ |
325
|
|
|
$this->options->setNamespace($namespace); |
326
|
|
|
return $this; |
327
|
|
|
} |
328
|
|
|
/** |
329
|
|
|
* Gets the optionAddComments value |
330
|
|
|
* @return array |
331
|
|
|
*/ |
332
|
|
|
public function getOptionAddComments() |
333
|
|
|
{ |
334
|
|
|
return $this->options->getAddComments(); |
335
|
|
|
} |
336
|
|
|
/** |
337
|
|
|
* Sets the optionAddComments value |
338
|
|
|
* @param array $addComments |
339
|
|
|
* @return Generator |
340
|
|
|
*/ |
341
|
|
|
public function setOptionAddComments($addComments) |
342
|
|
|
{ |
343
|
|
|
$this->options->setAddComments($addComments); |
344
|
|
|
return $this; |
345
|
|
|
} |
346
|
|
|
/** |
347
|
|
|
* Gets the optionStandalone value |
348
|
|
|
* @return bool |
349
|
|
|
*/ |
350
|
|
|
public function getOptionStandalone() |
351
|
|
|
{ |
352
|
|
|
return $this->options->getStandalone(); |
353
|
|
|
} |
354
|
|
|
/** |
355
|
|
|
* Sets the optionStandalone value |
356
|
|
|
* @param bool $standalone |
357
|
|
|
* @return Generator |
358
|
|
|
*/ |
359
|
|
|
public function setOptionStandalone($standalone) |
360
|
|
|
{ |
361
|
|
|
$this->options->setStandalone($standalone); |
362
|
|
|
return $this; |
363
|
|
|
} |
364
|
|
|
/** |
365
|
|
|
* Gets the optionValidation value |
366
|
|
|
* @return bool |
367
|
|
|
*/ |
368
|
|
|
public function getOptionValidation() |
369
|
|
|
{ |
370
|
|
|
return $this->options->getValidation(); |
371
|
|
|
} |
372
|
|
|
/** |
373
|
|
|
* Sets the optionValidation value |
374
|
|
|
* @param bool $validation |
375
|
|
|
* @return Generator |
376
|
|
|
*/ |
377
|
|
|
public function setOptionValidation($validation) |
378
|
|
|
{ |
379
|
|
|
$this->options->setValidation($validation); |
380
|
|
|
return $this; |
381
|
|
|
} |
382
|
|
|
/** |
383
|
|
|
* Gets the optionStructClass value |
384
|
|
|
* @return string |
385
|
|
|
*/ |
386
|
|
|
public function getOptionStructClass() |
387
|
|
|
{ |
388
|
|
|
return $this->options->getStructClass(); |
389
|
|
|
} |
390
|
|
|
/** |
391
|
|
|
* Sets the optionStructClass value |
392
|
|
|
* @param string $structClass |
393
|
|
|
* @return Generator |
394
|
|
|
*/ |
395
|
|
|
public function setOptionStructClass($structClass) |
396
|
|
|
{ |
397
|
|
|
$this->options->setStructClass($structClass); |
398
|
|
|
return $this; |
399
|
|
|
} |
400
|
|
|
/** |
401
|
|
|
* Gets the optionStructArrayClass value |
402
|
|
|
* @return string |
403
|
|
|
*/ |
404
|
|
|
public function getOptionStructArrayClass() |
405
|
|
|
{ |
406
|
|
|
return $this->options->getStructArrayClass(); |
407
|
|
|
} |
408
|
|
|
/** |
409
|
|
|
* Sets the optionStructArrayClass value |
410
|
|
|
* @param string $structArrayClass |
411
|
|
|
* @return Generator |
412
|
|
|
*/ |
413
|
|
|
public function setOptionStructArrayClass($structArrayClass) |
414
|
|
|
{ |
415
|
|
|
$this->options->setStructArrayClass($structArrayClass); |
416
|
|
|
return $this; |
417
|
|
|
} |
418
|
|
|
/** |
419
|
|
|
* Gets the optionSoapClientClass value |
420
|
|
|
* @return string |
421
|
|
|
*/ |
422
|
|
|
public function getOptionSoapClientClass() |
423
|
|
|
{ |
424
|
|
|
return $this->options->getSoapClientClass(); |
425
|
|
|
} |
426
|
|
|
/** |
427
|
|
|
* Sets the optionSoapClientClass value |
428
|
|
|
* @param string $soapClientClass |
429
|
|
|
* @return Generator |
430
|
|
|
*/ |
431
|
|
|
public function setOptionSoapClientClass($soapClientClass) |
432
|
|
|
{ |
433
|
|
|
$this->options->setSoapClientClass($soapClientClass); |
434
|
|
|
return $this; |
435
|
|
|
} |
436
|
|
|
/** |
437
|
|
|
* Gets the package name prefix |
438
|
|
|
* @param bool $ucFirst ucfirst package name prefix or not |
439
|
|
|
* @return string |
440
|
|
|
*/ |
441
|
|
|
public function getOptionPrefix($ucFirst = true) |
442
|
|
|
{ |
443
|
|
|
return $ucFirst ? ucfirst($this->getOptions()->getPrefix()) : $this->getOptions()->getPrefix(); |
444
|
|
|
} |
445
|
|
|
/** |
446
|
|
|
* Sets the package name prefix |
447
|
|
|
* @param string $optionPrefix |
448
|
|
|
* @return Generator |
449
|
|
|
*/ |
450
|
|
|
public function setOptionPrefix($optionPrefix) |
451
|
|
|
{ |
452
|
|
|
$this->options->setPrefix($optionPrefix); |
453
|
|
|
return $this; |
454
|
|
|
} |
455
|
|
|
/** |
456
|
|
|
* Gets the package name suffix |
457
|
|
|
* @param bool $ucFirst ucfirst package name suffix or not |
458
|
|
|
* @return string |
459
|
|
|
*/ |
460
|
|
|
public function getOptionSuffix($ucFirst = true) |
461
|
|
|
{ |
462
|
|
|
return $ucFirst ? ucfirst($this->getOptions()->getSuffix()) : $this->getOptions()->getSuffix(); |
463
|
|
|
} |
464
|
|
|
/** |
465
|
|
|
* Sets the package name suffix |
466
|
|
|
* @param string $optionSuffix |
467
|
|
|
* @return Generator |
468
|
|
|
*/ |
469
|
|
|
public function setOptionSuffix($optionSuffix) |
470
|
|
|
{ |
471
|
|
|
$this->options->setSuffix($optionSuffix); |
472
|
|
|
return $this; |
473
|
|
|
} |
474
|
|
|
/** |
475
|
|
|
* Gets the optionBasicLogin value |
476
|
|
|
* @return string |
477
|
|
|
*/ |
478
|
|
|
public function getOptionBasicLogin() |
479
|
|
|
{ |
480
|
|
|
return $this->options->getBasicLogin(); |
481
|
|
|
} |
482
|
|
|
/** |
483
|
|
|
* Sets the optionBasicLogin value |
484
|
|
|
* @param string $optionBasicLogin |
485
|
|
|
* @return Generator |
486
|
|
|
*/ |
487
|
|
|
public function setOptionBasicLogin($optionBasicLogin) |
488
|
|
|
{ |
489
|
|
|
$this->options->setBasicLogin($optionBasicLogin); |
490
|
|
|
return $this; |
491
|
|
|
} |
492
|
|
|
/** |
493
|
|
|
* Gets the optionBasicPassword value |
494
|
|
|
* @return string |
495
|
|
|
*/ |
496
|
|
|
public function getOptionBasicPassword() |
497
|
|
|
{ |
498
|
|
|
return $this->options->getBasicPassword(); |
499
|
|
|
} |
500
|
|
|
/** |
501
|
|
|
* Sets the optionBasicPassword value |
502
|
|
|
* @param string $optionBasicPassword |
503
|
|
|
* @return Generator |
504
|
|
|
*/ |
505
|
|
|
public function setOptionBasicPassword($optionBasicPassword) |
506
|
|
|
{ |
507
|
|
|
$this->options->setBasicPassword($optionBasicPassword); |
508
|
|
|
return $this; |
509
|
|
|
} |
510
|
|
|
/** |
511
|
|
|
* Gets the optionProxyHost value |
512
|
|
|
* @return string |
513
|
|
|
*/ |
514
|
|
|
public function getOptionProxyHost() |
515
|
|
|
{ |
516
|
|
|
return $this->options->getProxyHost(); |
517
|
|
|
} |
518
|
|
|
/** |
519
|
|
|
* Sets the optionProxyHost value |
520
|
|
|
* @param string $optionProxyHost |
521
|
|
|
* @return Generator |
522
|
|
|
*/ |
523
|
|
|
public function setOptionProxyHost($optionProxyHost) |
524
|
|
|
{ |
525
|
|
|
$this->options->setProxyHost($optionProxyHost); |
526
|
|
|
return $this; |
527
|
|
|
} |
528
|
|
|
/** |
529
|
|
|
* Gets the optionProxyPort value |
530
|
|
|
* @return string |
531
|
|
|
*/ |
532
|
|
|
public function getOptionProxyPort() |
533
|
|
|
{ |
534
|
|
|
return $this->options->getProxyPort(); |
535
|
|
|
} |
536
|
|
|
/** |
537
|
|
|
* Sets the optionProxyPort value |
538
|
|
|
* @param string $optionProxyPort |
539
|
|
|
* @return Generator |
540
|
|
|
*/ |
541
|
|
|
public function setOptionProxyPort($optionProxyPort) |
542
|
|
|
{ |
543
|
|
|
$this->options->setProxyPort($optionProxyPort); |
544
|
|
|
return $this; |
545
|
|
|
} |
546
|
|
|
/** |
547
|
|
|
* Gets the optionProxyLogin value |
548
|
|
|
* @return string |
549
|
|
|
*/ |
550
|
|
|
public function getOptionProxyLogin() |
551
|
|
|
{ |
552
|
|
|
return $this->options->getProxyLogin(); |
553
|
|
|
} |
554
|
|
|
/** |
555
|
|
|
* Sets the optionProxyLogin value |
556
|
|
|
* @param string $optionProxyLogin |
557
|
|
|
* @return Generator |
558
|
|
|
*/ |
559
|
|
|
public function setOptionProxyLogin($optionProxyLogin) |
560
|
|
|
{ |
561
|
|
|
$this->options->setProxyLogin($optionProxyLogin); |
562
|
|
|
return $this; |
563
|
|
|
} |
564
|
|
|
/** |
565
|
|
|
* Gets the optionProxyPassword value |
566
|
|
|
* @return string |
567
|
|
|
*/ |
568
|
|
|
public function getOptionProxyPassword() |
569
|
|
|
{ |
570
|
|
|
return $this->options->getProxyPassword(); |
571
|
|
|
} |
572
|
|
|
/** |
573
|
|
|
* Sets the optionProxyPassword value |
574
|
|
|
* @param string $optionProxyPassword |
575
|
|
|
* @return Generator |
576
|
|
|
*/ |
577
|
|
|
public function setOptionProxyPassword($optionProxyPassword) |
578
|
|
|
{ |
579
|
|
|
$this->options->setProxyPassword($optionProxyPassword); |
580
|
|
|
return $this; |
581
|
|
|
} |
582
|
|
|
/** |
583
|
|
|
* Gets the optionOrigin value |
584
|
|
|
* @return string |
585
|
|
|
*/ |
586
|
|
|
public function getOptionOrigin() |
587
|
|
|
{ |
588
|
|
|
return $this->options->getOrigin(); |
589
|
|
|
} |
590
|
|
|
/** |
591
|
|
|
* Sets the optionOrigin value |
592
|
|
|
* @param string $optionOrigin |
593
|
|
|
* @return Generator |
594
|
|
|
*/ |
595
|
|
|
public function setOptionOrigin($optionOrigin) |
596
|
|
|
{ |
597
|
|
|
$this->options->setOrigin($optionOrigin); |
598
|
|
|
$this->initWsdl(); |
599
|
|
|
return $this; |
600
|
|
|
} |
601
|
|
|
/** |
602
|
|
|
* Gets the optionDestination value |
603
|
|
|
* @return string |
604
|
|
|
*/ |
605
|
|
|
public function getOptionDestination() |
606
|
|
|
{ |
607
|
|
|
$destination = $this->options->getDestination(); |
608
|
|
|
if (!empty($destination)) { |
609
|
|
|
$destination = rtrim($destination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
610
|
|
|
} |
611
|
|
|
return $destination; |
612
|
|
|
} |
613
|
|
|
/** |
614
|
|
|
* Sets the optionDestination value |
615
|
|
|
* @param string $optionDestination |
616
|
|
|
* @return Generator |
617
|
|
|
*/ |
618
|
|
|
public function setOptionDestination($optionDestination) |
619
|
|
|
{ |
620
|
|
|
if (!empty($optionDestination)) { |
621
|
|
|
$this->options->setDestination(rtrim($optionDestination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR); |
622
|
|
|
} else { |
623
|
|
|
throw new \InvalidArgumentException('Package\'s destination can\'t be empty', __LINE__); |
624
|
|
|
} |
625
|
|
|
return $this; |
626
|
|
|
} |
627
|
|
|
/** |
628
|
|
|
* Gets the optionSrcDiname value |
629
|
|
|
* @return string |
630
|
|
|
*/ |
631
|
|
|
public function getOptionSrcDirname() |
632
|
|
|
{ |
633
|
|
|
return $this->options->getSrcDirname(); |
634
|
|
|
} |
635
|
|
|
/** |
636
|
|
|
* Sets the optionSrcDirname value |
637
|
|
|
* @param string $optionSrcDirname |
638
|
|
|
* @return Generator |
639
|
|
|
*/ |
640
|
|
|
public function setOptionSrcDirname($optionSrcDirname) |
641
|
|
|
{ |
642
|
|
|
$this->options->setSrcDirname($optionSrcDirname); |
643
|
|
|
return $this; |
644
|
|
|
} |
645
|
|
|
/** |
646
|
|
|
* Gets the optionSoapOptions value |
647
|
|
|
* @return string |
648
|
|
|
*/ |
649
|
|
|
public function getOptionSoapOptions() |
650
|
|
|
{ |
651
|
|
|
return $this->options->getSoapOptions(); |
652
|
|
|
} |
653
|
|
|
/** |
654
|
|
|
* Sets the optionSoapOptions value |
655
|
|
|
* @param array $optionSoapOptions |
656
|
|
|
* @return Generator |
657
|
|
|
*/ |
658
|
|
|
public function setOptionSoapOptions($optionSoapOptions) |
659
|
|
|
{ |
660
|
|
|
$this->options->setSoapOptions($optionSoapOptions); |
661
|
|
|
if ($this->getSoapClient() instanceof GeneratorSoapClient) { |
662
|
|
|
$this->getSoapClient()->initSoapClient(); |
663
|
|
|
} |
664
|
|
|
return $this; |
665
|
|
|
} |
666
|
|
|
/** |
667
|
|
|
* Gets the optionComposerName value |
668
|
|
|
* @return string |
669
|
|
|
*/ |
670
|
|
|
public function getOptionComposerName() |
671
|
|
|
{ |
672
|
|
|
return $this->options->getComposerName(); |
673
|
|
|
} |
674
|
|
|
/** |
675
|
|
|
* Sets the optionComposerName value |
676
|
|
|
* @param string $optionComposerName |
677
|
|
|
* @return Generator |
678
|
|
|
*/ |
679
|
|
|
public function setOptionComposerName($optionComposerName) |
680
|
|
|
{ |
681
|
|
|
if (!empty($optionComposerName)) { |
682
|
|
|
$this->options->setComposerName($optionComposerName); |
683
|
|
|
} else { |
684
|
|
|
throw new \InvalidArgumentException('Package\'s composer name can\'t be empty', __LINE__); |
685
|
|
|
} |
686
|
|
|
return $this; |
687
|
|
|
} |
688
|
|
|
/** |
689
|
|
|
* Gets the optionComposerSettings value |
690
|
|
|
* @return array |
691
|
|
|
*/ |
692
|
|
|
public function getOptionComposerSettings() |
693
|
|
|
{ |
694
|
|
|
return $this->options->getComposerSettings(); |
695
|
|
|
} |
696
|
|
|
/** |
697
|
|
|
* Sets the optionComposerSettings value |
698
|
|
|
* @param array $optionComposerSettings |
699
|
|
|
* @return Generator |
700
|
|
|
*/ |
701
|
|
|
public function setOptionComposerSettings(array $optionComposerSettings = array()) |
702
|
|
|
{ |
703
|
|
|
$this->options->setComposerSettings($optionComposerSettings); |
704
|
|
|
return $this; |
705
|
|
|
} |
706
|
|
|
/** |
707
|
|
|
* Gets the optionStructsFolder value |
708
|
|
|
* @return string |
709
|
|
|
*/ |
710
|
|
|
public function getOptionStructsFolder() |
711
|
|
|
{ |
712
|
|
|
return $this->options->getStructsFolder(); |
713
|
|
|
} |
714
|
|
|
/** |
715
|
|
|
* Sets the optionStructsFolder value |
716
|
|
|
* @param string $optionStructsFolder |
717
|
|
|
* @return Generator |
718
|
|
|
*/ |
719
|
|
|
public function setOptionStructsFolder($optionStructsFolder) |
720
|
|
|
{ |
721
|
|
|
$this->options->setStructsFolder($optionStructsFolder); |
722
|
|
|
return $this; |
723
|
|
|
} |
724
|
|
|
/** |
725
|
|
|
* Gets the optionArraysFolder value |
726
|
|
|
* @return string |
727
|
|
|
*/ |
728
|
|
|
public function getOptionArraysFolder() |
729
|
|
|
{ |
730
|
|
|
return $this->options->getArraysFolder(); |
731
|
|
|
} |
732
|
|
|
/** |
733
|
|
|
* Sets the optionArraysFolder value |
734
|
|
|
* @param string $optionArraysFolder |
735
|
|
|
* @return Generator |
736
|
|
|
*/ |
737
|
|
|
public function setOptionArraysFolder($optionArraysFolder) |
738
|
|
|
{ |
739
|
|
|
$this->options->setArraysFolder($optionArraysFolder); |
740
|
|
|
return $this; |
741
|
|
|
} |
742
|
|
|
/** |
743
|
|
|
* Gets the optionEnumsFolder value |
744
|
|
|
* @return string |
745
|
|
|
*/ |
746
|
|
|
public function getOptionEnumsFolder() |
747
|
|
|
{ |
748
|
|
|
return $this->options->getEnumsFolder(); |
749
|
|
|
} |
750
|
|
|
/** |
751
|
|
|
* Sets the optionEnumsFolder value |
752
|
|
|
* @param string $optionEnumsFolder |
753
|
|
|
* @return Generator |
754
|
|
|
*/ |
755
|
|
|
public function setOptionEnumsFolder($optionEnumsFolder) |
756
|
|
|
{ |
757
|
|
|
$this->options->setEnumsFolder($optionEnumsFolder); |
758
|
|
|
return $this; |
759
|
|
|
} |
760
|
|
|
/** |
761
|
|
|
* Gets the optionServicesFolder value |
762
|
|
|
* @return string |
763
|
|
|
*/ |
764
|
|
|
public function getOptionServicesFolder() |
765
|
|
|
{ |
766
|
|
|
return $this->options->getServicesFolder(); |
767
|
|
|
} |
768
|
|
|
/** |
769
|
|
|
* Sets the optionServicesFolder value |
770
|
|
|
* @param string $optionServicesFolder |
771
|
|
|
* @return Generator |
772
|
|
|
*/ |
773
|
|
|
public function setOptionServicesFolder($optionServicesFolder) |
774
|
|
|
{ |
775
|
|
|
$this->options->setServicesFolder($optionServicesFolder); |
776
|
|
|
return $this; |
777
|
|
|
} |
778
|
|
|
/** |
779
|
|
|
* Gets the WSDL |
780
|
|
|
* @return Wsdl|null |
781
|
|
|
*/ |
782
|
|
|
public function getWsdl() |
783
|
|
|
{ |
784
|
|
|
return $this->wsdl; |
785
|
|
|
} |
786
|
|
|
/** |
787
|
|
|
* Sets the WSDLs |
788
|
|
|
* @param Wsdl $wsdl |
789
|
|
|
* @return Generator |
790
|
|
|
*/ |
791
|
|
|
protected function setWsdl(Wsdl $wsdl) |
792
|
|
|
{ |
793
|
|
|
$this->wsdl = $wsdl; |
794
|
|
|
return $this; |
795
|
|
|
} |
796
|
|
|
/** |
797
|
|
|
* Adds Wsdl location |
798
|
|
|
* @param Wsdl $wsdl |
799
|
|
|
* @param string $schemaLocation |
800
|
|
|
* @return Generator |
801
|
|
|
*/ |
802
|
|
|
public function addSchemaToWsdl(Wsdl $wsdl, $schemaLocation) |
803
|
|
|
{ |
804
|
|
|
if (!empty($schemaLocation) && $wsdl->getContent() instanceof WsdlDocument && $wsdl->getContent()->getExternalSchema($schemaLocation) === null) { |
805
|
|
|
$wsdl->getContent()->addExternalSchema(new Schema($wsdl->getGenerator(), $schemaLocation, $this->getUrlContent($schemaLocation))); |
806
|
|
|
} |
807
|
|
|
return $this; |
808
|
|
|
} |
809
|
|
|
/** |
810
|
|
|
* Gets gather name class |
811
|
|
|
* @param AbstractModel $model the model for which we generate the folder |
812
|
|
|
* @return string |
813
|
|
|
*/ |
814
|
|
|
private function getGather(AbstractModel $model) |
815
|
|
|
{ |
816
|
|
|
return Utils::getPart($this->getOptionGatherMethods(), $model->getCleanName()); |
817
|
|
|
} |
818
|
|
|
/** |
819
|
|
|
* Returns the service name associated to the method/operation name in order to gather them in one service class |
820
|
|
|
* @uses Generator::getGather() |
821
|
|
|
* @param string $methodName original operation/method name |
822
|
|
|
* @return string |
823
|
|
|
*/ |
824
|
|
|
public function getServiceName($methodName) |
825
|
|
|
{ |
826
|
|
|
return ucfirst($this->getOptionGatherMethods() === GeneratorOptions::VALUE_NONE ? Service::DEFAULT_SERVICE_CLASS_NAME : $this->getGather(new EmptyModel($this, $methodName))); |
827
|
|
|
} |
828
|
|
|
/** |
829
|
|
|
* @param GeneratorOptions $options |
830
|
|
|
* @return Generator |
831
|
|
|
*/ |
832
|
|
|
protected function setOptions(GeneratorOptions $options = null) |
833
|
|
|
{ |
834
|
|
|
$this->options = $options; |
835
|
|
|
return $this; |
836
|
|
|
} |
837
|
|
|
/** |
838
|
|
|
* @return GeneratorOptions |
839
|
|
|
*/ |
840
|
|
|
public function getOptions() |
841
|
|
|
{ |
842
|
|
|
return $this->options; |
843
|
|
|
} |
844
|
|
|
/** |
845
|
|
|
* @return GeneratorSoapClient |
846
|
|
|
*/ |
847
|
|
|
public function getSoapClient() |
848
|
|
|
{ |
849
|
|
|
return $this->soapClient; |
850
|
|
|
} |
851
|
|
|
/** |
852
|
|
|
* @param string $url |
853
|
|
|
* @return string |
854
|
|
|
*/ |
855
|
|
|
public function getUrlContent($url) |
856
|
|
|
{ |
857
|
|
|
if (strpos($url, '://') !== false) { |
858
|
|
|
return Utils::getContentFromUrl($url, $this->getOptionBasicLogin(), $this->getOptionBasicPassword(), $this->getOptionProxyHost(), $this->getOptionProxyPort(), $this->getOptionProxyLogin(), $this->getOptionProxyPassword(), $this->getSoapClient()->getSoapClientStreamContextOptions()); |
859
|
|
|
} elseif (is_file($url)) { |
860
|
|
|
return file_get_contents($url); |
861
|
|
|
} |
862
|
|
|
return null; |
863
|
|
|
} |
864
|
|
|
/** |
865
|
|
|
* @return GeneratorContainers |
866
|
|
|
*/ |
867
|
|
|
public function getContainers() |
868
|
|
|
{ |
869
|
|
|
return $this->containers; |
870
|
|
|
} |
871
|
|
|
/** |
872
|
|
|
* @return array |
873
|
|
|
*/ |
874
|
|
|
public function jsonSerialize() |
875
|
|
|
{ |
876
|
|
|
return array( |
877
|
|
|
'containers' => $this->containers, |
878
|
|
|
'options' => $this->options, |
879
|
|
|
); |
880
|
|
|
} |
881
|
|
|
/** |
882
|
|
|
* @param string $json |
883
|
|
|
* @throws \InvalidArgumentException |
884
|
|
|
* @return Generator |
885
|
|
|
*/ |
886
|
|
|
public static function instanceFromSerializedJson($json) |
887
|
|
|
{ |
888
|
|
|
$decodedJson = json_decode($json, true); |
889
|
|
|
if (json_last_error() === JSON_ERROR_NONE) { |
890
|
|
|
// load options first |
891
|
|
|
$options = GeneratorOptions::instance(); |
892
|
|
|
foreach ($decodedJson['options']as $name => $value) { |
893
|
|
|
$options->setOptionValue($name, $value); |
894
|
|
|
} |
895
|
|
|
// create generator instance with options |
896
|
|
|
$instance = new static($options); |
897
|
|
|
// load services |
898
|
|
|
foreach ($decodedJson['containers']['services'] as $service) { |
899
|
|
|
$instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service)); |
900
|
|
|
} |
901
|
|
|
// load sructs |
902
|
|
|
foreach ($decodedJson['containers']['structs'] as $struct) { |
903
|
|
|
$instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct)); |
904
|
|
|
} |
905
|
|
|
} else { |
906
|
|
|
throw new \InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error())); |
907
|
|
|
} |
908
|
|
|
return $instance; |
909
|
|
|
} |
910
|
|
|
/** |
911
|
|
|
* @param Generator $generator |
912
|
|
|
* @param array $jsonArrayEntry |
913
|
|
|
* @return AbstractModel |
914
|
|
|
*/ |
915
|
|
|
private static function getModelInstanceFromJsonArrayEntry(Generator $generator, array $jsonArrayEntry) |
916
|
|
|
{ |
917
|
|
|
return AbstractModel::instanceFromSerializedJson($generator, $jsonArrayEntry); |
918
|
|
|
} |
919
|
|
|
} |
920
|
|
|
|