Skip to content

Commit

Permalink
Make it possible for wsdl:import tags to directly import XSD items.
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed May 17, 2024
1 parent 467e771 commit 4a36ef7
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Loader/StreamWrapperLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public function __construct($context = null)
{
$this->context = $context;
}

public function __invoke(string $location): string
{
try {
$content = file_get_contents(
$content = @file_get_contents(
$location,
context: is_resource($this->context) ? $this->context : null
);
Expand Down
23 changes: 21 additions & 2 deletions src/Xml/Configurator/FlattenWsdlImports.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
use Soap\Wsdl\Exception\UnloadableWsdlException;
use Soap\Wsdl\Loader\Context\FlatteningContext;
use Soap\Wsdl\Uri\IncludePathBuilder;
use Soap\Xml\Xmlns;
use Soap\Xml\Xpath\WsdlPreset;
use VeeWee\Xml\Dom\Configurator\Configurator;
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Exception\RuntimeException;
use function VeeWee\Xml\Dom\Locator\document_element;
use function VeeWee\Xml\Dom\Locator\Node\children;
use function VeeWee\Xml\Dom\Manipulator\Node\append_external_node;
use function VeeWee\Xml\Dom\Manipulator\Node\remove;
use function VeeWee\Xml\Dom\Manipulator\Node\replace_by_external_nodes;

Expand Down Expand Up @@ -66,11 +68,28 @@ private function importWsdlImportElement(DOMElement $import): void
}

$imported = Document::fromXmlString($result);
$definitions = $imported->map(document_element());

// A wsdl:import can be either a WSDL or an XSD file:
match ($imported->locateDocumentElement()->namespaceURI) {
Xmlns::xsd()->value() => $this->importXsdPart($import, $imported),
default => $this->importWsdlPart($import, $imported),
};
}

private function importWsdlPart(DOMElement $importElement, Document $importedDocument): void
{
$definitions = $importedDocument->map(document_element());

replace_by_external_nodes(

Check failure on line 83 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:83:9: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)

Check failure on line 83 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:83:9: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)

Check failure on line 83 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:83:9: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)
$import,
$importElement,
children($definitions)
);
}

private function importXsdPart(DOMElement $importElement, Document $importedDocument): void
{
$types = $this->context->types();

Check failure on line 91 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:91:34: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)

Check failure on line 91 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:91:34: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)

Check failure on line 91 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:91:34: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)
remove($importElement);

Check failure on line 92 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:92:9: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)

Check failure on line 92 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:92:9: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)

Check failure on line 92 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:92:9: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)
append_external_node($types, $importedDocument->locateDocumentElement());

Check failure on line 93 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:93:9: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)

Check failure on line 93 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:93:9: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)

Check failure on line 93 in src/Xml/Configurator/FlattenWsdlImports.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 @ ubuntu-latest

MissingThrowsDocblock

src/Xml/Configurator/FlattenWsdlImports.php:93:9: MissingThrowsDocblock: VeeWee\Xml\Exception\RuntimeException is thrown but not caught - please either catch or add a @throws annotation (see https://psalm.dev/169)
}
}
8 changes: 8 additions & 0 deletions tests/Unit/Xml/Configurator/FlattenWsdlImportsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@ public function provideTestCases()
'wsdl' => FIXTURE_DIR.'/flattening/multi-import.wsdl',
'expected' => Document::fromXmlFile(FIXTURE_DIR.'/flattening/result/multi-import-result.wsdl', comparable()),
];
yield 'xsd-imports' => [
'wsdl' => FIXTURE_DIR.'/flattening/import-xsd.wsdl',
'expected' => Document::fromXmlFile(FIXTURE_DIR.'/flattening/result/import-xsd-result.wsdl', comparable()),
];
yield 'multi-xsd-imports' => [
'wsdl' => FIXTURE_DIR.'/flattening/import-multi-xsd.wsdl',
'expected' => Document::fromXmlFile(FIXTURE_DIR.'/flattening/result/import-multi-xsd-result.wsdl', comparable()),
];
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/flattening/import-multi-xsd.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://soapinterop.org/"
targetNamespace="http://soapinterop.org/">
<import namespace="http://soapinterop.org/store1" location="xsd/store1.xsd" />
<import namespace="http://soapinterop.org/store2" location="xsd/store2.xsd" />
</definitions>
7 changes: 7 additions & 0 deletions tests/fixtures/flattening/import-xsd.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://soapinterop.org/"
targetNamespace="http://soapinterop.org/">
<import namespace="http://soapinterop.org/store1" location="xsd/store1.xsd" />
</definitions>
22 changes: 22 additions & 0 deletions tests/fixtures/flattening/result/import-multi-xsd-result.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://soapinterop.org/"
targetNamespace="http://soapinterop.org/">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://soapinterop.org/store1">
<xsd:complexType name="Store">
<xsd:sequence>
<element minOccurs="1" maxOccurs="1" name="Attribute1" type="string"/>
</xsd:sequence>
</xsd:complexType>
</schema>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://soapinterop.org/store2">
<xsd:complexType name="Store">
<xsd:sequence>
<element minOccurs="1" maxOccurs="1" name="Attribute2" type="string"/>
</xsd:sequence>
</xsd:complexType>
</schema>
</types>
</definitions>
15 changes: 15 additions & 0 deletions tests/fixtures/flattening/result/import-xsd-result.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://soapinterop.org/"
targetNamespace="http://soapinterop.org/">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://soapinterop.org/store1">
<xsd:complexType name="Store">
<xsd:sequence>
<element minOccurs="1" maxOccurs="1" name="Attribute1" type="string"/>
</xsd:sequence>
</xsd:complexType>
</schema>
</types>
</definitions>

0 comments on commit 4a36ef7

Please sign in to comment.