guikingone/symfony-uid-doctrine 问题修复 & 功能扩展

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

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

guikingone/symfony-uid-doctrine

最新稳定版本:0.1.1

Composer 安装命令:

composer require guikingone/symfony-uid-doctrine

包简介

Allow the use of symfony/uid as Doctrine field type

README 文档

README

SymfonyUidDoctrine SymfonyUidDoctrine - Configuration

The guikingone/symfony-uid-doctrine aim to provide the support of Symfony/Uid as a Doctrine type.

Installation

Consider using Packagist and Composer when installing the following project:

composer require guikingone/symfony-uid-doctrine

Configuration

Uuid

Doctrine\DBAL\Types\Type::addType('uuid', Guikingone\SymfonyUid\Doctrine\Uuid\UuidType::class);
# config/packages/doctrine.yaml
doctrine:
    dbal:
        types:
            uuid: Guikingone\SymfonyUid\Doctrine\Uuid\UuidType

Ulid

Doctrine\DBAL\Types\Type::addType('ulid', Guikingone\SymfonyUid\Doctrine\Ulid\UlidType::class);
# config/packages/doctrine.yaml
doctrine:
    dbal:
        types:
            ulid: Guikingone\SymfonyUid\Doctrine\Ulid\UlidType

Usage

Uuid

use Doctrine\ORM\Mapping as ORM;
use Guikingone\SymfonyUid\Doctrine\Uuid\UuidGenerator;

/**
 * @ORM\Entity
 * @ORM\Table(name="posts")
 */
class Post
{
    /**
     * @var Symfony\Component\Uid\Uuid
     *
     * @ORM\Id
     * @ORM\Column(type="uuid", unique=true)
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\CustomIdGenerator(class=UuidGenerator::class)
     */
    protected $id;

    public function getId(): Uuid
    {
        return $this->id;
    }
}

If you don't want to use the generator, consider using the __construct() method:

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;

/**
 * @ORM\Entity
 * @ORM\Table(name="posts")
 */
class Post
{
    /**
     * @var Symfony\Component\Uid\Uuid
     *
     * @ORM\Id
     * @ORM\Column(type="uuid", unique=true)
     */
    protected $id;

    public function __construct() 
    {
        $this->id = Uuid::v4();
    }

    public function getId(): Uuid
    {
        return $this->id;
    }
}

Ulid

use Doctrine\ORM\Mapping as ORM;
use Guikingone\SymfonyUid\Doctrine\Ulid\UlidGenerator;

/**
 * @ORM\Entity
 * @ORM\Table(name="posts")
 */
class Post
{
    /**
     * @var Symfony\Component\Uid\Ulid
     *
     * @ORM\Id
     * @ORM\Column(type="ulid", unique=true)
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\CustomIdGenerator(class=UlidGenerator::class)
     */
    protected $id;

    public function getId(): Ulid
    {
        return $this->id;
    }
}

If you don't want to use the generator, consider using the __construct() method:

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Ulid;

/**
 * @ORM\Entity
 * @ORM\Table(name="posts")
 */
class Post
{
    /**
     * @var Symfony\Component\Uid\Ulid
     *
     * @ORM\Id
     * @ORM\Column(type="ulid", unique=true)
     */
    protected $id;

    public function __construct() 
    {
        $this->id = new Ulid();
    }

    public function getId(): Ulid
    {
        return $this->id;
    }
}

Contributing

Contributions are welcome! Please read CONTRIBUTING for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固