-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the new naming logic for specifying the xml type name as well so …
…that the encoder doesnt get confused
- Loading branch information
Showing
4 changed files
with
49 additions
and
42 deletions.
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
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
34 changes: 34 additions & 0 deletions
34
src/Metadata/Converter/Types/Detector/AttributeTypeNameDetector.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,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soap\WsdlReader\Metadata\Converter\Types\Detector; | ||
|
||
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem; | ||
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeSingle; | ||
use GoetasWebservices\XML\XSDReader\Schema\Type\Type; | ||
use Psl\Option\Option; | ||
use Soap\WsdlReader\Metadata\Converter\Types\ParentContext; | ||
use function Psl\Option\from_nullable; | ||
|
||
final class AttributeTypeNameDetector | ||
{ | ||
public function __invoke(AttributeItem $attribute, ParentContext $parentContext): string | ||
{ | ||
$attributeType = $attribute instanceof AttributeSingle ? $attribute->getType() : null; | ||
$attributeRestriction = $attributeType?->getRestriction(); | ||
$attributeTypeName = $attributeType?->getName(); | ||
$attributeRestrictionName = ($attributeRestriction && !$attributeRestriction->getChecks()) ? $attributeRestriction->getBase()?->getName() : null; | ||
|
||
$typeName = $attributeTypeName ?: ($attributeRestrictionName ?: $attribute->getName()); | ||
|
||
// If a name cannot be determined from the type, we fallback to the attribute name: | ||
// Prefix the attribute name with the parent element name resulting in a more unique type-name. | ||
if (!$attributeTypeName && !$attributeRestrictionName) { | ||
$typeName = (new AttributeDeclaringParentTypeDetector())($attribute, $parentContext->currentParent()) | ||
->andThen(static fn (Type $parent): Option => from_nullable($parent->getName())) | ||
->map(static fn (string $parentName): string => $parentName . ucfirst($typeName)) | ||
->unwrapOr($typeName); | ||
} | ||
|
||
return $typeName; | ||
} | ||
} |
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