|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace WsdlToPhp\WsdlHandler\Tag; |
|
6
|
|
|
|
|
7
|
|
|
use WsdlToPhp\DomHandler\AbstractAttributeHandler as Attribute; |
|
8
|
|
|
use WsdlToPhp\DomHandler\AbstractNodeHandler; |
|
9
|
|
|
use WsdlToPhp\DomHandler\ElementHandler; |
|
10
|
|
|
use WsdlToPhp\DomHandler\NodeHandler; |
|
11
|
|
|
use WsdlToPhp\WsdlHandler\AbstractDocument; |
|
12
|
|
|
|
|
13
|
|
|
abstract class AbstractTag extends ElementHandler |
|
14
|
|
|
{ |
|
15
|
|
|
public const MAX_DEEP = 5; |
|
16
|
|
|
|
|
17
|
102 |
|
public function getDomDocumentHandler(): AbstractDocument |
|
18
|
|
|
{ |
|
19
|
102 |
|
return parent::getDomDocumentHandler(); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* This method aims to get the parent element that matches a valid Wsdl element (aka struct). |
|
24
|
|
|
* |
|
25
|
|
|
* @return null|NodeHandler |
|
26
|
|
|
*/ |
|
27
|
32 |
|
public function getSuitableParent(bool $checkName = true, array $additionalTags = [], int $maxDeep = self::MAX_DEEP, bool $strict = false): ?AbstractNodeHandler |
|
28
|
|
|
{ |
|
29
|
32 |
|
$parentNode = null; |
|
30
|
32 |
|
if ($this->getParent() instanceof AbstractNodeHandler) { |
|
|
|
|
|
|
31
|
32 |
|
$parentTags = $strict ? $additionalTags : $this->getSuitableParentTags($additionalTags); |
|
32
|
32 |
|
$parentNode = $this->getParent()->getNode(); |
|
33
|
32 |
|
while ($maxDeep-- > 0 && ($parentNode instanceof \DOMElement) && !empty($parentNode->nodeName) && (!preg_match('/'.implode('|', $parentTags).'/i', $parentNode->nodeName) || ($checkName && preg_match('/'.implode('|', $parentTags).'/i', $parentNode->nodeName) && (!$parentNode->hasAttribute('name') || '' === $parentNode->getAttribute('name'))))) { |
|
34
|
12 |
|
$parentNode = $parentNode->parentNode; |
|
35
|
|
|
} |
|
36
|
32 |
|
if ($parentNode instanceof \DOMElement) { |
|
37
|
28 |
|
$parentNode = $this->getDomDocumentHandler()->getHandler($parentNode); |
|
38
|
|
|
} else { |
|
39
|
8 |
|
$parentNode = null; |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
32 |
|
return $parentNode; |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
4 |
|
public function hasAttributeName(): bool |
|
47
|
|
|
{ |
|
48
|
4 |
|
return $this->hasAttribute(Attribute::ATTRIBUTE_NAME); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
2 |
|
public function hasAttributeRef(): bool |
|
52
|
|
|
{ |
|
53
|
2 |
|
return $this->hasAttribute(Attribute::ATTRIBUTE_REF); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
22 |
|
public function getAttributeName(): string |
|
57
|
|
|
{ |
|
58
|
22 |
|
return $this->getAttribute(Attribute::ATTRIBUTE_NAME) instanceof Attribute ? $this->getAttribute(Attribute::ATTRIBUTE_NAME)->getValue() : ''; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
4 |
|
public function getAttributeRef(): string |
|
62
|
|
|
{ |
|
63
|
4 |
|
return $this->getAttribute(Attribute::ATTRIBUTE_REF) instanceof Attribute ? $this->getAttribute(Attribute::ATTRIBUTE_REF)->getValue() : ''; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
4 |
|
public function hasAttributeValue(): bool |
|
67
|
|
|
{ |
|
68
|
4 |
|
return $this->hasAttribute(Attribute::ATTRIBUTE_VALUE); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
4 |
|
public function getValueAttributeValue(bool $withNamespace = false, bool $withinItsType = true, ?string $asType = null) |
|
72
|
|
|
{ |
|
73
|
4 |
|
return $this->getAttribute(Attribute::ATTRIBUTE_VALUE) instanceof Attribute ? $this->getAttribute(Attribute::ATTRIBUTE_VALUE)->getValue($withNamespace, $withinItsType, $asType) : ''; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
8 |
|
public function hasAttributeTargetNamespace(): bool |
|
77
|
|
|
{ |
|
78
|
8 |
|
return $this->hasAttribute(AbstractDocument::ATTRIBUTE_TARGET_NAMESPACE); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
8 |
|
public function getTargetNamespaceAttributeValue() |
|
82
|
|
|
{ |
|
83
|
8 |
|
return $this->getAttribute(AbstractDocument::ATTRIBUTE_TARGET_NAMESPACE) instanceof Attribute ? $this->getAttribute(AbstractDocument::ATTRIBUTE_TARGET_NAMESPACE)->getValue(true) : ''; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Retrieve element targetNamespace applicable value, |
|
88
|
|
|
* from targetNamespace attribute depending on the current Tag. |
|
89
|
|
|
*/ |
|
90
|
6 |
|
public function getTargetNamespace(): string |
|
91
|
|
|
{ |
|
92
|
6 |
|
$schema = $this instanceof TagSchema ? $this : $this->getStrictParent(AbstractDocument::TAG_SCHEMA); |
|
93
|
6 |
|
if ($schema instanceof TagSchema && $schema->hasAttributeTargetNamespace()) { |
|
94
|
6 |
|
$namespace = $schema->getTargetNamespaceAttributeValue(); |
|
95
|
|
|
} else { |
|
96
|
|
|
$namespace = $this->getDomDocumentHandler()->getAttributeTargetNamespaceValue(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
6 |
|
return $namespace; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
18 |
|
protected function getSuitableParentTags(array $additionalTags = []): array |
|
103
|
|
|
{ |
|
104
|
18 |
|
return array_merge([ |
|
105
|
18 |
|
AbstractDocument::TAG_ELEMENT, |
|
106
|
18 |
|
AbstractDocument::TAG_ATTRIBUTE, |
|
107
|
18 |
|
AbstractDocument::TAG_SIMPLE_TYPE, |
|
108
|
18 |
|
AbstractDocument::TAG_COMPLEX_TYPE, |
|
109
|
18 |
|
], $additionalTags); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
14 |
|
protected function getStrictParent(string $name, bool $checkName = false): ?AbstractNodeHandler |
|
113
|
|
|
{ |
|
114
|
14 |
|
$parent = $this->getSuitableParent($checkName, [ |
|
115
|
14 |
|
$name, |
|
116
|
14 |
|
], self::MAX_DEEP, true); |
|
117
|
|
|
|
|
118
|
14 |
|
if ($parent instanceof AbstractNodeHandler && $parent->getName() === $name) { |
|
119
|
12 |
|
return $parent; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
4 |
|
return null; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|