Passed
Push — master ( ab6b67...a48167 )
by Mikaël
74:03 queued 50:14
created

Generator::setOptionValidation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
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 1038
    public function __construct(GeneratorOptions $options)
53
    {
54 1038
        $this->setOptions($options)->initialize();
55 1026
    }
56
    /**
57
     * @return Generator
58
     */
59 1038
    protected function initialize()
60
    {
61 1038
        return $this->initContainers()
62 1038
            ->initParsers()
63 1038
            ->initFiles()
64 1038
            ->initSoapClient()
65 1026
            ->initWsdl();
66
    }
67
    /**
68
     * @throws \InvalidArgumentException
69
     * @return Generator
70
     */
71 1038
    protected function initSoapClient()
72
    {
73 1038
        if (!isset($this->soapClient)) {
74 1038
            $this->soapClient = new GeneratorSoapClient($this);
75 513
        }
76 1026
        return $this;
77
    }
78
    /**
79
     * @return Generator
80
     */
81 1038
    protected function initContainers()
82
    {
83 1038
        if (!isset($this->containers)) {
84 1038
            $this->containers = new GeneratorContainers($this);
85 519
        }
86 1038
        return $this;
87
    }
88
    /**
89
     * @return Generator
90
     */
91 1038
    protected function initParsers()
92
    {
93 1038
        if (!isset($this->parsers)) {
94 1038
            $this->parsers = new GeneratorParsers($this);
95 519
        }
96 1038
        return $this;
97
    }
98
    /**
99
     * @return GeneratorParsers
100
     */
101 198
    public function getParsers()
102
    {
103 198
        return $this->parsers;
104
    }
105
    /**
106
     * @return Generator
107
     */
108 1038
    protected function initFiles()
