-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from veewee/any
Read <any /> element information
- Loading branch information
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Metadata/Converter/Types/Configurator/AnyElementConfigurator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|