Skip to content

Commit

Permalink
use class const fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Nov 4, 2024
1 parent 9b63bbb commit 038a677
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/Generator/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ private function getAttributesForDefinition(DefinitionTypeAbstract $type, array
$mapping = $type->getMapping();
if ($mapping !== null) {
foreach ($mapping as $class => $value) {
$result[] = $this->newAttribute('DerivedType', [$this->newScalar($this->normalizer->class($class)), $this->newScalar($value)], $uses);
$className = new Node\Expr\ClassConstFetch(new Node\Name($this->normalizer->class($class)), 'class');
$result[] = $this->newAttribute('DerivedType', [$className, $this->newScalar($value)], $uses);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#[Description('Base collection type')]
#[Discriminator('type')]
#[DerivedType('MapDefinitionType', 'map')]
#[DerivedType('ArrayDefinitionType', 'array')]
#[DerivedType(MapDefinitionType::class, 'map')]
#[DerivedType(ArrayDefinitionType::class, 'array')]
abstract class CollectionDefinitionType extends DefinitionType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('')]
Expand Down
6 changes: 3 additions & 3 deletions tests/Generator/resource/php/complex/DefinitionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#[Description('Base definition type')]
#[Discriminator('type')]
#[DerivedType('StructDefinitionType', 'struct')]
#[DerivedType('MapDefinitionType', 'map')]
#[DerivedType('ArrayDefinitionType', 'array')]
#[DerivedType(StructDefinitionType::class, 'struct')]
#[DerivedType(MapDefinitionType::class, 'map')]
#[DerivedType(ArrayDefinitionType::class, 'array')]
abstract class DefinitionType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?string $description = null;
Expand Down
18 changes: 9 additions & 9 deletions tests/Generator/resource/php/complex/PropertyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

#[Description('Base property type')]
#[Discriminator('type')]
#[DerivedType('StringPropertyType', 'string')]
#[DerivedType('IntegerPropertyType', 'integer')]
#[DerivedType('NumberPropertyType', 'number')]
#[DerivedType('BooleanPropertyType', 'boolean')]
#[DerivedType('MapPropertyType', 'map')]
#[DerivedType('ArrayPropertyType', 'array')]
#[DerivedType('AnyPropertyType', 'any')]
#[DerivedType('GenericPropertyType', 'generic')]
#[DerivedType('ReferencePropertyType', 'reference')]
#[DerivedType(StringPropertyType::class, 'string')]
#[DerivedType(IntegerPropertyType::class, 'integer')]
#[DerivedType(NumberPropertyType::class, 'number')]
#[DerivedType(BooleanPropertyType::class, 'boolean')]
#[DerivedType(MapPropertyType::class, 'map')]
#[DerivedType(ArrayPropertyType::class, 'array')]
#[DerivedType(AnyPropertyType::class, 'any')]
#[DerivedType(GenericPropertyType::class, 'generic')]
#[DerivedType(ReferencePropertyType::class, 'reference')]
abstract class PropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?string $description = null;
Expand Down
8 changes: 4 additions & 4 deletions tests/Generator/resource/php/complex/ScalarPropertyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

#[Description('Base scalar property type')]
#[Discriminator('type')]
#[DerivedType('StringPropertyType', 'string')]
#[DerivedType('IntegerPropertyType', 'integer')]
#[DerivedType('NumberPropertyType', 'number')]
#[DerivedType('BooleanPropertyType', 'boolean')]
#[DerivedType(StringPropertyType::class, 'string')]
#[DerivedType(IntegerPropertyType::class, 'integer')]
#[DerivedType(NumberPropertyType::class, 'number')]
#[DerivedType(BooleanPropertyType::class, 'boolean')]
abstract class ScalarPropertyType extends PropertyType implements \JsonSerializable, \PSX\Record\RecordableInterface
{
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Generator/resource/php/complex/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

#[Description('')]
#[Discriminator('type')]
#[DerivedType('SecurityHttpBasic', 'httpBasic')]
#[DerivedType('SecurityHttpBearer', 'httpBearer')]
#[DerivedType('SecurityApiKey', 'apiKey')]
#[DerivedType('SecurityOAuth', 'oauth2')]
#[DerivedType(SecurityHttpBasic::class, 'httpBasic')]
#[DerivedType(SecurityHttpBearer::class, 'httpBearer')]
#[DerivedType(SecurityApiKey::class, 'apiKey')]
#[DerivedType(SecurityOAuth::class, 'oauth2')]
abstract class Security implements \JsonSerializable, \PSX\Record\RecordableInterface
{
#[Description('The global security type of the API must be one of: httpBasic, httpBearer, apiKey or oauth2')]
Expand Down

0 comments on commit 038a677

Please sign in to comment.