marekskopal/cycle-decimal

支持 Cycle ORM 的 ext-decimal PHP 扩展的十进制类型

v0.3.0 2024-03-20 21:05 UTC

This package is auto-updated.

Last update: 2024-09-20 22:20:28 UTC


README

支持 Cycle ORM 的 ext-decimal PHP 扩展的十进制类型。

安装

composer require marekskopal/cycle-decimal

使用

DecimalTypecast 添加到您的实体类型转换列表中,并在实体中使用十进制类型。

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\ORM\Parser\Typecast;
use Decimal\Decimal;
use MarekSkopal\Cycle\Decimal\ColumnDecimal;
use MarekSkopal\Cycle\Decimal\DecimalTypecast;

#[Entity(
    typecast: [
        Typecast::class,
        DecimalTypecast::class,
    ]
)]
class MyEntity
{
    #[Column(type: 'decimal(8,2)', typecast: DecimalTypecast::Type)]
    public Decimal $value;
    
    #[Column(type: 'decimal(8,2)', typecast: 'decimal(8,2)')]
    public Decimal $valueWithPrecision;
    
    #[ColumnDecimal(precision: 8, scale: 2)]
    public Decimal $valueWithAttribute;
}