Skip to content

Commit 3c6591b

Browse files
committed
Merge branch 'release/1.0.3'
2 parents 2a1eb98 + 01cdfb2 commit 3c6591b

16 files changed

+300
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## 1.0.3 - 2021/05/13
4+
- issue #2 - getAttributeMessageNamespace() must be of the type string, null returned
5+
36
## 1.0.2 - 2021/02/03
47
- Review .php_cs settings, apply PHP CS Fixer
58

src/AbstractDocument.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,31 @@ abstract class AbstractDocument extends DomDocumentHandler
5858
const TAG_UNION = 'union';
5959
const TAG_UNIQUE = 'unique';
6060

61+
const ATTRIBUTE_TARGET_NAMESPACE = 'targetNamespace';
62+
6163
public function getNamespaceUri(string $namespace): string
6264
{
6365
$rootElement = $this->getRootElement();
6466
$uri = '';
6567
if ($rootElement instanceof ElementHandler && $rootElement->hasAttribute(sprintf('xmlns:%s', $namespace))) {
66-
$uri = $rootElement->getAttribute(sprintf('xmlns:%s', $namespace))->getValue();
68+
$uri = $rootElement->getAttributeValue(sprintf('xmlns:%s', $namespace));
6769
}
6870

6971
return $uri;
7072
}
7173

