amacode/property-info-override 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

amacode/property-info-override

最新稳定版本:1.0.1

Composer 安装命令:

composer require amacode/property-info-override

包简介

Wrapper for symfony PropertyInfo component which returns user-defined property info if set

README 文档

README

Packagist Version GitHub Workflow Status Codecov GitHub

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
    }
}

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-22