Skip to content

Commit 31adf06

Browse files
authored
Merge pull request #20 from veewee/wsdl-import-xsd
Make it possible for wsdl:import tags to directly import XSD items.
2 parents 467e771 + 25106c8 commit 31adf06

File tree

7 files changed

+89
-4
lines changed

7 files changed

+89
-4
lines changed

src/Loader/StreamWrapperLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function __construct($context = null)
2222
{
2323
$this->context = $context;
2424
}
25-
25+
2626
public function __invoke(string $location): string
2727
{
2828
try {
29-
$content = file_get_contents(
29+
$content = @file_get_contents(
3030
$location,
3131
context: is_resource($this->context) ? $this->context : null
3232
);

src/Xml/Configurator/FlattenWsdlImports.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
use Soap\Wsdl\Exception\UnloadableWsdlException;
1010
use Soap\Wsdl\Loader\Context\FlatteningContext;
1111
use Soap\Wsdl\Uri\IncludePathBuilder;
12+
use Soap\Xml\Xmlns;
1213
use Soap\Xml\Xpath\WsdlPreset;
1314
use VeeWee\Xml\Dom\Configurator\Configurator;
1415
use VeeWee\Xml\Dom\Document;
1516
use VeeWee\Xml\Exception\RuntimeException;
1617
use function VeeWee\Xml\Dom\Locator\document_element;
1718
use function VeeWee\Xml\Dom\Locator\Node\children;
19+
use function VeeWee\Xml\Dom\Manipulator\Node\append_external_node;
1820
use function VeeWee\Xml\Dom\Manipulator\Node\remove;
1921
use function VeeWee\Xml\Dom\Manipulator\Node\replace_by_external_nodes;
2022

@@ -66,11 +68,34 @@ private function importWsdlImportElement(DOMElement $import): void
6668
}
6769

6870
$imported = Document::fromXmlString($result);
69-
$definitions = $imported->map(document_element());
71+
72+
// A wsdl:import can be either a WSDL or an XSD file:
73+
match ($imported->locateDocumentElement()->namespaceURI) {
74+
Xmlns::xsd()->value() => $this->importXsdPart($import, $imported),
75+
default => $this->importWsdlPart($import, $imported),
76+
};
77+
}
78+
79+
/**
80+
* @throws RuntimeException
81+
*/
82+
private function importWsdlPart(DOMElement $importElement, Document $importedDocument): void
83+
{
84+
$definitions = $importedDocument->map(document_element());
7085

7186
replace_by_external_nodes(
72-
$import,
87+
$importElement,
7388
children($definitions)
7489
);
7590
}
91+
92+
/**
93+
* @throws RuntimeException
94+
*/
95+
private function importXsdPart(DOMElement $importElement, Document $importedDocument): void
96+
{
97+
$types = $this->context->types();
98+
remove($importElement);
99+
append_external_node($types, $importedDocument->locateDocumentElement());
100+
}
76101
}

tests/Unit/Xml/Configurator/FlattenWsdlImportsTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,13 @@ public function provideTestCases()
4646
'wsdl' => FIXTURE_DIR.'/flattening/multi-import.wsdl',
4747
'expected' => Document::fromXmlFile(FIXTURE_DIR.'/flattening/result/multi-import-result.wsdl', comparable()),
4848
];
49+
yield 'xsd-imports' => [
50+
'wsdl' => FIXTURE_DIR.'/flattening/import-xsd.wsdl',
51+
'expected' => Document::fromXmlFile(FIXTURE_DIR.'/flattening/result/import-xsd-result.wsdl', comparable()),
52+
];
53+
yield 'multi-xsd-imports' => [
54+
'wsdl' => FIXTURE_DIR.'/flattening/import-multi-xsd.wsdl',
55+
'expected' => Document::fromXmlFile(FIXTURE_DIR.'/flattening/result/import-multi-xsd-result.wsdl', comparable()),
56+
];
4957
}
5058
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<definitions
3+
xmlns="http://schemas.xmlsoap.org/wsdl/"
4+
xmlns:tns="http://soapinterop.org/"
5+
targetNamespace="http://soapinterop.org/">
6+
<import namespace="http://soapinterop.org/store1" location="xsd/store1.xsd" />
7+
<import namespace="http://soapinterop.org/store2" location="xsd/store2.xsd" />
8+
</definitions>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<definitions
3+
xmlns="http://schemas.xmlsoap.org/wsdl/"
4+
xmlns:tns="http://soapinterop.org/"
5+
targetNamespace="http://soapinterop.org/">
6+
<import namespace="http://soapinterop.org/store1" location="xsd/store1.xsd" />
7+
</definitions>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<definitions
3+
xmlns="http://schemas.xmlsoap.org/wsdl/"
4+
xmlns:tns="http://soapinterop.org/"
5+
targetNamespace="http://soapinterop.org/">
6+
<types>
7+
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://soapinterop.org/store1">
8+
<xsd:complexType name="Store">
9+
<xsd:sequence>
10+
<element minOccurs="1" maxOccurs="1" name="Attribute1" type="string"/>
11+
</xsd:sequence>
12+
</xsd:complexType>
13+
</schema>
14+
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://soapinterop.org/store2">
15+
<xsd:complexType name="Store">
16+
<xsd:sequence>
17+
<element minOccurs="1" maxOccurs="1" name="Attribute2" type="string"/>
18+
</xsd:sequence>
19+
</xsd:complexType>
20+
</schema>
21+
</types>
22+
</definitions>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<definitions
3+
xmlns="http://schemas.xmlsoap.org/wsdl/"
4+
xmlns:tns="http://soapinterop.org/"
5+
targetNamespace="http://soapinterop.org/">
6+
<types>
7+
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://soapinterop.org/store1">
8+
<xsd:complexType name="Store">
9+
<xsd:sequence>
10+
<element minOccurs="1" maxOccurs="1" name="Attribute1" type="string"/>
11+
</xsd:sequence>
12+
</xsd:complexType>
13+
</schema>
14+
</types>
15+
</definitions>

0 commit comments

Comments
 (0)