Completed
Push — master ( 2bdad3...069cad )
by Mikaël
44:23 queued 21:55
created

Generator::setOptionArraysFolder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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
    private $wsdl;
24
    /**
25
     * @var GeneratorOptions
26
     */
27
    private $options;
28
    /**
29
     * Used parsers
30
     * @var GeneratorParsers
31
     */
32
    private $parsers;
33
    /**
34
     * Used files
35
     * @var GeneratorFiles
36
     */
37
    private $files;
38
    /**
39
     * Used containers
40
     * @var GeneratorContainers
41
     */
42
    private $containers;
43
    /**
44
     * Used SoapClient
45
     * @var GeneratorSoapClient
46
     */
47
    private $soapClient;
48
    /**
49
     * Constructor
50
     * @param GeneratorOptions $options
51
     */
52 750
    public function __construct(GeneratorOptions $options)
53
    {
54 750
        $this->setOptions($options)->initialize();
55 740
    }
56
    /**
57
     * @return Generator
58
     */
59 750
    protected function initialize()
60
    {
61 750
        return $this->initContainers()
62 750
            ->initParsers()
63 750
            ->initFiles()
64 750
            ->initSoapClient()
65 745
            ->initWsdl();
66
    }
67
    /**
68
     * @throws \InvalidArgumentException
69
     * @return Generator
70
     */
71 750
    protected function initSoapClient()
72
    {
73 750
        if (!isset($this->soapClient)) {
74 750
            $this->soapClient = new GeneratorSoapClient($this);
75 447
        }
76 745
        return $this;
77
    }
78
    /**
79
     * @return Generator
80
     */
81 750
    protected function initContainers()
82
    {
83 750
        if (!isset($this->containers)) {
84 750
            $this->containers = new GeneratorContainers($this);
85 450
        }
86 750
        return $this;
87
    }
88
    /**
89
     * @return Generator
90
     */
91 750
    protected function initParsers()
