|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WsdlToPhp\PackageGenerator\Parser\Wsdl; |
|
4
|
|
|
|
|
5
|
|
|
use WsdlToPhp\PackageGenerator\Model\Wsdl; |
|
6
|
|
|
use WsdlToPhp\PackageGenerator\Model\Schema; |
|
7
|
|
|
use WsdlToPhp\PackageGenerator\Parser\AbstractParser as Parser; |
|
8
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Generator; |
|
9
|
|
|
use WsdlToPhp\PackageGenerator\DomHandler\Wsdl\Wsdl as WsdlDocument; |
|
10
|
|
|
use WsdlToPhp\PackageGenerator\DomHandler\Wsdl\Schema as SchemaDocument; |
|
11
|
|
|
|
|
12
|
|
|
abstract class AbstractParser extends Parser |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var Generator |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $generator; |
|
18
|
|
|
/** |
|
19
|
|
|
* @var AbstractTag[] |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $tags; |
|
22
|
|
|
/** |
|
23
|
|
|
* List of Wsdl parsed for the current tag |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
private $parsedWsdls; |
|
27
|
|
|
/** |
|
28
|
|
|
* List of Schema parsed for the current tag |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
private $parsedSchemas; |
|
32
|
|
|
/** |
|
33
|
|
|
* |
|
34
|
|
|
* @param Generator $generator |
|
35
|
|
|
*/ |
|
36
|
456 |
|
public function __construct(Generator $generator) |
|
37
|
|
|
{ |
|
38
|
456 |
|
$this->generator = $generator; |
|
39
|
456 |
|
$this->parsedWsdls = array(); |
|
40
|
456 |
|
$this->parsedSchemas = array(); |
|
41
|
456 |
|
} |
|
42
|
|
|
/** |
|
43
|
|
|
* The method takes care of looping among WSDLS as much time as it is needed |
|
44
|
|
|
* @see \WsdlToPhp\PackageGenerator\Generator\ParserInterface::parse() |
|
45
|
|
|
*/ |
|
46
|
396 |
|
final public function parse() |
|
47
|
|
|
{ |
|
48
|
396 |
|
$wsdl = $this->generator->getWsdl(); |
|
49
|
396 |
|
if ($wsdl instanceof Wsdl) { |
|
50
|
396 |
|
$content = $wsdl->getContent(); |
|
51
|
396 |
|
if ($content instanceof WsdlDocument) { |
|
52
|
396 |
|
if ($this->isWsdlParsed($wsdl) === false) { |
|
53
|
297 |
|
$this |
|
54
|
396 |
|
->setWsdlAsParsed($wsdl) |
|
55
|
396 |
|
->setTags($content->getElementsByName($this->parsingTag())) |
|
56
|
396 |
|
->parseWsdl($wsdl); |
|
57
|
297 |
|
} |
|
58
|
396 |
|
foreach ($content->getExternalSchemas() as $schema) { |
|
59
|
148 |
|
if ($this->isSchemaParsed($wsdl, $schema) === false) { |
|
60
|
148 |
|
$this->setSchemaAsParsed($wsdl, $schema); |
|
61
|
148 |
|
$schemaContent = $schema->getContent(); |
|
62
|
148 |
|
if ($schemaContent instanceof SchemaDocument) { |
|
63
|
111 |
|
$this |
|
64
|
148 |
|
->setTags($schemaContent->getElementsByName($this->parsingTag())) |
|
65
|
148 |
|
->parseSchema($wsdl, $schema); |
|
66
|
111 |
|
} |
|
67
|
111 |
|
} |
|
68
|
297 |
|
} |
|
69
|
297 |
|
} |
|
70
|
297 |
|
} |
|
71
|
396 |
|
} |
|
72
|
|
|
/** |
|
73
|
|
|
* Actual parsing of the Wsdl |
|
74
|
|
|
* @param Wsdl $wsdl |
|
75
|
|
|
*/ |
|
76
|
|
|
abstract protected function parseWsdl(Wsdl $wsdl); |
|
77
|
|
|
/** |
|
78
|
|
|
* Actual parsing of the Schema |
|
79
|
|
|
* @param Wsdl $wsdl |
|
80
|
|
|
* @param Schema $schema |
|
81
|
|
|
*/ |
|
82
|
|
|
abstract protected function parseSchema(Wsdl $wsdl, Schema $schema); |
|
83
|
|
|
/** |
|
84
|
|
|
* Must return the tag that will be parsed |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
|
|
abstract protected function parsingTag(); |
|
88
|
|
|
/** |
|
89
|
|
|
* @param array $tags |
|
90
|
|
|
* @return \WsdlToPhp\PackageGenerator\Parser\Wsdl\AbstractParser |
|
91
|
|
|
*/ |
|
92
|
396 |
|
private function setTags(array $tags) |
|
93
|
|
|
{ |
|
94
|
396 |
|
$this->tags = $tags; |
|
95
|
396 |
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
/** |
|
98
|
|
|
* @return AbstractTag[] |
|
99
|
|
|
*/ |
|
100
|
396 |
|
public function getTags() |
|
101
|
|
|
{ |
|
102
|
396 |
|
return $this->tags; |
|
103
|
|
|
} |
|
104
|
|
|
/** |
|
105
|
|
|
* @param Wsdl $wsdl |
|
106
|
|
|
* @return AbstractParser |
|
107
|
|
|
*/ |
|
108
|
396 |
|
private function setWsdlAsParsed(Wsdl $wsdl) |
|
109
|
|
|
{ |
|
110
|
396 |
|
if (!array_key_exists($wsdl->getName(), $this->parsedWsdls)) { |
|
111
|
396 |
|
$this->parsedWsdls[$wsdl->getName()] = array(); |
|
112
|
297 |
|
} |
|
113
|
396 |
|
$this->parsedWsdls[$wsdl->getName()][] = $this->parsingTag(); |
|
114
|
396 |
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
/** |
|
117
|
|
|
* @param Wsdl $wsdl |
|
118
|
|
|
* @return boolean |
|
119
|
|
|
*/ |
|
120
|
396 |
|
public function isWsdlParsed(Wsdl $wsdl) |
|
121
|
|
|
{ |
|
122
|
|
|
return |
|
123
|
396 |
|
array_key_exists($wsdl->getName(), $this->parsedWsdls) && |
|
124
|
396 |
|
is_array($this->parsedWsdls[$wsdl->getName()]) && |
|
125
|
396 |
|
in_array($this->parsingTag(), $this->parsedWsdls[$wsdl->getName()]); |
|
126
|
|
|
} |
|
127
|
|
|
/** |
|
128
|
|
|
* @param Wsdl $wsdl |
|
129
|
|
|
* @param Schema $schema |
|
130
|
|
|
* @return AbstractParser |
|
131
|
|
|
*/ |
|
132
|
148 |
|
private function setSchemaAsParsed(Wsdl $wsdl, Schema $schema) |
|
133
|
|
|
{ |
|
134
|
148 |
|
$key = $wsdl->getName() . $schema->getName(); |
|
135
|
148 |
|
if (!array_key_exists($key, $this->parsedSchemas)) { |
|
136
|
148 |
|
$this->parsedSchemas[$key] = array(); |
|
137
|
111 |
|
} |
|
138
|
148 |
|
$this->parsedSchemas[$key][] = $this->parsingTag(); |
|
139
|
148 |
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
/** |
|
142
|
|
|
* @param Wsdl $wsdl |
|
143
|
|
|
* @param Schema $schema |
|
144
|
|
|
* @return boolean |
|
145
|
|
|
*/ |
|
146
|
148 |
|
public function isSchemaParsed(Wsdl $wsdl, Schema $schema) |
|
147
|
|
|
{ |
|
148
|
148 |
|
$key = $wsdl->getName() . $schema->getName(); |
|
149
|
|
|
return |
|
150
|
148 |
|
array_key_exists($key, $this->parsedSchemas) && |
|
151
|
148 |
|
is_array($this->parsedSchemas[$key]) && |
|
152
|
148 |
|
in_array($this->parsingTag(), $this->parsedSchemas[$key]); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|