Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read <any /> element information #39

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require": {
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
"ext-dom": "*",
"goetas-webservices/xsd-reader": "^0.4.6",
"goetas-webservices/xsd-reader": "^0.4.8",
"php-soap/engine": "^2.13",
"php-soap/wsdl": "^1.10",
"php-soap/xml": "^1.8.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php declare(strict_types=1);

namespace Soap\WsdlReader\Metadata\Converter\Types\Configurator;

use GoetasWebservices\XML\XSDReader\Schema\Element\Any\Any;
use Soap\Engine\Metadata\Model\TypeMeta;
use Soap\Engine\Metadata\Model\XsdType as EngineType;
use Soap\Engine\Metadata\Model\XsdType as MetaType;
use Soap\WsdlReader\Metadata\Converter\Types\TypesConverterContext;
use Soap\Xml\Xmlns;
use function Psl\Fun\pipe;

final class AnyElementConfigurator
{
public function __invoke(EngineType $engineType, mixed $xsdType, TypesConverterContext $context): EngineType
{
if (!$xsdType instanceof Any) {
return $engineType;
}

$xsd = Xmlns::xsd()->value();
$targetNamespace = $xsdType->getSchema()->getTargetNamespace() ?? '';

$configure = pipe(
static fn (MetaType $metaType): MetaType => (new DocsConfigurator())($metaType, $xsdType, $context),
static fn (MetaType $metaType): MetaType => (new OccurrencesConfigurator())($metaType, $xsdType, $context),
);

return $configure(
$engineType
->withXmlTargetNodeName('any')
->withXmlTypeName('any')
->withBaseType('anyXML')
->withXmlNamespace($xsd)
->withXmlNamespaceName($context->knownNamespaces->lookupNameFromNamespace($xsd)->unwrapOr('xsd'))
->withXmlTargetNamespace($targetNamespace)
->withXmlTargetNamespaceName(
$context->knownNamespaces->lookupNameFromNamespace($targetNamespace)->unwrapOr(
$engineType->getXmlNamespaceName()
)
)
->withMeta(
static fn (TypeMeta $meta): TypeMeta => $meta
->withRestriction([
'processXMLContent' => [
['value' => $xsdType->getProcessContents()->value],
]
])
->withIsElement(true)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private function parseElementItem(ElementItem $element, TypesConverterContext $c
$typeName = $type?->getName() ?: $element->getName();
$configure = pipe(
static fn (EngineType $engineType): EngineType => (new Configurator\ElementConfigurator())($engineType, $element, $context),
static fn (EngineType $engineType): EngineType => (new Configurator\AnyElementConfigurator())($engineType, $element, $context),
);

return new PropertyCollection(
Expand Down
29 changes: 29 additions & 0 deletions tests/PhpCompatibility/schema1012.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
SOAP XML Schema 1001: Any elements
--FILE--
<?php
include __DIR__."/test_schema.inc";
$schema = <<<EOF
<element name="GetCustomerDetailsRequest">
<complexType>
<sequence>
<element name="customerId" type="xsd:string" />
<element name="countryCode" type="xsd:string" nillable="true" />
<any processContents="strict" maxOccurs="0" />
</sequence>
</complexType>
</element>
EOF;
test_schema($schema,'type="tns:GetCustomerDetailsRequest"');
?>
--EXPECT--
Methods:
> test(GetCustomerDetailsRequest $testParam): void

Types:
> http://test-uri/:GetCustomerDetailsRequest {
string $customerId
?string $countryCode
any $any
}

Loading