amacode / property-info-override
Wrapper for symfony PropertyInfo component which returns user-defined property info if set
1.0.1
2023-01-23 15:48 UTC
Requires
- php: >=7.4
- koriym/attributes: ^1.0
- symfony/config: >=4
- symfony/dependency-injection: >=4
- symfony/http-kernel: >=4
- symfony/property-info: >=4
Requires (Dev)
- ext-json: *
- phpunit/phpcov: ^8.2
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^7.2
- symfony/browser-kit: >=4
- symplify/easy-coding-standard: ^10.2
README
Overview
This package is an extension for PropertyInfo component.
Sometimes the default PropertyInfoExtractor
defines the property meta info not the way you want. It may break you API schema generation or requests validations (is actual for ApiPlatform).
This package allows you to override a property type meta info which can be used by 3rd party libraries if it had been defined incorrectly (see usage example below).
Installation
composer require amacode/property-info-override
Usage
Add PropertyType
annotation/attribute to property where type is defined incorrectly by PropertyInfoExtractor
<?php declare(strict_types=1); namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Amacode\PropertyInfoOverride\Annotation\PropertyType; /** * @ORM\Entity() */ class TestEntity { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * By default, bigint will be defined as string by DoctrineExtractor because it can be bigger than PHP_INT_MAX in 32-bit systems. * But if you're sure that your bigint will always be less than PHP_INT_MAX, you can override type manually. * * @PropertyType(type="int") * * @ORM\Column(type="bigint") */ private $bigIntAsInt; /** * @ORM\Column(type="bigint") */ private $bigIntAsString; }
Client code
<?php class ClientCode { private PropertyInfoExtractorInterface $propertyInfoExtractor; public function __construct(PropertyInfoExtractorInterface $propertyInfoExtractor) { $this->propertyInfoExtractor = $propertyInfoExtractor; } public function action(): void { $types = $this->propertyInfoExtractor->getTypes(TestEntity::class, 'bigIntAsInt'); echo $types[0]->getBuiltinType(); // int $types = $this->propertyInfoExtractor->getTypes(TestEntity::class, 'bigIntAsString'); echo $types[0]->getBuiltinType(); // string } }