Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

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

use GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementRef;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle;
use Soap\Engine\Metadata\Model\TypeMeta;
use Soap\Engine\Metadata\Model\XsdType as EngineType;
Expand All @@ -17,7 +19,11 @@ public function __invoke(EngineType $engineType, mixed $xsdType, TypesConverterC
}

// Elements can have inline types. Mark the attribute as a local type in that case.
$innerType = $xsdType->getType();
$innerType = match (true) {
$xsdType instanceof ElementDef,
$xsdType instanceof ElementRef => null,
default => $xsdType->getType(),
};
$isConsideredAnInlineType = $innerType && $innerType->getName() === null;
if ($isConsideredAnInlineType) {
$engineType = $engineType->withMeta(
Expand Down
34 changes: 24 additions & 10 deletions src/Metadata/Converter/Types/Detector/ElementTypeNameDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

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

use GoetasWebservices\XML\XSDReader\Schema\Element\Any\Any;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementItem;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementRef;
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle;
use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;
use Soap\WsdlReader\Metadata\Converter\Types\ParentContext;

Expand All @@ -14,18 +15,31 @@ public function __invoke(ElementItem $element, ParentContext $parentContext, ?st
{
$type = $element instanceof ElementSingle ? $element->getType() : null;
$typeName = $calculatedTypeName ?? ($type?->getName() ?: $element->getName());
$rootParent = $parentContext->rootParent();

// For inline simple types, we prefix the name of the element with the name of the parent type.
if ($type instanceof SimpleType && !$type->getName()) {
$parent = $parentContext->currentParent();
// Add some conditions to validate if the element type name should be modified:
if (
$rootParent === $element // Dont enhance yourself
|| $element instanceof Any // Any types are just objects. 'any' is a proper name here.
|| $element instanceof ElementRef // Refs already have a proper name
|| $type?->getName() // Named types already have a proper name
) {
return $typeName;
}

// Make sure the root parent has a name:
if (
!$rootParent instanceof Type
&& !$rootParent instanceof ElementItem
) {
return $typeName;
}

if ($parent instanceof Type || $parent instanceof ElementItem) {
if ($parentName = $parent->getName()) {
$typeName = $parentName . ucfirst($typeName);
}
}
$rootParentName = $rootParent->getName();
if (!$rootParentName) {
return $typeName;
}

return $typeName;
return $rootParentName . ucfirst($typeName);
}
}
5 changes: 4 additions & 1 deletion src/Metadata/Converter/Types/Visitor/ElementVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Soap\Engine\Metadata\Model\Type as EngineType;
use Soap\Engine\Metadata\Model\XsdType as MetaType;
use Soap\WsdlReader\Metadata\Converter\Types\Configurator;
use Soap\WsdlReader\Metadata\Converter\Types\Detector\ElementTypeNameDetector;
use Soap\WsdlReader\Metadata\Converter\Types\TypesConverterContext;
use function Psl\Fun\pipe;

Expand Down Expand Up @@ -35,9 +36,11 @@ public function __invoke(AbstractElementSingle $element, TypesConverterContext $
static fn (MetaType $metaType): MetaType => (new Configurator\ElementConfigurator())($metaType, $element, $context),
);

$name = (new ElementTypeNameDetector())($element, $context->parent()->unwrap(), $element->getName());

return new TypeCollection(
new EngineType(
$configure(MetaType::guess($element->getName())),
$configure(MetaType::guess($name)),
(new PropertiesVisitor())($xsdType, $context)
),
...((new InlineElementTypeVisitor())($xsdType, $context))
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpCompatibility/schema036.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Methods:
Types:
> http://test-uri/:testType {
int $int
testType2 $testType2
testTypeTestType2 $testType2
}
> http://test-uri/:testType2 {
> http://test-uri/:testTypeTestType2 {
int $int
}
4 changes: 2 additions & 2 deletions tests/PhpCompatibility/schema1002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Methods:

Types:
> http://test-uri/:VoluntaryChangesType {
?Penalty $Penalty
?VoluntaryChangesTypePenalty $Penalty
@?boolean $VolChangeInd
}
> http://test-uri/:Penalty {
> http://test-uri/:VoluntaryChangesTypePenalty {
@?string $PenaltyType
@?string $DepartureStatus
}
4 changes: 2 additions & 2 deletions tests/PhpCompatibility/schema1003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Methods:

Types:
> http://test-uri/:SpecialEquipPrefs {
array<int<1, 15>, SpecialEquipPref> $SpecialEquipPref
array<int<1, 15>, SpecialEquipPrefsSpecialEquipPref> $SpecialEquipPref
}
> http://test-uri/:SpecialEquipPref {
> http://test-uri/:SpecialEquipPrefsSpecialEquipPref {
@?string $Action
}
8 changes: 4 additions & 4 deletions tests/PhpCompatibility/schema1005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ Methods:

Types:
> http://test-uri/:LoyaltyTravelInfoType {
?HotelStayInfo $HotelStayInfo
?AirFlightInfo $AirFlightInfo
?LoyaltyTravelInfoTypeHotelStayInfo $HotelStayInfo
?LoyaltyTravelInfoTypeAirFlightInfo $AirFlightInfo
}
> http://test-uri/:HotelStayInfo {
> http://test-uri/:LoyaltyTravelInfoTypeHotelStayInfo {
?string $ReservationID
}
> http://test-uri/:AirFlightInfo {
> http://test-uri/:LoyaltyTravelInfoTypeAirFlightInfo {
?string $FlightSegment
}
4 changes: 2 additions & 2 deletions tests/PhpCompatibility/schema1007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Types:
}
> http://test-uri/:VerificationType {
?string $Email
?StartLocation $StartLocation
?VerificationTypeStartLocation $StartLocation
}
> http://test-uri/:StartLocation extends LocationType {
> http://test-uri/:VerificationTypeStartLocation extends LocationType {
string $_
@?string $LocationCode
@?dateTime $AssociatedDateTime
Expand Down
50 changes: 50 additions & 0 deletions tests/PhpCompatibility/schema1016.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--TEST--
SOAP XML Schema 1016: Group ref with minOccurs / MaxOccurs
--FILE--
<?php
include __DIR__."/test_schema.inc";
$schema = <<<EOF
<complexType name="Code">
<sequence>
<element form="unqualified" name="code" type="string" />
</sequence>
</complexType>
<simpleType name="SomeSpecificTypeCodeEnum">
<restriction base="string">
<enumeration value="foo" />
<enumeration value="bar" />
</restriction>
</simpleType>
<complexType name="SomeType">
<choice>
<element name="code">
<complexType>
<complexContent>
<restriction base="tns:Code">
<sequence>
<element form="unqualified" name="code" type="tns:SomeSpecificTypeCodeEnum" />
</sequence>
</restriction>
</complexContent>
</complexType>
</element>
</choice>
</complexType>
EOF;
test_schema($schema,'type="tns:Element"');
?>
--EXPECT--
Methods:
> test(Element $testParam): void

Types:
> http://test-uri/:Code {
string $code
}
> http://test-uri/:SomeSpecificTypeCodeEnum extends string in (foo|bar)
> http://test-uri/:SomeType {
?SomeTypeCode $code
}
> http://test-uri/:SomeTypeCode extends Code {
?SomeSpecificTypeCodeEnum in (foo|bar) $code
}
Loading