Skip to content

Commit

Permalink
Parse additional XML type information that can be used for encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Jan 26, 2024
1 parent 1b1b8b0 commit 59db2a2
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 34 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"ext-dom": "*",
"goetas-webservices/xsd-reader": "^0.4.1",
"php-soap/engine": "^2.4",
"php-soap/engine": "^2.6",
"php-soap/wsdl": "^1.4",
"veewee/xml": "^2.6",
"azjezz/psl": "^2.4",
Expand Down
8 changes: 8 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@
<pluginClass class="Psl\Psalm\Plugin"/>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins>
<issueHandlers>
<!-- Using implicit casting quite often here. For now lets disable the rule 'til someone finds time to fix this. -->
<RiskyTruthyFalsyComparison>
<errorLevel type="suppress">
<directory name="src/Metadata/" />
</errorLevel>
</RiskyTruthyFalsyComparison>
</issueHandlers>
</psalm>
4 changes: 2 additions & 2 deletions src/Formatter/LongTypeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function __invoke(Type $type): string
)->unwrapOr(null);

$declaration = [
$type->getXsdType()->getXmlNamespace() . ':'.$type->getName(),
$extension ? ' extends '.$extension : '',
$type->getXsdType()->getXmlTargetNamespace() . ':'.$type->getName(),
$extension !== null ? ' extends '.$extension : '',
(new EnumFormatter())($type->getXsdType()),
(new UnionFormatter())($type->getXsdType()),
$hasProps ? ' {' : '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __invoke(EngineType $engineType, mixed $xsdType, TypesConverterC
}

return pipe(
static fn (EngineType $engineType): EngineType => (new NamespaceConfigurator())($engineType, $xsdType, $context),
static fn (EngineType $engineType): EngineType => (new XmlTypeInfoConfigurator())($engineType, $xsdType, $context),
static fn (EngineType $engineType): EngineType => (new DocsConfigurator())($engineType, $xsdType, $context),
static fn (EngineType $engineType): EngineType => (new AttributeSingleConfigurator())($engineType, $xsdType, $context),
static fn (EngineType $engineType): EngineType => (new AbstractAttributeItemConfigurator())($engineType, $xsdType, $context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __invoke(EngineType $engineType, mixed $element, TypesConverterC
static fn (TypeMeta $meta): TypeMeta => $meta->withIsElement(true)
),
static fn (EngineType $engineType): EngineType => (new TypeConfigurator())($engineType, $xsdType, $context),
static fn (EngineType $engineType): EngineType => (new NamespaceConfigurator())($engineType, $element, $context),
static fn (EngineType $engineType): EngineType => (new XmlTypeInfoConfigurator())($engineType, $element, $context),
static fn (EngineType $engineType): EngineType => (new DocsConfigurator())($engineType, $element, $context),
static fn (EngineType $engineType): EngineType => (new DefaultConfigurator())($engineType, $element, $context),
static fn (EngineType $engineType): EngineType => (new FixedConfigurator())($engineType, $element, $context),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __invoke(MetaType $metaType, mixed $xsdType, TypesConverterConte
}

return pipe(
static fn (MetaType $metaType): MetaType => (new NamespaceConfigurator())($metaType, $xsdType, $context),
static fn (MetaType $metaType): MetaType => (new XmlTypeInfoConfigurator())($metaType, $xsdType, $context),
static fn (MetaType $metaType): MetaType => (new DocsConfigurator())($metaType, $xsdType, $context),
static fn (MetaType $metaType): MetaType => (new RestrictionsConfigurator())($metaType, $xsdType, $context),
static fn (MetaType $metaType): MetaType => (new AbstractConfigurator())($metaType, $xsdType, $context),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);

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

use GoetasWebservices\XML\XSDReader\Schema\Item;
use GoetasWebservices\XML\XSDReader\Schema\SchemaItem;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;
use Soap\Engine\Metadata\Model\XsdType as EngineType;
use Soap\WsdlReader\Metadata\Converter\Types\TypesConverterContext;

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

$item = $xsdType instanceof Item ? $xsdType : null;
$type = $xsdType instanceof Type ? $xsdType : $item?->getType();

$itemName = $item?->getName() ?: $type?->getName();
$typeName = $type?->getName() ?? '';
$targetNamespace = $xsdType->getSchema()->getTargetNamespace() ?? '';
$typeNamespace = $type?->getSchema()->getTargetNamespace() ?: $targetNamespace;

return $engineType
->withXmlTargetNodeName($itemName ?: $typeName)
->withXmlTypeName($typeName)
->withXmlNamespace($typeNamespace)
->withXmlNamespaceName(
$context->knownNamespaces->lookupNameFromNamespace($typeNamespace)->unwrapOr(
$engineType->getXmlNamespaceName()
)
)
->withXmlTargetNamespace($targetNamespace)
->withXmlTargetNamespaceName(
$context->knownNamespaces->lookupNameFromNamespace($targetNamespace)->unwrapOr(
$engineType->getXmlNamespaceName()
)
);
}
}

0 comments on commit 59db2a2

Please sign in to comment.