109
    {
110 1038
        if (!isset($this->files)) {
111 1038
            $this->files = new GeneratorFiles($this);
112 519
        }
113 1038
        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 1032
    protected function initWsdl()
138
    {
139 1032
        $this->setWsdl(new Wsdl($this, $this->getOptionOrigin(), $this->getUrlContent($this->getOptionOrigin())));
140 1032
        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 1230
    public function getStructByName($structName)
201
    {
202 1230
        $struct = $this->getStructs()->getStructByName($structName);
203 1230
        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 468
    public function getStructByNameAndType($structName, $type)
213
    {
214 468
        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 522
    public function getServices($usingGatherMethods = false)
242
    {
243 522
        $services = $this->containers->getServices();
244 522
        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 522
        return $services;
256
    }
257
    /**
258
     * @return StructContainer
259
     */
260 1362
    public function getStructs()
261
    {
262 1362
        return $this->containers->getStructs();
263
    }
264
    /**
265
     * Sets the optionCategory value
266
     * @return string
267
     */
268 672
    public function getOptionCategory()
269
    {
270 672
        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 522
    public function getOptionGatherMethods()
287
    {
288 522
        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 144
    public function getOptionGenericConstantsNames()
305
    {
306 144
        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 636
    public function getOptionNamespacePrefix()
341
    {
342 636
        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 462
    public function getOptionAddComments()
359
    {
360 462
        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 306
    public function getOptionValidation()
395
    {
396 306
        return $this->options->getValidation();
397
    }
398
    /**
399
     * Sets the optionValidation value
400
     * @param bool $validation
401
     * @return Generator
402
     */
403 60
    public function setOptionValidation($validation)
404
    {
405 60
        $this->options->setValidation($validation);
406 60
        return $this;
407
    }
408
    /**
409
     * Gets the optionStructClass value
410
     * @return string
411
     */
412 282
    public function getOptionStructClass()
413
    {
414 282
        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 optionStructEnumClass value
446
     * @return string
447
     */
448 138
    public function getOptionStructEnumClass()
449
    {
450 138
        return $this->options->getStructEnumClass();
451
    }
452
    /**
453
     * Sets the optionStructEnumClass value
454
     * @param string $structEnumClass
455
     * @return Generator
456
     */
457 6
    public function setOptionStructEnumClass($structEnumClass)
458
    {
459 6
        $this->options->setStructEnumClass($structEnumClass);
460 6
        return $this;
461
    }
462
    /**
463
     * Gets the optionSoapClientClass value
464
     * @return string
465
     */
466 150
    public function getOptionSoapClientClass()
467
    {
468 150
        return $this->options->getSoapClientClass();
469
    }
470
    /**
471
     * Sets the optionSoapClientClass value
472
     * @param string $soapClientClass
473
     * @return Generator
474
     */
475 6
    public function setOptionSoapClientClass($soapClientClass)
476
    {
477 6
        $this->options->setSoapClientClass($soapClientClass);
478 6
        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 1188
    public function getOptionPrefix($ucFirst = true)
486
    {
487 1188
        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 126
    public function setOptionPrefix($optionPrefix)
495
    {
496 126
        $this->options->setPrefix($optionPrefix);
497 126
        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 1152
    public function getOptionSuffix($ucFirst = true)
505
    {
506 1152
        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 42
    public function setOptionSuffix($optionSuffix)
514
    {
515 42
        $this->options->setSuffix($optionSuffix);
516 42
        return $this;
517
    }
518
    /**
519
     * Gets the optionBasicLogin value
520
     * @return string
521
     */
522 1062
    public function getOptionBasicLogin()
523
    {
524 1062
        return $this->options->getBasicLogin();
525
    }
526
    /**
527
     * Sets the optionBasicLogin value
528
     * @param string $optionBasicLogin
529
     * @return Generator
530
     */
531 6
    public function setOptionBasicLogin($optionBasicLogin)
532
    {
533 6
        $this->options->setBasicLogin($optionBasicLogin);
534 6
        return $this;
535
    }
536
    /**
537
     * Gets the optionBasicPassword value
538
     * @return string
539
     */
540 1062
    public function getOptionBasicPassword()
541
    {
542 1062
        return $this->options->getBasicPassword();
543
    }
544
    /**
545
     * Sets the optionBasicPassword value
546
     * @param string $optionBasicPassword
547
     * @return Generator
548
     */
549 6
    public function setOptionBasicPassword($optionBasicPassword)
550
    {
551 6
        $this->options->setBasicPassword($optionBasicPassword);
552 6
        return $this;
553
    }
554
    /**
555
     * Gets the optionProxyHost value
556
     * @return string
557
     */
558 1062
    public function getOptionProxyHost()
559
    {
560 1062
        return $this->options->getProxyHost();
561
    }
562
    /**
563
     * Sets the optionProxyHost value
564
     * @param string $optionProxyHost
565
     * @return Generator
566
     */
567 6
    public function setOptionProxyHost($optionProxyHost)
568
    {
569 6
        $this->options->setProxyHost($optionProxyHost);
570 6
        return $this;
571
    }
572
    /**
573
     * Gets the optionProxyPort value
574
     * @return string
575
     */
576 1062
    public function getOptionProxyPort()
577 1
    {
578 1062
        return $this->options->getProxyPort();
579
    }
580
    /**
581
     * Sets the optionProxyPort value
582
     * @param string $optionProxyPort
583
     * @return Generator
584
     */
585 6
    public function setOptionProxyPort($optionProxyPort)
586
    {
587 6
        $this->options->setProxyPort($optionProxyPort);
588 6
        return $this;
589
    }
590
    /**
591
     * Gets the optionProxyLogin value
592
     * @return string
593
     */
594 1062
    public function getOptionProxyLogin()
595
    {
596 1062
        return $this->options->getProxyLogin();
597
    }
598
    /**
599
     * Sets the optionProxyLogin value
600
     * @param string $optionProxyLogin
601
     * @return Generator
602
     */
603 6
    public function setOptionProxyLogin($optionProxyLogin)
604
    {
605 6
        $this->options->setProxyLogin($optionProxyLogin);
606 6
        return $this;
607
    }
608
    /**
609
     * Gets the optionProxyPassword value
610
     * @return string
611
     */
612 1062
    public function getOptionProxyPassword()
613
    {
614 1062
        return $this->options->getProxyPassword();
615
    }
616
    /**
617
     * Sets the optionProxyPassword value
618
     * @param string $optionProxyPassword
619
     * @return Generator
620
     */
621 6
    public function setOptionProxyPassword($optionProxyPassword)
622
    {
623 6
        $this->options->setProxyPassword($optionProxyPassword);
624 6
        return $this;
625
    }
626
    /**
627
     * Gets the optionOrigin value
628
     * @return string
629
     */
630 1056
    public function getOptionOrigin()
631
    {
632 1056
        return $this->options->getOrigin();
633
    }
634
    /**
635
     * Sets the optionOrigin value
636
     * @param string $optionOrigin
637
     * @return Generator
638
     */
639 6
    public function setOptionOrigin($optionOrigin)
640
    {
641 6
        $this->options->setOrigin($optionOrigin);
642 6
        $this->initWsdl();
643 6
        return $this;
644
    }
645
    /**
646
     * Gets the optionDestination value
647
     * @return string
648
     */
649 630
    public function getOptionDestination()
650
    {
651 630
        $destination = $this->options->getDestination();
652 630
        if (!empty($destination)) {
653 624
            $destination = rtrim($destination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
654 312
        }
655 630
        return $destination;
656
    }
657
    /**
658
     * Sets the optionDestination value
659
     * @param string $optionDestination
660
     * @return Generator
661
     */
662 18
    public function setOptionDestination($optionDestination)
663
    {
664 18
        if (!empty($optionDestination)) {
665 12
            $this->options->setDestination(rtrim($optionDestination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
666 6
        } else {
667 6
            throw new \InvalidArgumentException('Package\'s destination can\'t be empty', __LINE__);
668
        }
669 12
        return $this;
670
    }
671
    /**
672
     * Gets the optionSrcDirname value
673
     * @return string
674
     */
675 552
    public function getOptionSrcDirname()
676
    {
677 552
        return $this->options->getSrcDirname();
678
    }
679
    /**
680
     * Sets the optionSrcDirname value
681
     * @param string $optionSrcDirname
682
     * @return Generator
683
     */
684 18
    public function setOptionSrcDirname($optionSrcDirname)
685
    {
686 18
        $this->options->setSrcDirname($optionSrcDirname);
687 18
        return $this;
688
    }
689
    /**
690
     * Gets the optionSoapOptions value
691
     * @return array
692
     */
693 1050
    public function getOptionSoapOptions()
694
    {
695 1050
        return $this->options->getSoapOptions();
696
    }
697
    /**
698
     * Sets the optionSoapOptions value
699
     * @param array $optionSoapOptions
700
     * @return Generator
701
     */
702 6
    public function setOptionSoapOptions($optionSoapOptions)
703
    {
704 6
        $this->options->setSoapOptions($optionSoapOptions);
705 6
        if ($this->soapClient) {
706 6
            $this->soapClient->initSoapClient();
707 3
        }
708 6
        return $this;
709
    }
710
    /**
711
     * Gets the optionComposerName value
712
     * @return string
713
     */
714 78
    public function getOptionComposerName()
715
    {
716 78
        return $this->options->getComposerName();
717
    }
718
    /**
719
     * Sets the optionComposerName value
720
     * @param string $optionComposerName
721
     * @return Generator
722
     */
723 42
    public function setOptionComposerName($optionComposerName)
724
    {
725 42
        if (!empty($optionComposerName)) {
726 36
            $this->options->setComposerName($optionComposerName);
727 18
        } else {
728 6
            throw new \InvalidArgumentException('Package\'s composer name can\'t be empty', __LINE__);
729
        }
730 36
        return $this;
731
    }
732
    /**
733
     * Gets the optionComposerSettings value
734
     * @return array
735
     */
736 60
    public function getOptionComposerSettings()
737
    {
738 60
        return $this->options->getComposerSettings();
739
    }
740
    /**
741
     * Sets the optionComposerSettings value
742
     * @param array $optionComposerSettings
743
     * @return Generator
744
     */
745 12
    public function setOptionComposerSettings(array $optionComposerSettings = [])
746
    {
747 12
        $this->options->setComposerSettings($optionComposerSettings);
748 12
        return $this;
749
    }
750
    /**
751
     * Gets the optionStructsFolder value
752
     * @return string
753
     */
754 636
    public function getOptionStructsFolder()
755
    {
756 636
        return $this->options->getStructsFolder();
757
    }
758
    /**
759
     * Sets the optionStructsFolder value
760
     * @param string $optionStructsFolder
761
     * @return Generator
762
     */
763 6
    public function setOptionStructsFolder($optionStructsFolder)
764
    {
765 6
        $this->options->setStructsFolder($optionStructsFolder);
766 6
        return $this;
767
    }
768
    /**
769
     * Gets the optionArraysFolder value
770
     * @return string
771
     */
772 96
    public function getOptionArraysFolder()
773
    {
774 96
        return $this->options->getArraysFolder();
775
    }
776
    /**
777
     * Sets the optionArraysFolder value
778
     * @param string $optionArraysFolder
779
     * @return Generator
780
     */
781 6
    public function setOptionArraysFolder($optionArraysFolder)
782
    {
783 6
        $this->options->setArraysFolder($optionArraysFolder);
784 6
        return $this;
785
    }
786
    /**
787
     * Gets the optionEnumsFolder value
788
     * @return string
789
     */
790 222
    public function getOptionEnumsFolder()
791
    {
792 222
        return $this->options->getEnumsFolder();
793
    }
794
    /**
795
     * Sets the optionEnumsFolder value
796
     * @param string $optionEnumsFolder
797
     * @return Generator
798
     */
799 6
    public function setOptionEnumsFolder($optionEnumsFolder)
800
    {
801 6
        $this->options->setEnumsFolder($optionEnumsFolder);
802 6
        return $this;
803
    }
804
    /**
805
     * Gets the optionServicesFolder value
806
     * @return string
807
     */
808 1002
    public function getOptionServicesFolder()
809
    {
810 1002
        return $this->options->getServicesFolder();
811
    }
812
    /**
813
     * Sets the optionServicesFolder value
814
     * @param string $optionServicesFolder
815
     * @return Generator
816
     */
817 6
    public function setOptionServicesFolder($optionServicesFolder)
818
    {
819 6
        $this->options->setServicesFolder($optionServicesFolder);
820 6
        return $this;
821
    }
822
    /**
823
     * Gets the optionSchemasSave value
824
     * @return bool
825
     */
826 18
    public function getOptionSchemasSave()
827
    {
828 18
        return $this->options->getSchemasSave();
829
    }
830
    /**
831
     * Sets the optionSchemasSave value
832
     * @param bool $optionSchemasSave
833
     * @return Generator
834
     */
835 12
    public function setOptionSchemasSave($optionSchemasSave)
836
    {
837 12
        $this->options->setSchemasSave($optionSchemasSave);
838 12
        return $this;
839
    }
840
    /**
841
     * Gets the optionSchemasFolder value
842
     * @return string
843
     */
844 12
    public function getOptionSchemasFolder()
845
    {
846 12
        return $this->options->getSchemasFolder();
847
    }
848
    /**
849
     * Sets the optionSchemasFolder value
850
     * @param string $optionSchemasFolder
851
     * @return Generator
852
     */
853 12
    public function setOptionSchemasFolder($optionSchemasFolder)
854
    {
855 12
        $this->options->setSchemasFolder($optionSchemasFolder);
856 12
        return $this;
857
    }
858
    /**
859
     * Gets the optionXsdTypesPath value
860
     * @return string
861
     */
862 336
    public function getOptionXsdTypesPath()
863
    {
864 336
        return $this->options->getXsdTypesPath();
865
    }
866
    /**
867
     * Sets the optionXsdTypesPath value
868
     * @param string $xsdTypesPath
869
     * @return Generator
870
     */
871 6
    public function setOptionXsdTypesPath($xsdTypesPath)
872
    {
873 6
        $this->options->setXsdTypesPath($xsdTypesPath);
874 6
        return $this;
875
    }
876
    /**
877
     * Gets the WSDL
878
     * @return Wsdl|null
879
     */
880 774
    public function getWsdl()
881
    {
882 774
        return $this->wsdl;
883
    }
884
    /**
885
     * Sets the WSDLs
886
     * @param Wsdl $wsdl
887
     * @return Generator
888
     */
889 1032
    protected function setWsdl(Wsdl $wsdl)
890
    {
891 1032
        $this->wsdl = $wsdl;
892 1032
        return $this;
893
    }
894
    /**
895
     * Adds Wsdl location
896
     * @param Wsdl $wsdl
897
     * @param string $schemaLocation
898
     * @return Generator
899
     */
900 198
    public function addSchemaToWsdl(Wsdl $wsdl, $schemaLocation)
901
    {
902 198
        if (!empty($schemaLocation) && $wsdl->getContent() instanceof WsdlDocument && $wsdl->getContent()->getExternalSchema($schemaLocation) === null) {
903 198
            $wsdl->getContent()->addExternalSchema(new Schema($wsdl->getGenerator(), $schemaLocation, $this->getUrlContent($schemaLocation)));
904 99
        }
905 198
        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 462
    protected function getGather(AbstractModel $model)
913
    {
914 462
        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 462
    public function getServiceName($methodName)
922
    {
923 462
        return ucfirst($this->getGather(new EmptyModel($this, $methodName)));
924
    }
925
    /**
926
     * @param GeneratorOptions $options
927
     * @return Generator
928
     */
929 1038
    protected function setOptions(GeneratorOptions $options = null)
930
    {
931 1038
        $this->options = $options;
932 1038
        return $this;
933
    }
934
    /**
935
     * @return GeneratorOptions
936
     */
937 1200
    public function getOptions()
938
    {
939 1200
        return $this->options;
940
    }
941
    /**
942
     * @return GeneratorSoapClient
943
     */
944 390
    public function getSoapClient()
945
    {
946 390
        return $this->soapClient;
947
    }
948
    /**
949
     * @param string $url
950
     * @return string
951
     */
952 1044
    public function getUrlContent($url)
953
    {
954 1044
        if (mb_strpos($url, '://') !== false) {
955 12
            $content = Utils::getContentFromUrl($url, $this->getOptionBasicLogin(), $this->getOptionBasicPassword(), $this->getOptionProxyHost(), $this->getOptionProxyPort(), $this->getOptionProxyLogin(), $this->getOptionProxyPassword(), $this->getSoapClient()->getSoapClientStreamContextOptions());
956 12
            if ($this->getOptionSchemasSave() === true) {
957 6
                Utils::saveSchemas($this->getOptionDestination(), $this->getOptionSchemasFolder(), $url, $content);
958 3
            }
959 12
            return $content;
960 1032
        } elseif (is_file($url)) {
961 1026
            return file_get_contents($url);
962
        }
963 6
        return null;
964
    }
965
    /**
966
     * @return GeneratorContainers
967
     */
968 546
    public function getContainers()
969
    {
970 546
        return $this->containers;
971
    }
972
    /**
973
     * @return array
974
     */
975 6
    public function jsonSerialize()
976
    {
977
        return [
978 6
            'containers' => $this->containers,
979 6
            'options' => $this->options,
980 3
        ];
981
    }
982
    /**
983
     * @param string $json
984
     * @throws \InvalidArgumentException
985
     * @return Generator
986
     */
987 552
    public static function instanceFromSerializedJson($json)
988
    {
989 552
        $decodedJson = json_decode($json, true);
990 552
        if (json_last_error() === JSON_ERROR_NONE) {
991
            // load options first
992 546
            $options = GeneratorOptions::instance();
993 546
            foreach ($decodedJson['options'] as $name => $value) {
994 546
                $options->setOptionValue($name, $value);
995 273
            }
996
            // create generator instance with options
997 546
            $instance = new static($options);
998
            // load services
999 546
            foreach ($decodedJson['containers']['services'] as $service) {
1000 546
                $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service));
1001 273
            }
1002
            // load structs
1003 546
            foreach ($decodedJson['containers']['structs'] as $struct) {
1004 546
                $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct));
1005 273
            }
1006 273
        } else {
1007 6
            throw new \InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error()));
1008
        }
1009 546
        return $instance;
1010
    }
1011
    /**
1012
     * @param Generator $generator
1013
     * @param array $jsonArrayEntry
1014
     * @return AbstractModel
1015
     */
1016 546
    protected static function getModelInstanceFromJsonArrayEntry(Generator $generator, array $jsonArrayEntry)
1017
    {
1018 546
        return AbstractModel::instanceFromSerializedJson($generator, $jsonArrayEntry);
1019
    }
1020
}
1021