Completed
Push — develop ( bacd9d...dcd68d )
by Mikaël
46:10 queued 42:30
created

Generator::setOptionOrigin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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