Completed
Push — feature/issue-157 ( 8c1a44 )
by Mikaël
20:07
created

Generator::getParsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
985 234
            }
986 234
        } else {
987
            throw new \InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error()));
988
        }
989 390
        return $instance;
990
    }
991
    /**
992
     * @param Generator $generator
993
     * @param array $jsonArrayEntry
994
     * @return AbstractModel
995
     */
996 390
    protected static function getModelInstanceFromJsonArrayEntry(Generator $generator, array $jsonArrayEntry)
997
    {
998 390
        return AbstractModel::instanceFromSerializedJson($generator, $jsonArrayEntry);
999
    }
1000
}
1001