fasano/phprimitives-doctrine 问题修复 & 功能扩展

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

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

fasano/phprimitives-doctrine

最新稳定版本:1.0.0

Composer 安装命令:

composer require fasano/phprimitives-doctrine

包简介

Doctrine extension for PHPrimitives.

README 文档

README

A set of Doctrine DBAL types to map any PHPrimitive with almost no boilerplate.

Installation

composer require fasano/phprimitives-doctrine

Creating a Custom Type

Extend the abstract type that matches your primitive's scalar type, then implement two methods:

use Fasano\PHPrimitives\Doctrine\StringPrimitiveType;

final class EmailType extends StringPrimitiveType
{
    public function getName(): string
    {
        return 'email';
    }

    protected function getPrimitiveClass(): string
    {
        return Email::class;
    }
}

Registering Types

Register your custom types, as usual:

use Doctrine\DBAL\Types\Type;

Type::addType('email', EmailType::class);
Type::addType('age',   AgeType::class);
Type::addType('status', StatusType::class);

Symfony — register via config/packages/doctrine.yaml instead:

doctrine:
    dbal:
        types:
            email:  Infra\Doctrine\Type\EmailType
            age:    Infra\Doctrine\Type\AgeType
            status: Infra\Doctrine\Type\StatusType

Using The Types

Reference the type name in your #[Column] attribute:

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class User
{
    #[ORM\Column(type: 'email')]
    public Email $email;

    #[ORM\Column(type: 'age')]
    public Age $age;

    #[ORM\Column(type: 'status')]
    public Status $status;
}

Doctrine will call construct() when hydrating from the database and deconstruct() when persisting, so your domain invariants are enforced on every read and write.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固