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