-
-
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.
Prefix attribute type-names with parent type name.
- Loading branch information
Showing
7 changed files
with
149 additions
and
6 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
52 changes: 52 additions & 0 deletions
52
src/Metadata/Converter/Types/Detector/AttributeDeclaringParentTypeDetector.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,52 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soap\WsdlReader\Metadata\Converter\Types\Detector; | ||
|
||
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeContainer; | ||
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem; | ||
use GoetasWebservices\XML\XSDReader\Schema\Item; | ||
use GoetasWebservices\XML\XSDReader\Schema\SchemaItem; | ||
use GoetasWebservices\XML\XSDReader\Schema\Type\Type; | ||
use Psl\Option\Option; | ||
use function Psl\Option\none; | ||
use function Psl\Option\some; | ||
|
||
final class AttributeDeclaringParentTypeDetector | ||
{ | ||
/** | ||
* This class detects the declaring parent type of an attribute. | ||
* It can be used together with the ParentContext and works as followed | ||
* | ||
* - If the parent is an AttributeContainer, it will check if the parent has the attribute | ||
* - If the parent is not declaring the attribute, it will check if the parent is extending another type and test this extended type. | ||
* | ||
* @return Option<Type> | ||
*/ | ||
public function __invoke(AttributeItem $item, ?SchemaItem $parent): Option | ||
{ | ||
$parent = match(true) { | ||
$parent instanceof Item => $parent->getType(), | ||
default => $parent, | ||
}; | ||
|
||
if (!$parent instanceof Type) { | ||
return none(); | ||
} | ||
|
||
if ($parent instanceof AttributeContainer) { | ||
foreach ($parent->getAttributes() as $parentAttribute) { | ||
if ($parentAttribute->getName() === $item->getName()) { | ||
/** @var Option<Type> */ | ||
return some($parent); | ||
} | ||
} | ||
} | ||
|
||
$extensionBase = $parent->getExtension()?->getBase(); | ||
if ($extensionBase) { | ||
return $this->__invoke($item, $extensionBase); | ||
} | ||
|
||
return none(); | ||
} | ||
} |
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,13 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soap\WsdlReader\Metadata\Converter\Types; | ||
|
||
use GoetasWebservices\XML\XSDReader\Schema\SchemaItem; | ||
|
||
final class ParentContext | ||
{ | ||
public function __construct( | ||
public readonly SchemaItem $item, | ||
) { | ||
} | ||
} |
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
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,32 @@ | ||
--TEST-- | ||
SOAP XML Schema 1001: Prepend element name before attribute type names for more unique type-names. | ||
--FILE-- | ||
<?php | ||
include __DIR__."/test_schema.inc"; | ||
$schema = <<<EOF | ||
<complexType name="VehicleCoreType"> | ||
<sequence> | ||
<element name="VehType" minOccurs="0" type="string" /> | ||
</sequence> | ||
<attribute name="DriveType" use="optional"> | ||
<simpleType> | ||
<restriction base="NMTOKEN"> | ||
<enumeration value="AWD" /> | ||
<enumeration value="4WD" /> | ||
<enumeration value="Unspecified" /> | ||
</restriction> | ||
</simpleType> | ||
</attribute> | ||
</complexType> | ||
EOF; | ||
test_schema($schema,'type="tns:VehicleCoreType"'); | ||
?> | ||
--EXPECT-- | ||
Methods: | ||
> test(VehicleCoreType $testParam): void | ||
|
||
Types: | ||
> http://test-uri/:VehicleCoreType { | ||
?string $VehType | ||
@?VehicleCoreTypeDriveType in (AWD|4WD|Unspecified) $DriveType | ||
} |