Total Complexity | 130 |
Total Lines | 1002 |
Duplicated Lines | 0 % |
Changes | 8 | ||
Bugs | 0 | Features | 0 |
Complex classes like Generator often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Generator, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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 | 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() |
||
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() |
||
192 | } |
||
193 | /** |
||
194 | * Gets the struct by its name |
||
195 | * Starting from issue #157, we know call getVirtual secondly as structs are now betterly parsed and so is their inheritance/type is detected |
||
196 | * @uses Generator::getStructs() |
||
197 | * @param string $structName the original struct name |
||
198 | * @return Struct|null |
||
199 | */ |
||
200 | public function getStructByName($structName) |
||
201 | { |
||
202 | $struct = $this->getStructs()->getStructByName($structName); |
||
203 | return $struct ? $struct : $this->getStructs()->getVirtual($structName); |
||
204 | } |
||
205 | /** |
||
206 | * Gets the struct by its name and type |
||
207 | * @uses Generator::getStructs() |
||
208 | * @param string $structName the original struct name |
||
209 | * @param string $type the original struct type |
||
210 | * @return Struct|null |
||
211 | */ |
||
212 | public function getStructByNameAndType($structName, $type) |
||
213 | { |
||
214 | return $this->getStructs()->getStructByNameAndType($structName, $type); |
||
215 | } |
||
216 | /** |
||
217 | * Gets a service by its name |
||
218 | * @param string $serviceName the service name |
||
219 | * @return Service|null |
||
220 | */ |
||
221 | public function getService($serviceName) |
||
222 | { |
||
223 | return $this->getServices()->getServiceByName($serviceName); |
||
224 | } |
||
225 | /** |
||
226 | * Returns the method |
||
227 | * @uses Generator::getServiceName() |
||
228 | * @uses Generator::getService() |
||
229 | * @uses Service::getMethod() |
||
230 | * @param string $methodName the original function name |
||
231 | * @return Method|null |
||
232 | */ |
||
233 | public function getServiceMethod($methodName) |
||
234 | { |
||
235 | return $this->getService($this->getServiceName($methodName)) instanceof Service ? $this->getService($this->getServiceName($methodName))->getMethod($methodName) : null; |
||
236 | } |
||
237 | /** |
||
238 | * @param bool $usingGatherMethods allows to gather methods within a single service if gather_methods options is set to true |
||
239 | * @return ServiceContainer |
||
240 | */ |
||
241 | public function getServices($usingGatherMethods = false) |
||
242 | { |
||
243 | $services = $this->containers->getServices(); |
||
244 | if ($usingGatherMethods && GeneratorOptions::VALUE_NONE === $this->getOptionGatherMethods()) { |
||
245 | $serviceContainer = new ServiceContainer($this); |
||
246 | $serviceModel = new Service($this, Service::DEFAULT_SERVICE_CLASS_NAME); |
||
247 | foreach ($services as $service) { |
||
248 | foreach ($service->getMethods() as $method) { |
||
249 | $serviceModel->getMethods()->add($method); |
||
250 | } |
||
251 | } |
||
252 | $serviceContainer->add($serviceModel); |
||
253 | $services = $serviceContainer; |
||
254 | } |
||
255 | return $services; |
||
256 | } |
||
257 | /** |
||
258 | * @return StructContainer |
||
259 | */ |
||
260 | public function getStructs() |
||
261 | { |
||
262 | return $this->containers->getStructs(); |
||
263 | } |
||
264 | /** |
||
265 | * Sets the optionCategory value |
||
266 | * @return string |
||
267 | */ |
||
268 | public function getOptionCategory() |
||
269 | { |
||
270 | return $this->options->getCategory(); |
||
271 | } |
||
272 | /** |
||
273 | * Sets the optionCategory value |
||
274 | * @param string $category |
||
275 | * @return Generator |
||
276 | */ |
||
277 | public function setOptionCategory($category) |
||
278 | { |
||
279 | $this->options->setCategory($category); |
||
280 | return $this; |
||
281 | } |
||
282 | /** |
||
283 | * Sets the optionGatherMethods value |
||
284 | * @return string |
||
285 | */ |
||
286 | public function getOptionGatherMethods() |
||
287 | { |
||
288 | return $this->options->getGatherMethods(); |
||
289 | } |
||
290 | /** |
||
291 | * Sets the optionGatherMethods value |
||
292 | * @param string $gatherMethods |
||
293 | * @return Generator |
||
294 | */ |
||
295 | public function setOptionGatherMethods($gatherMethods) |
||
296 | { |
||
297 | $this->options->setGatherMethods($gatherMethods); |
||
298 | return $this; |
||
299 | } |
||
300 | /** |
||
301 | * Gets the optionGenericConstantsNames value |
||
302 | * @return bool |
||
303 | */ |
||
304 | public function getOptionGenericConstantsNames() |
||
305 | { |
||
306 | return $this->options->getGenericConstantsName(); |
||
307 | } |
||
308 | /** |
||
309 | * Sets the optionGenericConstantsNames value |
||
310 | * @param bool $genericConstantsNames |
||
311 | * @return Generator |
||
312 | */ |
||
313 | public function setOptionGenericConstantsNames($genericConstantsNames) |
||
314 | { |
||
315 | $this->options->setGenericConstantsName($genericConstantsNames); |
||
316 | return $this; |
||
317 | } |
||
318 | /** |
||
319 | * Gets the optionGenerateTutorialFile value |
||
320 | * @return bool |
||
321 | */ |
||
322 | public function getOptionGenerateTutorialFile() |
||
325 | } |
||
326 | /** |
||
327 | * Sets the optionGenerateTutorialFile value |
||
328 | * @param bool $generateTutorialFile |
||
329 | * @return Generator |
||
330 | */ |
||
331 | public function setOptionGenerateTutorialFile($generateTutorialFile) |
||
335 | } |
||
336 | /** |
||
337 | * Gets the optionNamespacePrefix value |
||
338 | * @return string |
||
339 | */ |
||
340 | public function getOptionNamespacePrefix() |
||
341 | { |
||
342 | return $this->options->getNamespace(); |
||
343 | } |
||
344 | /** |
||
345 | * Sets the optionGenerateTutorialFile value |
||
346 | * @param string $namespace |
||
347 | * @return Generator |
||
348 | */ |
||
349 | public function setOptionNamespacePrefix($namespace) |
||
350 | { |
||
351 | $this->options->setNamespace($namespace); |
||
352 | return $this; |
||
353 | } |
||
354 | /** |
||
355 | * Gets the optionAddComments value |
||
356 | * @return array |
||
357 | */ |
||
358 | public function getOptionAddComments() |
||
359 | { |
||
360 | return $this->options->getAddComments(); |
||
361 | } |
||
362 | /** |
||
363 | * Sets the optionAddComments value |
||
364 | * @param array $addComments |
||
365 | * @return Generator |
||
366 | */ |
||
367 | public function setOptionAddComments($addComments) |
||
368 | { |
||
369 | $this->options->setAddComments($addComments); |
||
370 | return $this; |
||
371 | } |
||
372 | /** |
||
373 | * Gets the optionStandalone value |
||
374 | * @return bool |
||
375 | */ |
||
376 | public function getOptionStandalone() |
||
377 | { |
||
378 | return $this->options->getStandalone(); |
||
379 | } |
||
380 | /** |
||
381 | * Sets the optionStandalone value |
||
382 | * @param bool $standalone |
||
383 | * @return Generator |
||
384 | */ |
||
385 | public function setOptionStandalone($standalone) |
||
389 | } |
||
390 | /** |
||
391 | * Gets the optionValidation value |
||
392 | * @return bool |
||
393 | */ |
||
394 | public function getOptionValidation() |
||
395 | { |
||
396 | return $this->options->getValidation(); |
||
397 | } |
||
398 | /** |
||
399 | * Sets the optionValidation value |
||
400 | * @param bool $validation |
||
401 | * @return Generator |
||
402 | */ |
||
403 | public function setOptionValidation($validation) |
||
404 | { |
||
405 | $this->options->setValidation($validation); |
||
406 | return $this; |
||
407 | } |
||
408 | /** |
||
409 | * Gets the optionStructClass value |
||
410 | * @return string |
||
411 | */ |
||
412 | public function getOptionStructClass() |
||
415 | } |
||
416 | /** |
||
417 | * Sets the optionStructClass value |
||
418 | * @param string $structClass |
||
419 | * @return Generator |
||
420 | */ |
||
421 | public function setOptionStructClass($structClass) |
||
422 | { |
||
423 | $this->options->setStructClass($structClass); |
||
424 | return $this; |
||
425 | } |
||
426 | /** |
||
427 | * Gets the optionStructArrayClass value |
||
428 | * @return string |
||
429 | */ |
||
430 | public function getOptionStructArrayClass() |
||
433 | } |
||
434 | /** |
||
435 | * Sets the optionStructArrayClass value |
||
436 | * @param string $structArrayClass |
||
437 | * @return Generator |
||
438 | */ |
||
439 | public function setOptionStructArrayClass($structArrayClass) |
||
440 | { |
||
441 | $this->options->setStructArrayClass($structArrayClass); |
||
442 | return $this; |
||
443 | } |
||
444 | /** |
||
445 | * Gets the optionStructEnumClass value |
||
446 | * @return string |
||
447 | */ |
||
448 | public function getOptionStructEnumClass() |
||
449 | { |
||
450 | return $this->options->getStructEnumClass(); |
||
451 | } |
||
452 | /** |
||
453 | * Sets the optionStructEnumClass value |
||
454 | * @param string $structEnumClass |
||
455 | * @return Generator |
||
456 | */ |
||
457 | public function setOptionStructEnumClass($structEnumClass) |
||
458 | { |
||
459 | $this->options->setStructEnumClass($structEnumClass); |
||
460 | return $this; |
||
461 | } |
||
462 | /** |
||
463 | * Gets the optionSoapClientClass value |
||
464 | * @return string |
||
465 | */ |
||
466 | public function getOptionSoapClientClass() |
||
467 | { |
||
468 | return $this->options->getSoapClientClass(); |
||
469 | } |
||
470 | /** |
||
471 | * Sets the optionSoapClientClass value |
||
472 | * @param string $soapClientClass |
||
473 | * @return Generator |
||
474 | */ |
||
475 | public function setOptionSoapClientClass($soapClientClass) |
||
476 | { |
||
477 | $this->options->setSoapClientClass($soapClientClass); |
||
478 | return $this; |
||
479 | } |
||
480 | /** |
||
481 | * Gets the package name prefix |
||
482 | * @param bool $ucFirst ucfirst package name prefix or not |
||
483 | * @return string |
||
484 | */ |
||
485 | public function getOptionPrefix($ucFirst = true) |
||
486 | { |
||
487 | return $ucFirst ? ucfirst($this->getOptions()->getPrefix()) : $this->getOptions()->getPrefix(); |
||
488 | } |
||
489 | /** |
||
490 | * Sets the package name prefix |
||
491 | * @param string $optionPrefix |
||
492 | * @return Generator |
||
493 | */ |
||
494 | public function setOptionPrefix($optionPrefix) |
||
495 | { |
||
496 | $this->options->setPrefix($optionPrefix); |
||
497 | return $this; |
||
498 | } |
||
499 | /** |
||
500 | * Gets the package name suffix |
||
501 | * @param bool $ucFirst ucfirst package name suffix or not |
||
502 | * @return string |
||
503 | */ |
||
504 | public function getOptionSuffix($ucFirst = true) |
||
505 | { |
||
506 | return $ucFirst ? ucfirst($this->getOptions()->getSuffix()) : $this->getOptions()->getSuffix(); |
||
507 | } |
||
508 | /** |
||
509 | * Sets the package name suffix |
||
510 | * @param string $optionSuffix |
||
511 | * @return Generator |
||
512 | */ |
||
513 | public function setOptionSuffix($optionSuffix) |
||
514 | { |
||
515 | $this->options->setSuffix($optionSuffix); |
||
516 | return $this; |
||
517 | } |
||
518 | /** |
||
519 | * Gets the optionBasicLogin value |
||
520 | * @return string |
||
521 | */ |
||
522 | public function getOptionBasicLogin() |
||
523 | { |
||
524 | return $this->options->getBasicLogin(); |
||
525 | } |
||
526 | /** |
||
527 | * Sets the optionBasicLogin value |
||
528 | * @param string $optionBasicLogin |
||
529 | * @return Generator |
||
530 | */ |
||
531 | public function setOptionBasicLogin($optionBasicLogin) |
||
532 | { |
||
533 | $this->options->setBasicLogin($optionBasicLogin); |
||
534 | return $this; |
||
535 | } |
||
536 | /** |
||
537 | * Gets the optionBasicPassword value |
||
538 | * @return string |
||
539 | */ |
||
540 | public function getOptionBasicPassword() |
||
541 | { |
||
542 | return $this->options->getBasicPassword(); |
||
543 | } |
||
544 | /** |
||
545 | * Sets the optionBasicPassword value |
||
546 | * @param string $optionBasicPassword |
||
547 | * @return Generator |
||
548 | */ |
||
549 | public function setOptionBasicPassword($optionBasicPassword) |
||
550 | { |
||
551 | $this->options->setBasicPassword($optionBasicPassword); |
||
552 | return $this; |
||
553 | } |
||
554 | /** |
||
555 | * Gets the optionProxyHost value |
||
556 | * @return string |
||
557 | */ |
||
558 | public function getOptionProxyHost() |
||
559 | { |
||
560 | return $this->options->getProxyHost(); |
||
561 | } |
||
562 | /** |
||
563 | * Sets the optionProxyHost value |
||
564 | * @param string $optionProxyHost |
||
565 | * @return Generator |
||
566 | */ |
||
567 | public function setOptionProxyHost($optionProxyHost) |
||
568 | { |
||
569 | $this->options->setProxyHost($optionProxyHost); |
||
570 | return $this; |
||
571 | } |
||
572 | /** |
||
573 | * Gets the optionProxyPort value |
||
574 | * @return string |
||
575 | */ |
||
576 | public function getOptionProxyPort() |
||
577 | { |
||
578 | return $this->options->getProxyPort(); |
||
579 | } |
||
580 | /** |
||
581 | * Sets the optionProxyPort value |
||
582 | * @param string $optionProxyPort |
||
583 | * @return Generator |
||
584 | */ |
||
585 | public function setOptionProxyPort($optionProxyPort) |
||
586 | { |
||
587 | $this->options->setProxyPort($optionProxyPort); |
||
588 | return $this; |
||
589 | } |
||
590 | /** |
||
591 | * Gets the optionProxyLogin value |
||
592 | * @return string |
||
593 | */ |
||
594 | public function getOptionProxyLogin() |
||
595 | { |
||
596 | return $this->options->getProxyLogin(); |
||
597 | } |
||
598 | /** |
||
599 | * Sets the optionProxyLogin value |
||
600 | * @param string $optionProxyLogin |
||
601 | * @return Generator |
||
602 | */ |
||
603 | public function setOptionProxyLogin($optionProxyLogin) |
||
604 | { |
||
605 | $this->options->setProxyLogin($optionProxyLogin); |
||
606 | return $this; |
||
607 | } |
||
608 | /** |
||
609 | * Gets the optionProxyPassword value |
||
610 | * @return string |
||
611 | */ |
||
612 | public function getOptionProxyPassword() |
||
613 | { |
||
614 | return $this->options->getProxyPassword(); |
||
615 | } |
||
616 | /** |
||
617 | * Sets the optionProxyPassword value |
||
618 | * @param string $optionProxyPassword |
||
619 | * @return Generator |
||
620 | */ |
||
621 | public function setOptionProxyPassword($optionProxyPassword) |
||
622 | { |
||
623 | $this->options->setProxyPassword($optionProxyPassword); |
||
624 | return $this; |
||
625 | } |
||
626 | /** |
||
627 | * Gets the optionOrigin value |
||
628 | * @return string |
||
629 | */ |
||
630 | public function getOptionOrigin() |
||
631 | { |
||
632 | return $this->options->getOrigin(); |
||
633 | } |
||
634 | /** |
||
635 | * Sets the optionOrigin value |
||
636 | * @param string $optionOrigin |
||
637 | * @return Generator |
||
638 | */ |
||
639 | public function setOptionOrigin($optionOrigin) |
||
640 | { |
||
641 | $this->options->setOrigin($optionOrigin); |
||
642 | $this->initWsdl(); |
||
643 | return $this; |
||
644 | } |
||
645 | /** |
||
646 | * Gets the optionDestination value |
||
647 | * @return string |
||
648 | */ |
||
649 | public function getOptionDestination() |
||
650 | { |
||
651 | $destination = $this->options->getDestination(); |
||
652 | if (!empty($destination)) { |
||
653 | $destination = rtrim($destination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
||
654 | } |
||
655 | return $destination; |
||
656 | } |
||
657 | /** |
||
658 | * Sets the optionDestination value |
||
659 | * @param string $optionDestination |
||
660 | * @return Generator |
||
661 | */ |
||
662 | public function setOptionDestination($optionDestination) |
||
663 | { |
||
664 | if (!empty($optionDestination)) { |
||
665 | $this->options->setDestination(rtrim($optionDestination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR); |
||
666 | } else { |
||
667 | throw new \InvalidArgumentException('Package\'s destination can\'t be empty', __LINE__); |
||
668 | } |
||
669 | return $this; |
||
670 | } |
||
671 | /** |
||
672 | * Gets the optionSrcDirname value |
||
673 | * @return string |
||
674 | */ |
||
675 | public function getOptionSrcDirname() |
||
676 | { |
||
677 | return $this->options->getSrcDirname(); |
||
678 | } |
||
679 | /** |
||
680 | * Sets the optionSrcDirname value |
||
681 | * @param string $optionSrcDirname |
||
682 | * @return Generator |
||
683 | */ |
||
684 | public function setOptionSrcDirname($optionSrcDirname) |
||
685 | { |
||
686 | $this->options->setSrcDirname($optionSrcDirname); |
||
687 | return $this; |
||
688 | } |
||
689 | /** |
||
690 | * Gets the optionSoapOptions value |
||
691 | * @return array |
||
692 | */ |
||
693 | public function getOptionSoapOptions() |
||
694 | { |
||
695 | return $this->options->getSoapOptions(); |
||
696 | } |
||
697 | /** |
||
698 | * Sets the optionSoapOptions value |
||
699 | * @param array $optionSoapOptions |
||
700 | * @return Generator |
||
701 | */ |
||
702 | public function setOptionSoapOptions($optionSoapOptions) |
||
703 | { |
||
704 | $this->options->setSoapOptions($optionSoapOptions); |
||
705 | if ($this->soapClient) { |
||
706 | $this->soapClient->initSoapClient(); |
||
707 | } |
||
708 | return $this; |
||
709 | } |
||
710 | /** |
||
711 | * Gets the optionComposerName value |
||
712 | * @return string |
||
713 | */ |
||
714 | public function getOptionComposerName() |
||
715 | { |
||
716 | return $this->options->getComposerName(); |
||
717 | } |
||
718 | /** |
||
719 | * Sets the optionComposerName value |
||
720 | * @param string $optionComposerName |
||
721 | * @return Generator |
||
722 | */ |
||
723 | public function setOptionComposerName($optionComposerName) |
||
724 | { |
||
725 | if (!empty($optionComposerName)) { |
||
726 | $this->options->setComposerName($optionComposerName); |
||
727 | } else { |
||
728 | throw new \InvalidArgumentException('Package\'s composer name can\'t be empty', __LINE__); |
||
729 | } |
||
730 | return $this; |
||
731 | } |
||
732 | /** |
||
733 | * Gets the optionComposerSettings value |
||
734 | * @return array |
||
735 | */ |
||
736 | public function getOptionComposerSettings() |
||
737 | { |
||
738 | return $this->options->getComposerSettings(); |
||
739 | } |
||
740 | /** |
||
741 | * Sets the optionComposerSettings value |
||
742 | * @param array $optionComposerSettings |
||
743 | * @return Generator |
||
744 | */ |
||
745 | public function setOptionComposerSettings(array $optionComposerSettings = []) |
||
746 | { |
||
747 | $this->options->setComposerSettings($optionComposerSettings); |
||
748 | return $this; |
||
749 | } |
||
750 | /** |
||
751 | * Gets the optionStructsFolder value |
||
752 | * @return string |
||
753 | */ |
||
754 | public function getOptionStructsFolder() |
||
757 | } |
||
758 | /** |
||
759 | * Sets the optionStructsFolder value |
||
760 | * @param string $optionStructsFolder |
||
761 | * @return Generator |
||
762 | */ |
||
763 | public function setOptionStructsFolder($optionStructsFolder) |
||
764 | { |
||
765 | $this->options->setStructsFolder($optionStructsFolder); |
||
766 | return $this; |
||
767 | } |
||
768 | /** |
||
769 | * Gets the optionArraysFolder value |
||
770 | * @return string |
||
771 | */ |
||
772 | public function getOptionArraysFolder() |
||
775 | } |
||
776 | /** |
||
777 | * Sets the optionArraysFolder value |
||
778 | * @param string $optionArraysFolder |
||
779 | * @return Generator |
||
780 | */ |
||
781 | public function setOptionArraysFolder($optionArraysFolder) |
||
782 | { |
||
783 | $this->options->setArraysFolder($optionArraysFolder); |
||
784 | return $this; |
||
785 | } |
||
786 | /** |
||
787 | * Gets the optionEnumsFolder value |
||
788 | * @return string |
||
789 | */ |
||
790 | public function getOptionEnumsFolder() |
||
791 | { |
||
792 | return $this->options->getEnumsFolder(); |
||
793 | } |
||
794 | /** |
||
795 | * Sets the optionEnumsFolder value |
||
796 | * @param string $optionEnumsFolder |
||
797 | * @return Generator |
||
798 | */ |
||
799 | public function setOptionEnumsFolder($optionEnumsFolder) |
||
800 | { |
||
801 | $this->options->setEnumsFolder($optionEnumsFolder); |
||
802 | return $this; |
||
803 | } |
||
804 | /** |
||
805 | * Gets the optionServicesFolder value |
||
806 | * @return string |
||
807 | */ |
||
808 | public function getOptionServicesFolder() |
||
809 | { |
||
810 | return $this->options->getServicesFolder(); |
||
811 | } |
||
812 | /** |
||
813 | * Sets the optionServicesFolder value |
||
814 | * @param string $optionServicesFolder |
||
815 | * @return Generator |
||
816 | */ |
||
817 | public function setOptionServicesFolder($optionServicesFolder) |
||
818 | { |
||
819 | $this->options->setServicesFolder($optionServicesFolder); |
||
820 | return $this; |
||
821 | } |
||
822 | /** |
||
823 | * Gets the optionSchemasSave value |
||
824 | * @return bool |
||
825 | */ |
||
826 | public function getOptionSchemasSave() |
||
827 | { |
||
828 | return $this->options->getSchemasSave(); |
||
829 | } |
||
830 | /** |
||
831 | * Sets the optionSchemasSave value |
||
832 | * @param bool $optionSchemasSave |
||
833 | * @return Generator |
||
834 | */ |
||
835 | public function setOptionSchemasSave($optionSchemasSave) |
||
836 | { |
||
837 | $this->options->setSchemasSave($optionSchemasSave); |
||
838 | return $this; |
||
839 | } |
||
840 | /** |
||
841 | * Gets the optionSchemasFolder value |
||
842 | * @return string |
||
843 | */ |
||
844 | public function getOptionSchemasFolder() |
||
845 | { |
||
846 | return $this->options->getSchemasFolder(); |
||
847 | } |
||
848 | /** |
||
849 | * Sets the optionSchemasFolder value |
||
850 | * @param string $optionSchemasFolder |
||
851 | * @return Generator |
||
852 | */ |
||
853 | public function setOptionSchemasFolder($optionSchemasFolder) |
||
854 | { |
||
855 | $this->options->setSchemasFolder($optionSchemasFolder); |
||
856 | return $this; |
||
857 | } |
||
858 | /** |
||
859 | * Gets the optionXsdTypesPath value |
||
860 | * @return string |
||
861 | */ |
||
862 | public function getOptionXsdTypesPath() |
||
863 | { |
||
864 | return $this->options->getXsdTypesPath(); |
||
865 | } |
||
866 | /** |
||
867 | * Sets the optionXsdTypesPath value |
||
868 | * @param string $xsdTypesPath |
||
869 | * @return Generator |
||
870 | */ |
||
871 | public function setOptionXsdTypesPath($xsdTypesPath) |
||
875 | } |
||
876 | /** |
||
877 | * Gets the WSDL |
||
878 | * @return Wsdl|null |
||
879 | */ |
||
880 | public function getWsdl() |
||
881 | { |
||
882 | return $this->wsdl; |
||
883 | } |
||
884 | /** |
||
885 | * Sets the WSDLs |
||
886 | * @param Wsdl $wsdl |
||
887 | * @return Generator |
||
888 | */ |
||
889 | protected function setWsdl(Wsdl $wsdl) |
||
890 | { |
||
891 | $this->wsdl = $wsdl; |
||
892 | return $this; |
||
893 | } |
||
894 | /** |
||
895 | * Adds Wsdl location |
||
896 | * @param Wsdl $wsdl |
||
897 | * @param string $schemaLocation |
||
898 | * @return Generator |
||
899 | */ |
||
900 | public function addSchemaToWsdl(Wsdl $wsdl, $schemaLocation) |
||
901 | { |
||
902 | if (!empty($schemaLocation) && $wsdl->getContent() instanceof WsdlDocument && $wsdl->getContent()->getExternalSchema($schemaLocation) === null) { |
||
903 | $wsdl->getContent()->addExternalSchema(new Schema($wsdl->getGenerator(), $schemaLocation, $this->getUrlContent($schemaLocation))); |
||
904 | } |
||
905 | return $this; |
||
906 | } |
||
907 | /** |
||
908 | * Gets gather name class |
||
909 | * @param AbstractModel $model the model for which we generate the folder |
||
910 | * @return string |
||
911 | */ |
||
912 | protected function getGather(AbstractModel $model) |
||
913 | { |
||
914 | return Utils::getPart($this->getOptionGatherMethods(), $model->getCleanName()); |
||
915 | } |
||
916 | /** |
||
917 | * Returns the service name associated to the method/operation name in order to gather them in one service class |
||
918 | * @param string $methodName original operation/method name |
||
919 | * @return string |
||
920 | */ |
||
921 | public function getServiceName($methodName) |
||
924 | } |
||
925 | /** |
||
926 | * @param GeneratorOptions $options |
||
927 | * @return Generator |
||
928 | */ |
||
929 | protected function setOptions(GeneratorOptions $options = null) |
||
930 | { |
||
931 | $this->options = $options; |
||
932 | return $this; |
||
933 | } |
||
934 | /** |
||
935 | * @return GeneratorOptions |
||
936 | */ |
||
937 | public function getOptions() |
||
938 | { |
||
939 | return $this->options; |
||
940 | } |
||
941 | /** |
||
942 | * @return GeneratorSoapClient |
||
943 | */ |
||
944 | public function getSoapClient() |
||
947 | } |
||
948 | /** |
||
949 | * @param string $url |
||
950 | * @return string |
||
951 | */ |
||
952 | public function getUrlContent($url) |
||
953 | { |
||
954 | if (mb_strpos($url, '://') !== false) { |
||
955 | $content = Utils::getContentFromUrl($url, $this->getOptionBasicLogin(), $this->getOptionBasicPassword(), $this->getOptionProxyHost(), $this->getOptionProxyPort(), $this->getOptionProxyLogin(), $this->getOptionProxyPassword(), $this->getSoapClient()->getSoapClientStreamContextOptions()); |
||
956 | if ($this->getOptionSchemasSave() === true) { |
||
957 | Utils::saveSchemas($this->getOptionDestination(), $this->getOptionSchemasFolder(), $url, $content); |
||
958 | } |
||
959 | return $content; |
||
960 | } elseif (is_file($url)) { |
||
961 | return file_get_contents($url); |
||
962 | } |
||
963 | return null; |
||
964 | } |
||
965 | /** |
||
966 | * @return GeneratorContainers |
||
967 | */ |
||
968 | public function getContainers() |
||
971 | } |
||
972 | /** |
||
973 | * @return array |
||
974 | */ |
||
975 | public function jsonSerialize() |
||
976 | { |
||
977 | return [ |
||
978 | 'containers' => $this->containers, |
||
979 | 'options' => $this->options, |
||
980 | ]; |
||
981 | } |
||
982 | /** |
||
983 | * @param string $json |
||
984 | * @throws \InvalidArgumentException |
||
985 | * @return Generator |
||
986 | */ |
||
987 | public static function instanceFromSerializedJson($json) |
||
988 | { |
||
989 | $decodedJson = json_decode($json, true); |
||
990 | if (json_last_error() === JSON_ERROR_NONE) { |
||
991 | // load options first |
||
992 | $options = GeneratorOptions::instance(); |
||
993 | foreach ($decodedJson['options'] as $name => $value) { |
||
994 | $options->setOptionValue($name, $value); |
||
995 | } |
||
996 | // create generator instance with options |
||
997 | $instance = new static($options); |
||
998 | // load services |
||
999 | foreach ($decodedJson['containers']['services'] as $service) { |
||
1000 | $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service)); |
||
1001 | } |
||
1002 | // load structs |
||
1003 | foreach ($decodedJson['containers']['structs'] as $struct) { |
||
1004 | $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct)); |
||
1005 | } |
||
1006 | } else { |
||
1007 | throw new \InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error())); |
||
1008 | } |
||
1009 | return $instance; |
||
1010 | } |
||
1011 | /** |
||
1012 | * @param Generator $generator |
||
1013 | * @param array $jsonArrayEntry |
||
1014 | * @return AbstractModel |
||
1015 | */ |
||
1016 | protected static function getModelInstanceFromJsonArrayEntry(Generator $generator, array $jsonArrayEntry) |
||
1019 | } |
||
1020 | } |
||
1021 |