承接 gusarov112/php-enum-doctrine 相关项目开发

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

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

gusarov112/php-enum-doctrine

Composer 安装命令:

composer require gusarov112/php-enum-doctrine

包简介

Allows to add you custom php enums as doctrine type

README 文档

README

  • Allows to add you custom php enums as doctrine type.
  • Supports generation of correct alter SQL when updating enum values.

Extension for php-enum (myclabs fork)

Installation

Than require package

composer require gusarov112/php-enum-doctrine

Symfony configuration

  Gusarov112\PhpEnumDoctrine\EventListener\EnumUpdaterSubscriber:
    tags:
      - { name: doctrine.event_subscriber }

Example

Create enum

class PetEnum extends \Gusarov112\Enum\Enum
{
    const CAT = 'CAT';
    const DOG = 'DOG';
}

Create corresponding enum type by extending abstract type

class PetType extends \Gusarov112\PhpEnumDoctrine\DBAL\EnumType
{
    public function getEnumClassName(): string
    {
        return PetEnum::class;
    }

    public function getName()
    {
        return 'pet_type';
    }
}

Use your column type in doctrine entity

use Doctrine\ORM\Mapping as ORM;

class PetEntity {
    /**
     * @var PetEnum
     * @ORM\Column(type="pet_type")
     */
    private $type;

    public function getType(): PetEnum
    {
        return $this->type;
    }

    public function setType(PetEnum $type): self
    {
        $this->type = $type;

        return $this;
    }
}

Do not forger to register your type

\Doctrine\DBAL\Types\Type::addType('pet_type', PetType::class);

Add event subscriber if you have migrations bundle and want to autogenerate enum list alter SQL's

$eventManager = new \Doctrine\Common\EventManager();
$eventManager->addEventSubscriber(new \Gusarov112\PhpEnumDoctrine\EventListener\EnumUpdaterSubscriber());

#!/bin/bash ./vendor/bin/doctrine migrations:diff

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固