marekskopal/orm-decimal
Composer 安装命令:
composer require marekskopal/orm-decimal
包简介
Decimal type from ext-decimal PHP extension mapper for MarekSkopal ORM.
关键字:
README 文档
README
Decimal\Decimal type mapper for marekskopal/orm, powered by the ext-decimal PHP extension. Handles precise decimal arithmetic without floating-point rounding errors — ideal for monetary values and other exact numeric data.
Requirements
- PHP >= 8.4
ext-decimalPHP extensionmarekskopal/orm^1.0
Installation
composer require marekskopal/orm-decimal
The
ext-decimalextension must be installed separately. See php-decimal.io for installation instructions.
Usage
Apply the #[ColumnDecimal] attribute to a Decimal property on your ORM entity. The precision and scale parameters map directly to the SQL DECIMAL(precision, scale) column type.
use Decimal\Decimal; use MarekSkopal\ORM\Attribute\Entity; use MarekSkopal\ORM\Decimal\Attribute\ColumnDecimal; #[Entity] class Product { #[ColumnDecimal(precision: 8, scale: 2)] public Decimal $price; #[ColumnDecimal(precision: 10, scale: 4, nullable: true)] public ?Decimal $discount; }
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
precision |
int |
yes | Total number of significant digits (must be > 0) |
scale |
int |
yes | Digits after the decimal point (must be < precision) |
name |
string |
no | Override the database column name |
nullable |
bool |
no | Allow null values (default: false) |
How It Works
ColumnDecimal— a PHP attribute that extends the ORM'sColumnattribute withType::Decimaland registersDecimalMapperas its value handler.DecimalMapper— implementsMapperInterface, converting database strings toDecimal\Decimalobjects on read (mapToProperty) and back to strings on write (mapToColumn).
License
MIT — see LICENSE.
统计信息
- 总下载量: 593
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-07