|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace WsdlToPhp\PackageGenerator\Generator; |
|
6
|
|
|
|
|
7
|
|
|
use WsdlToPhp\PackageGenerator\File\AbstractModelFile; |
|
8
|
|
|
use WsdlToPhp\PackageGenerator\File\ClassMap as ClassMapFile; |
|
9
|
|
|
use WsdlToPhp\PackageGenerator\File\Composer as ComposerFile; |
|
10
|
|
|
use WsdlToPhp\PackageGenerator\File\Service as ServiceFile; |
|
11
|
|
|
use WsdlToPhp\PackageGenerator\File\Struct as StructFile; |
|
12
|
|
|
use WsdlToPhp\PackageGenerator\File\StructArray as StructArrayFile; |
|
13
|
|
|
use WsdlToPhp\PackageGenerator\File\StructEnum as StructEnumFile; |
|
14
|
|
|
use WsdlToPhp\PackageGenerator\File\Tutorial as TutorialFile; |
|
15
|
|
|
use WsdlToPhp\PackageGenerator\Model\EmptyModel; |
|
16
|
|
|
use WsdlToPhp\PackageGenerator\Model\Struct as StructModel; |
|
17
|
|
|
|
|
18
|
|
|
class GeneratorFiles extends AbstractGeneratorAware |
|
19
|
|
|
{ |
|
20
|
|
|
protected ClassMapFile $classmapFile; |
|
21
|
|
|
|
|
22
|
26 |
|
public function getClassmapFile(): ClassMapFile |
|
23
|
|
|
{ |
|
24
|
26 |
|
if (!isset($this->classmapFile)) { |
|
25
|
26 |
|
$classMapModel = new EmptyModel($this->generator, 'ClassMap'); |
|
26
|
26 |
|
$classMap = new ClassMapFile($this->generator, $classMapModel->getPackagedName()); |
|
27
|
26 |
|
$classMap->setModel($classMapModel); |
|
28
|
26 |
|
$this->classmapFile = $classMap; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
26 |
|
return $this->classmapFile; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
12 |
|
public function doGenerate(): GeneratorFiles |
|
35
|
|
|
{ |
|
36
|
12 |
|
return $this |
|
37
|
12 |
|
->generateStructsClasses() |
|
38
|
12 |
|
->generateServicesClasses() |
|
39
|
12 |
|
->generateClassMap() |
|
40
|
12 |
|
->generateTutorialFile() |
|
41
|
12 |
|
->generateComposerFile() |
|
42
|
12 |
|
; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
12 |
|
protected function generateStructsClasses(): GeneratorFiles |
|
46
|
|
|
{ |
|
47
|
12 |
|
foreach ($this->getGenerator()->getStructs() as $struct) { |
|
48
|
12 |
|
if (!$struct->isStruct()) { |
|
49
|
12 |
|
continue; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
12 |
|
$this |
|
53
|
12 |
|
->getStructFile($struct) |
|
54
|
12 |
|
->setModel($struct) |
|
55
|
12 |
|
->write() |
|
56
|
12 |
|
; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
12 |
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
12 |
|
protected function getStructFile(StructModel $struct): AbstractModelFile |
|
63
|
|
|
{ |
|
64
|
12 |
|
if ($struct->isRestriction()) { |
|
65
|
12 |
|
$file = new StructEnumFile($this->generator, $struct->getPackagedName()); |
|
66
|
12 |
|
} elseif ($struct->isArray()) { |
|
67
|
6 |
|
$file = new StructArrayFile($this->generator, $struct->getPackagedName()); |
|
68
|
|
|
} else { |
|
69
|
12 |
|
$file = new StructFile($this->generator, $struct->getPackagedName()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
12 |
|
return $file; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
12 |
|
protected function generateServicesClasses(): self |
|
76
|
|
|
{ |
|
77
|
12 |
|
foreach ($this->getGenerator()->getServices(true) as $service) { |
|
78
|
12 |
|
$file = new ServiceFile($this->generator, $service->getPackagedName()); |
|
79
|
12 |
|
$file->setModel($service)->write(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
12 |
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
12 |
|
protected function generateClassMap(): self |
|
86
|
|
|
{ |
|
87
|
12 |
|
$this->getClassmapFile()->write(); |
|
88
|
|
|
|
|
89
|
12 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
12 |
|
protected function generateTutorialFile(): self |
|
93
|
|
|
{ |
|
94
|
12 |
|
if ($this->generator->getOptionGenerateTutorialFile() && $this->getClassmapFile() instanceof ClassMapFile) { |
|
95
|
12 |
|
$tutorialFile = new TutorialFile($this->generator, 'tutorial'); |
|
96
|
12 |
|
$tutorialFile->write(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
12 |
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
12 |
|
protected function generateComposerFile(): self |
|
103
|
|
|
{ |
|
104
|
12 |
|
if ($this->generator->getOptionStandalone()) { |
|
105
|
10 |
|
$composerFile = new ComposerFile($this->generator, 'composer'); |
|
106
|
10 |
|
$composerFile->write(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
12 |
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|