92
    {
93 750
        if (!isset($this->parsers)) {
94 750
            $this->parsers = new GeneratorParsers($this);
95 450
        }
96 750
        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 750
    protected function initFiles()
109
    {
110 750
        if (!isset($this->files)) {
111 750
            $this->files = new GeneratorFiles($this);
112 450
        }
113 750
        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 750
    protected function initWsdl()
138
    {
139 750
        $this->setWsdl(new Wsdl($this, $this->getOptionOrigin(), $this->getUrlContent($this->getOptionOrigin())));
140 745
        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 545
    public function getStruct($structName)
200
    {
201 545
        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 635
    public function getStructs()
248
    {
249 635
        return $this->containers->getStructs();
250
    }
251
    /**
252
     * Sets the optionCategory value
253
     * @return string
254
     */
255 395
    public function getOptionCategory()
256
    {
257 395
        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 365
    public function getOptionNamespacePrefix()
328
    {
329 365
        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 285
    public function getOptionAddComments()
346
    {
347 285
        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 165
    public function getOptionValidation()
382
    {
383 165
        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 140
    public function getOptionStructClass()
400
    {
401 140
        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 760
    public function getOptionPrefix($ucFirst = true)
455
    {
456 760
        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 730
    public function getOptionSuffix($ucFirst = true)
474
    {
475 730
        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 770
    public function getOptionBasicLogin()
492
    {
493 770
        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 770
    public function getOptionBasicPassword()
510
    {
511 770
        return $this->options->getBasicPassword();
512
    }
513
    /**
514
     * Sets the optionBasicPassword value
515
     * @param string $optionBasicPassword
516
     * @return Generator
517
     */
518 5
    public function setOptionBasicPassword($optionBasicPassword)
519
    {
520 5
        $this->options->setBasicPassword($optionBasicPassword);
521 5
        return $this;
522
    }
523
    /**
524
     * Gets the optionProxyHost value
525
     * @return string
526
     */
527 770
    public function getOptionProxyHost()
528
    {
529 770
        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 770
    public function getOptionProxyPort()
546
    {
547 770
        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 770
    public function getOptionProxyLogin()
564
    {
565 770
        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 770
    public function getOptionProxyPassword()
582
    {
583 770
        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 765
    public function getOptionOrigin()
600
    {
601 765
        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 420
    public function getOptionDestination()
619
    {
620 420
        $destination = $this->options->getDestination();
621 420
        if (!empty($destination)) {
622 415
            $destination = rtrim($destination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
623 249
        }
624 420
        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 optionSrcDiname value
642
     * @return string
643
     */
644 360
    public function getOptionSrcDirname()
645
    {
646 360
        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 string
661
     */
662 760
    public function getOptionSoapOptions()
663
    {
664 760
        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 365
    public function getOptionStructsFolder()
724
    {
725 365
        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 725
    public function getOptionServicesFolder()
778
    {
779 725
        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 WSDL
793
     * @return Wsdl|null
794
     */
795 575
    public function getWsdl()
796
    {
797 575
        return $this->wsdl;
798
    }
799
    /**
800
     * Sets the WSDLs
801
     * @param Wsdl $wsdl
802
     * @return Generator
803
     */
804 745
    protected function setWsdl(Wsdl $wsdl)
805
    {
806 745
        $this->wsdl = $wsdl;
807 745
        return $this;
808
    }
809
    /**
810
     * Adds Wsdl location
811
     * @param Wsdl $wsdl
812
     * @param string $schemaLocation
813
     * @return Generator
814
     */
815 150
    public function addSchemaToWsdl(Wsdl $wsdl, $schemaLocation)
816
    {
817 150
        if (!empty($schemaLocation) && $wsdl->getContent() instanceof WsdlDocument && $wsdl->getContent()->getExternalSchema($schemaLocation) === null) {
818 150
            $wsdl->getContent()->addExternalSchema(new Schema($wsdl->getGenerator(), $schemaLocation, $this->getUrlContent($schemaLocation)));
819 90
        }
820 150
        return $this;
821
    }
822
    /**
823
     * Gets gather name class
824
     * @param AbstractModel $model the model for which we generate the folder
825
     * @return string
826
     */
827 355
    private function getGather(AbstractModel $model)
828
    {
829 355
        return Utils::getPart($this->getOptionGatherMethods(), $model->getCleanName());
830
    }
831
    /**
832
     * Returns the service name associated to the method/operation name in order to gather them in one service class
833
     * @param string $methodName original operation/method name
834
     * @return string
835
     */
836 355
    public function getServiceName($methodName)
837
    {
838 355
        return ucfirst($this->getGather(new EmptyModel($this, $methodName)));
839
    }
840
    /**
841
     * @param GeneratorOptions $options
842
     * @return Generator
843
     */
844 750
    protected function setOptions(GeneratorOptions $options = null)
845
    {
846 750
        $this->options = $options;
847 750
        return $this;
848
    }
849
    /**
850
     * @return GeneratorOptions
851
     */
852 770
    public function getOptions()
853
    {
854 770
        return $this->options;
855
    }
856
    /**
857
     * @return GeneratorSoapClient
858
     */
859 300
    public function getSoapClient()
860
    {
861 300
        return $this->soapClient;
862
    }
863
    /**
864
     * @param string $url
865
     * @return string
866
     */
867 755
    public function getUrlContent($url)
868
    {
869 755
        if (strpos($url, '://') !== false) {
870 10
            return Utils::getContentFromUrl($url, $this->getOptionBasicLogin(), $this->getOptionBasicPassword(), $this->getOptionProxyHost(), $this->getOptionProxyPort(), $this->getOptionProxyLogin(), $this->getOptionProxyPassword(), $this->getSoapClient()->getSoapClientStreamContextOptions());
871 745
        } elseif (is_file($url)) {
872 740
            return file_get_contents($url);
873
        }
874 5
        return null;
875
    }
876
    /**
877
     * @return GeneratorContainers
878
     */
879 375
    public function getContainers()
880
    {
881 375
        return $this->containers;
882
    }
883
    /**
884
     * @return array
885
     */
886 5
    public function jsonSerialize()
887
    {
888
        return [
889 5
            'containers' => $this->containers,
890 5
            'options' => $this->options,
891 3
        ];
892
    }
893
    /**
894
     * @param string $json
895
     * @throws \InvalidArgumentException
896
     * @return Generator
897
     */
898 375
    public static function instanceFromSerializedJson($json)
899
    {
900 375
        $decodedJson = json_decode($json, true);
901 375
        if (json_last_error() === JSON_ERROR_NONE) {
902
            // load options first
903 375
            $options = GeneratorOptions::instance();
904 375
            foreach ($decodedJson['options']as $name => $value) {
905 375
                $options->setOptionValue($name, $value);
906 225
            }
907
            // create generator instance with options
908 375
            $instance = new static($options);
909
            // load services
910 375
            foreach ($decodedJson['containers']['services'] as $service) {
911 375
                $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service));
912 225
            }
913
            // load sructs
914 375
            foreach ($decodedJson['containers']['structs'] as $struct) {
915 375
                $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct));
916 225
            }
917 225
        } else {
918
            throw new \InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error()));
919
        }
920 375
        return $instance;
921
    }
922
    /**
923
     * @param Generator $generator
924
     * @param array $jsonArrayEntry
925
     * @return AbstractModel
926
     */
927 375
    private static function getModelInstanceFromJsonArrayEntry(Generator $generator, array $jsonArrayEntry)
928
    {
929 375
        return AbstractModel::instanceFromSerializedJson($generator, $jsonArrayEntry);
930
    }
931
}
932