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