承接 marekskopal/orm-decimal 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

marekskopal/orm-decimal

Composer 安装命令:

composer require marekskopal/orm-decimal

包简介

Decimal type from ext-decimal PHP extension mapper for MarekSkopal ORM.

README 文档

README

PHP License

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

Installation

composer require marekskopal/orm-decimal

The ext-decimal extension 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's Column attribute with Type::Decimal and registers DecimalMapper as its value handler.
  • DecimalMapper — implements MapperInterface, converting database strings to Decimal\Decimal objects on read (mapToProperty) and back to strings on write (mapToColumn).

License

MIT — see LICENSE.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固