定制 ufo-tech/doctrine-helper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ufo-tech/doctrine-helper

最新稳定版本:1.1.0

Composer 安装命令:

composer require ufo-tech/doctrine-helper

包简介

A set of ready-made solutions for Doctrine (traits, interfaces, classes) that allows you to get rid of routine and speeds up development

README 文档

README

A set of ready-made solutions for Doctrine (traits, interfaces, classes) that allows you to get rid of routine and speeds up development

Documentations

Use php enum for MySQL enum type

1. Create your enum for cases for your entity field

<?php
namespace App;

enum MyEnum: string
{
    case CASE_1 = 'My case 1';
    case CASE_2 = 'My case 2';
}

2. Create DBAL class and extend Ufo\DoctrineHelper\DBAL\AbstractEnumType

<?php
namespace App\DBAL;

use BackedEnum;
use App\MyEnum;

class MyEnumType extends AbstractEnumType
{
    protected string|BackedEnum $enum = MyEnum::class;
}

3. Register new type in DBAL

doctrine:
    dbal:
        types:
            App\MyEnum: 'App\DBAL\MyEnumType'
        mapping_types:
            enum: string

4. Use your php enum for set and change value

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'demo')]
class Demo
{
    #[ORM\Column(type: MyEnum::class, nullable: false)]
    protected string $case;


    public function __construct(MyEnum $case)
    {
        $this->case = $case->value;
    }

    public function changeCase(MyEnum $case): void
    {
        $this->type = $case->value;
    }

    public function getCase(): string
    {
        return $this->case;
    }

}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固