74+
public function getAttributeTargetNamespaceValue(): string
75+
{
76+
$namespace = '';
77+
$rootElement = $this->getRootElement();
78+
79+
if ($rootElement instanceof ElementHandler && $rootElement->hasAttribute(self::ATTRIBUTE_TARGET_NAMESPACE)) {
80+
$namespace = $rootElement->getAttributeValue(self::ATTRIBUTE_TARGET_NAMESPACE, true);
81+
}
82+
83+
return $namespace;
84+
}
85+
7286
protected function getElementHandler(DOMElement $element, AbstractDomDocumentHandler $domDocument, int $index = -1): ElementHandler
7387
{
7488
$handlerName = Tag::class;

src/Tag/AbstractTag.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ abstract class AbstractTag extends ElementHandler
1515
{
1616
const MAX_DEEP = 5;
1717

18+
public function getDomDocumentHandler(): AbstractDocument
19+
{
20+
return parent::getDomDocumentHandler();
21+
}
22+
1823
/**
1924
* This method aims to get the parent element that matches a valid Wsdl element (aka struct).
2025
*
@@ -69,6 +74,32 @@ public function getValueAttributeValue(bool $withNamespace = false, bool $within
6974
return $this->getAttribute(Attribute::ATTRIBUTE_VALUE) instanceof Attribute ? $this->getAttribute(Attribute::ATTRIBUTE_VALUE)->getValue($withNamespace, $withinItsType, $asType) : '';
7075
}
7176

77+
public function hasAttributeTargetNamespace(): bool
78+
{
79+
return $this->hasAttribute(AbstractDocument::ATTRIBUTE_TARGET_NAMESPACE);
80+
}
81+
82+
public function getTargetNamespaceAttributeValue()
83+
{
84+
return $this->getAttribute(AbstractDocument::ATTRIBUTE_TARGET_NAMESPACE) instanceof Attribute ? $this->getAttribute(AbstractDocument::ATTRIBUTE_TARGET_NAMESPACE)->getValue(true) : '';
85+
}
86+
87+
/**
88+
* Retrieve element targetNamespace applicable value,
89+
* from targetNamespace attribute depending on the current Tag.
90+
*/
91+
public function getTargetNamespace(): string
92+
{
93+
$schema = $this instanceof TagSchema ? $this : $this->getStrictParent(AbstractDocument::TAG_SCHEMA);
94+
if ($schema instanceof TagSchema && $schema->hasAttributeTargetNamespace()) {
95+
$namespace = $schema->getTargetNamespaceAttributeValue();
96+
} else {
97+
$namespace = $this->getDomDocumentHandler()->getAttributeTargetNamespaceValue();
98+
}
99+
100+
return $namespace;
101+
}
102+
72103
protected function getSuitableParentTags(array $additionalTags = []): array
73104
{
74105
return array_merge([

src/Tag/AbstractTagOperationElement.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public function getAttributeMessage(): string
2525
return $this->hasAttributeMessage() ? $this->getAttribute(self::ATTRIBUTE_MESSAGE)->getValue() : '';
2626
}
2727

28-
public function getAttributeMessageNamespace(): string
28+
public function getAttributeMessageNamespace(): ?string
2929
{
30-
return $this->hasAttribute(self::ATTRIBUTE_MESSAGE) ? $this->getAttribute(self::ATTRIBUTE_MESSAGE)->getValueNamespace() : '';
30+
return $this->hasAttribute(self::ATTRIBUTE_MESSAGE) ? $this->getAttribute(self::ATTRIBUTE_MESSAGE)->getValueNamespace() : null;
3131
}
3232

3333
public function getMessage(): ?TagMessage
@@ -36,7 +36,7 @@ public function getMessage(): ?TagMessage
3636
$messageName = $this->getAttributeMessage();
3737

3838
if (!empty($messageName)) {
39-
$message = $this->getDomDocumentHandler()->getElementByNameAndAttributes('message', [
39+
$message = $this->getDomDocumentHandler()->getElementByNameAndAttributes(AbstractDocument::TAG_MESSAGE, [
4040
'name' => $messageName,
4141
], true);
4242
}

src/Tag/TagAttributeGroup.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44

55
namespace WsdlToPhp\WsdlHandler\Tag;
66

7+
use WsdlToPhp\WsdlHandler\AbstractDocument;
8+
79
class TagAttributeGroup extends Tag
810
{
911
public function getReferencingElements(): array
1012
{
1113
$elements = [];
12-
$attributeGroups = $this->getDomDocumentHandler()->getElementsByNameAndAttributes('attributeGroup', [
14+
$attributeGroups = $this->getDomDocumentHandler()->getElementsByNameAndAttributes(AbstractDocument::TAG_ATTRIBUTE_GROUP, [
1315
'ref' => sprintf('*:%s', $this->getAttributeName()),
1416
]);
1517
/*
1618
* In case of a referencing element that use this attributeGroup that is not namespaced,
1719
* use the non namespaced value
1820
*/
1921
if (empty($attributeGroups)) {
20-
$attributeGroups = $this->getDomDocumentHandler()->getElementsByNameAndAttributes('attributeGroup', [
22+
$attributeGroups = $this->getDomDocumentHandler()->getElementsByNameAndAttributes(AbstractDocument::TAG_ATTRIBUTE_GROUP, [
2123
'ref' => sprintf('*%s', $this->getAttributeName()),
2224
]);
2325
}

src/Tag/TagHeader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ protected function getHeaderNamespaceFromPart(): string
7676
$finalNamespace = $part->getFinalNamespace();
7777
if (!empty($finalNamespace)) {
7878
$namespace = $this->getDomDocumentHandler()->getNamespaceUri($finalNamespace);
79+
} elseif (($element = $part->getMatchingElement()) instanceof TagElement) {
80+
$namespace = $element->getTargetNamespace();
7981
}
8082
}
8183

src/Tag/TagMessage.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
namespace WsdlToPhp\WsdlHandler\Tag;
66

7+
use WsdlToPhp\WsdlHandler\AbstractDocument;
8+
79
class TagMessage extends Tag
810
{
911
public function getPart(string $name): ?TagPart
1012
{
11-
return $this->getChildByNameAndAttributes('part', [
13+
return $this->getChildByNameAndAttributes(AbstractDocument::TAG_PART, [
1214
'name' => $name,
1315
]);
1416
}

src/Tag/TagPart.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ public function getAttributeElement(bool $returnValue = true)
2020
return $this->getAttributeMixedValue(self::ATTRIBUTE_ELEMENT, $returnValue);
2121
}
2222

23+
public function getMatchingElement(): ?TagElement
24+
{
25+
$element = null;
26+
$elementName = $this->getAttributeElement();
27+
if (!empty($elementName)) {
28+
$element = $this->getDomDocumentHandler()->getElementByNameAndAttributes(AbstractDocument::TAG_ELEMENT, [
29+
'name' => $elementName,
30+
], true);
31+
}
32+
33+
return $element;
34+
}
35+
2336
/**
2437
* @return null|AttributeHandler|int|string
2538
*/
@@ -32,16 +45,11 @@ public function getFinalType(): string
3245
{
3346
$type = $this->getAttributeType();
3447
if (empty($type)) {
35-
$elementName = $this->getAttributeElement();
36-
if (!empty($elementName)) {
37-
$element = $this->getDomDocumentHandler()->getElementByNameAndAttributes(AbstractDocument::TAG_ELEMENT, [
38-
'name' => $elementName,
39-
], true);
40-
if ($element instanceof TagElement && $element->hasAttribute(self::ATTRIBUTE_TYPE)) {
41-
$type = $element->getAttribute(self::ATTRIBUTE_TYPE)->getValue();
42-
} else {
43-
$type = $elementName;
44-
}
48+
$element = $this->getMatchingElement();
49+
if ($element instanceof TagElement && $element->hasAttribute(self::ATTRIBUTE_TYPE)) {
50+
$type = $element->getAttribute(self::ATTRIBUTE_TYPE)->getValue();
51+
} else {
52+
$type = $this->getAttributeElement();
4553
}
4654
}
4755

@@ -61,13 +69,13 @@ public function getFinalName(): string
6169
public function getFinalNamespace(): ?string
6270
{
6371
$attribute = $this->getAttributeType(false);
64-
if (!empty($attribute)) {
65-
return $attribute->getValueNamespace();
72+
if ($attribute instanceof AttributeHandler && !empty($namespace = $attribute->getValueNamespace())) {
73+
return $namespace;
6674
}
6775

6876
$attribute = $this->getAttributeElement(false);
69-
if (!empty($attribute)) {
70-
return $attribute->getValueNamespace();
77+
if ($attribute instanceof AttributeHandler && !empty($namespace = $attribute->getValueNamespace())) {
78+
return $namespace;
7179
}
7280

7381
return null;

tests/AbstractTestCase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ public static function schemaEwsTypesInstance(): Schema
198198
return self::getSchema(self::schemaEwsTypesPath());
199199
}
200200

201+
public static function wsdlUnitTestPath(): string
202+
{
203+
return self::getPath('unit_tests.wsdl');
204+
}
205+
206+
public static function wsdlUnitTestInstance(): Wsdl
207+
{
208+
return self::getWsdl(self::wsdlUnitTestPath());
209+
}
210+
201211
public static function getWsdl(string $wsdlPath, bool $addExternalSchemas = true): Wsdl
202212
{
203213
$wsdlKey = sprintf('%s_%s', $wsdlPath, ((int) $addExternalSchemas));

tests/Tag/TagChoiceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function testGetChildrenElementsMustReturnNestedChildrenTags()
174174
* </xs:annotation>
175175
* </xs:attributeGroup>
176176
* </xs:complexType>
177-
* </xs:element>
177+
* </xs:element>.
178178
*/
179179
public function testGetChildrenElementsMustReturnFirstLevelNestedChildrenTagsOfHotelDescriptiveInfoRs()
180180
{
@@ -250,7 +250,7 @@ public function testGetChildrenElementsMustReturnFirstLevelNestedChildrenTagsOfH
250250
* </xs:annotation>
251251
* </xs:attributeGroup>
252252
* </xs:complexType>
253-
* </xs:element>
253+
* </xs:element>.
254254
*/
255255
public function testGetChildrenElementsMustReturnFirstLevelNestedChildrenTagsOfHotelAvailRs()
256256
{
@@ -295,7 +295,7 @@ public function testGetChildrenElementsMustReturnFirstLevelNestedChildrenTagsOfH
295295
* </xs:choice>
296296
* </xs:sequence>
297297
* </xs:complexType>
298-
* </xs:element>
298+
* </xs:element>.
299299
*/
300300
public function testGetChildrenElementsMustReturnFirstLevelNestedChildrenTagsOfDetails()
301301
{

0 commit comments

Comments
 (0)