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