Skip to content

Commit 4b54ed4

Browse files
authored
Merge pull request #39 from veewee/any
Read <any /> element information
2 parents 8e809c3 + a1d3e03 commit 4b54ed4

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"require": {
1616
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
1717
"ext-dom": "*",
18-
"goetas-webservices/xsd-reader": "^0.4.6",
18+
"goetas-webservices/xsd-reader": "^0.4.8",
1919
"php-soap/engine": "^2.13",
2020
"php-soap/wsdl": "^1.10",
2121
"php-soap/xml": "^1.8.0",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Soap\WsdlReader\Metadata\Converter\Types\Configurator;
4+
5+
use GoetasWebservices\XML\XSDReader\Schema\Element\Any\Any;
6+
use Soap\Engine\Metadata\Model\TypeMeta;
7+
use Soap\Engine\Metadata\Model\XsdType as EngineType;
8+
use Soap\Engine\Metadata\Model\XsdType as MetaType;
9+
use Soap\WsdlReader\Metadata\Converter\Types\TypesConverterContext;
10+
use Soap\Xml\Xmlns;
11+
use function Psl\Fun\pipe;
12+
13+
final class AnyElementConfigurator
14+
{
15+
public function __invoke(EngineType $engineType, mixed $xsdType, TypesConverterContext $context): EngineType
16+
{
17+
if (!$xsdType instanceof Any) {
18+
return $engineType;
19+
}
20+
21+
$xsd = Xmlns::xsd()->value();
22+
$targetNamespace = $xsdType->getSchema()->getTargetNamespace() ?? '';
23+
24+
$configure = pipe(
25+
static fn (MetaType $metaType): MetaType => (new DocsConfigurator())($metaType, $xsdType, $context),
26+
static fn (MetaType $metaType): MetaType => (new OccurrencesConfigurator())($metaType, $xsdType, $context),
27+
);
28+
29+
return $configure(
30+
$engineType
31+
->withXmlTargetNodeName('any')
32+
->withXmlTypeName('any')
33+
->withBaseType('anyXML')
34+
->withXmlNamespace($xsd)
35+
->withXmlNamespaceName($context->knownNamespaces->lookupNameFromNamespace($xsd)->unwrapOr('xsd'))
36+
->withXmlTargetNamespace($targetNamespace)
37+
->withXmlTargetNamespaceName(
38+
$context->knownNamespaces->lookupNameFromNamespace($targetNamespace)->unwrapOr(
39+
$engineType->getXmlNamespaceName()
40+
)
41+
)
42+
->withMeta(
43+
static fn (TypeMeta $meta): TypeMeta => $meta
44+
->withRestriction([
45+
'processXMLContent' => [
46+
['value' => $xsdType->getProcessContents()->value],
47+
]
48+
])
49+
->withIsElement(true)
50+
)
51+
);
52+
}
53+
}

src/Metadata/Converter/Types/Visitor/ElementContainerVisitor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private function parseElementItem(ElementItem $element, TypesConverterContext $c
3939
$typeName = $type?->getName() ?: $element->getName();
4040
$configure = pipe(
4141
static fn (EngineType $engineType): EngineType => (new Configurator\ElementConfigurator())($engineType, $element, $context),
42+
static fn (EngineType $engineType): EngineType => (new Configurator\AnyElementConfigurator())($engineType, $element, $context),
4243
);
4344

4445
return new PropertyCollection(
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
SOAP XML Schema 1001: Any elements
3+
--FILE--
4+
<?php
5+
include __DIR__."/test_schema.inc";
6+
$schema = <<<EOF
7+
<element name="GetCustomerDetailsRequest">
8+
<complexType>
9+
<sequence>
10+
<element name="customerId" type="xsd:string" />
11+
<element name="countryCode" type="xsd:string" nillable="true" />
12+
<any processContents="strict" maxOccurs="0" />
13+
</sequence>
14+
</complexType>
15+
</element>
16+
EOF;
17+
test_schema($schema,'type="tns:GetCustomerDetailsRequest"');
18+
?>
19+
--EXPECT--
20+
Methods:
21+
> test(GetCustomerDetailsRequest $testParam): void
22+
23+
Types:
24+
> http://test-uri/:GetCustomerDetailsRequest {
25+
string $customerId
26+
?string $countryCode
27+
any $any
28+
}
29+

0 commit comments

Comments
 (0)