Completed
Push — master ( ab3100...ab2db9 )
by Mikaël
57:47 queued 20:08
created

Generator::getStructByName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

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