1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WsdlToPhp\PackageGenerator\WsdlHandler; |
4
|
|
|
|
5
|
|
|
use WsdlToPhp\PackageGenerator\WsdlHandler\Tag\AbstractTag; |
6
|
|
|
use WsdlToPhp\PackageGenerator\Model\Schema as Model; |
7
|
|
|
use WsdlToPhp\PackageGenerator\Container\Model\Schema as ModelContainer; |
8
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Generator; |
9
|
|
|
|
10
|
|
|
class Wsdl extends AbstractDocument |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var ModelContainer |
14
|
|
|
*/ |
15
|
|
|
protected $externalSchemas; |
16
|
|
|
/** |
17
|
|
|
* @see \WsdlToPhp\DomHandler\AbstractDomDocumentHandler::__construct() |
18
|
|
|
* @param \DOMDocument $domDocument |
19
|
|
|
* @param Generator $generator |
20
|
|
|
*/ |
21
|
|
|
public function __construct(\DOMDocument $domDocument, Generator $generator) |
22
|
|
|
{ |
23
|
|
|
parent::__construct($domDocument); |
24
|
|
|
$this->externalSchemas = new ModelContainer($generator); |
25
|
|
|
} |
26
|
|
|
/** |
27
|
|
|
* @param Model $schema |
28
|
|
|
* @return \WsdlToPhp\PackageGenerator\WsdlHandler\Wsdl |
29
|
|
|
*/ |
30
|
|
|
public function addExternalSchema(Model $schema) |
31
|
|
|
{ |
32
|
|
|
$this->externalSchemas->add($schema); |
33
|
|
|
return $this; |
34
|
|
|
} |
35
|
|
|
/** |
36
|
|
|
* @param string $name |
37
|
|
|
* @return \WsdlToPhp\PackageGenerator\Model\Schema|null |
38
|
|
|
*/ |
39
|
|
|
public function getExternalSchema($name) |
40
|
|
|
{ |
41
|
|
|
return $this->externalSchemas->getSchemaByName($name); |
42
|
|
|
} |
43
|
|
|
/** |
44
|
|
|
* @return \WsdlToPhp\PackageGenerator\Container\Model\Schema |
45
|
|
|
*/ |
46
|
|
|
public function getExternalSchemas() |
47
|
|
|
{ |
48
|
|
|
return $this->externalSchemas; |
49
|
|
|
} |
50
|
|
|
/** |
51
|
|
|
* @see \WsdlToPhp\PackageGenerator\WsdlHandler\AbstractDocument::getElementByName() |
52
|
|
|
* @return AbstractTag|null |
53
|
|
|
*/ |
54
|
|
|
public function getElementByName($name, $includeExternals = false) |
55
|
|
|
{ |
56
|
|
|
return $this->useParentMethodAndExternals(__FUNCTION__, array( |
57
|
|
|
$name, |
58
|
|
|
), $includeExternals, true); |
59
|
|
|
} |
60
|
|
|
/** |
61
|
|
|
* @see \WsdlToPhp\DomHandler\AbstractDomDocumentHandler::getElementByNameAndAttributes() |
62
|
|
|
* @return AbstractTag|null |
63
|
|
|
*/ |
64
|
|
|
public function getElementByNameAndAttributes($name, array $attributes, $includeExternals = false) |
65
|
|
|
{ |
66
|
|
|
return $this->useParentMethodAndExternals(__FUNCTION__, array( |
67
|
|
|
$name, |
68
|
|
|
$attributes, |
69
|
|
|
), $includeExternals, true); |
70
|
|
|
} |
71
|
|
|
/** |
72
|
|
|
* @see \WsdlToPhp\PackageGenerator\WsdlHandler\AbstractDocument::getElementsByName() |
73
|
|
|
* @return AbstractTag[] |
74
|
|
|
*/ |
75
|
|
|
public function getElementsByName($name, $includeExternals = false) |
76
|
|
|
{ |
77
|
|
|
return $this->useParentMethodAndExternals(__FUNCTION__, array( |
78
|
|
|
$name, |
79
|
|
|
), $includeExternals); |
80
|
|
|
} |
81
|
|
|
/** |
82
|
|
|
* @param string $name |
83
|
|
|
* @param array $attributes |
84
|
|
|
* @param \DOMNode|null $node |
85
|
|
|
* @param bool $includeExternals |
86
|
|
|
* @see \WsdlToPhp\DomHandler\AbstractDomDocumentHandler::getElementsByNameAndAttributes() |
87
|
|
|
* @return AbstractTag[] |
88
|
|
|
*/ |
89
|
|
|
public function getElementsByNameAndAttributes($name, array $attributes, \DOMNode $node = null, $includeExternals = false) |
90
|
|
|
{ |
91
|
|
|
return $this->useParentMethodAndExternals(__FUNCTION__, array( |
92
|
|
|
$name, |
93
|
|
|
$attributes, |
94
|
|
|
$node, |
95
|
|
|
), $includeExternals); |
96
|
|
|
} |
97
|
|
|
/** |
98
|
|
|
* Handler any method that exist within the parant class, |
99
|
|
|
* in addition it handles the case when we want to use the external schemas to search in |
100
|
|
|
* @param string $method |
101
|
|
|
* @param array $parameters |
102
|
|
|
* @param bool $includeExternals |
103
|
|
|
* @param bool $returnOne |
104
|
|
|
* @return mixed |
105
|
|
|
*/ |
106
|
|
|
private function useParentMethodAndExternals($method, $parameters, $includeExternals = false, $returnOne = false) |
107
|
|
|
{ |
108
|
|
|
$result = call_user_func_array(array( |
109
|
|
|
$this, |
110
|
|
|
sprintf('parent::%s', $method), |
111
|
|
|
), $parameters); |
112
|
|
|
if ($includeExternals === true && (($returnOne === true && $result === null) || $returnOne === false)) { |
113
|
|
|
$result = $this->useExternalSchemas($method, $parameters, $result, $returnOne); |
114
|
|
|
} |
115
|
|
|
return $result; |
116
|
|
|
} |
117
|
|
|
/** |
118
|
|
|
* @param string $method |
119
|
|
|
* @param array $parameters |
120
|
|
|
* @param bool $returnOne |
121
|
|
|
* @return mixed |
122
|
|
|
*/ |
123
|
|
|
private function useExternalSchemas($method, $parameters, $parentResult, $returnOne = false) |
124
|
|
|
{ |
125
|
|
|
$result = $parentResult; |
126
|
|
|
if ($this->getExternalSchemas()->count() > 0) { |
127
|
|
|
foreach ($this->getExternalSchemas() as $externalSchema) { |
128
|
|
|
if ($externalSchema->getContent() instanceof AbstractDocument) { |
129
|
|
|
$externalResult = call_user_func_array(array( |
130
|
|
|
$externalSchema->getContent(), |
131
|
|
|
$method, |
132
|
|
|
), $parameters); |
133
|
|
|
if ($returnOne === true && $externalResult !== null) { |
134
|
|
|
$result = $externalResult; |
135
|
|
|
break; |
136
|
|
|
} elseif (is_array($externalResult) && !empty($externalResult)) { |
137
|
|
|
$result = array_merge($result, $externalResult); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
return $result; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|