承接 gubler/guid-doctrine 相关项目开发

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

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

gubler/guid-doctrine

Composer 安装命令:

composer require gubler/guid-doctrine

包简介

Use of a ramsey/uuid UUID with GUID codec as Doctrine field type.

README 文档

README

This is based off of the ramsey/uuid-doctrine project. The only thing this project does differently is return GUIDs. This to handle Active Directory GUIDs.

The gubler/guid-doctrine package provides the ability to use ramsey/uuid as a Doctrine field type.

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.

Installation

The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:

composer require gubler/guid-doctrine

Examples

Configuration

To configure Doctrine to use gubler/guid as a field type, you'll need to set up the following in your bootstrap:

\Doctrine\DBAL\Types\Type::addType('uuid', 'Gubler\Guid\Doctrine\GuidType');

In Symfony:

# config/packages/doctrine.yaml
doctrine:
   dbal:
       types:
           guid:  Gubler\Guid\Doctrine\GuidType

In Zend Framework:

<?php 
// module.config.php
use Gubler\Guid\Doctrine\GuidType;

return [
    'doctrine' => [
        'configuration' => [
            'orm_default' => [
                'types' => [
                    GuidType::NAME => GuidType::class,

Usage

Then, in your models, you may annotate properties by setting the @Column type to guid, and defining a custom generator of Gubler\Guid\GuidGenerator. Doctrine will handle the rest.

/**
 * @Entity
 * @Table(name="products")
 */
class Product
{
    /**
     * @var \Ramsey\Uuid\Uuid
     *
     * @Id
     * @Column(type="guid", unique=true)
     * @GeneratedValue(strategy="CUSTOM")
     * @CustomIdGenerator(class="Gubler\Guid\Doctrine\GuidGenerator")
     */
    protected $id;

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

If you use the XML Mapping instead of PHP annotations.

<id name="id" column="id" type="guid">
    <generator strategy="CUSTOM"/>
    <custom-id-generator class="Gubler\Guid\Doctrine\GuidGenerator"/>
</id>

You can also use the YAML Mapping.

id:
    id:
        type: guid
        generator:
            strategy: CUSTOM
        customIdGenerator:
            class: Gubler\Guid\Doctrine\GuidGenerator

Binary Database Columns

In the previous example, Doctrine will create a database column of type CHAR(36), but you may also use this library to store GUIDs as binary strings. The GuidBinaryType helps accomplish this.

In your bootstrap, place the following:

\Doctrine\DBAL\Types\Type::addType('guid_binary', 'Gubler\Guid\Doctrine\GuidBinaryType');
$entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('guid_binary', 'binary');

In Symfony:

# config/packages/doctrine.yaml
doctrine:
   dbal:
       types:
           guid_binary:  Gubler\Guid\Doctrine\GuidBinaryType
       mapping_types:
           guid_binary: binary

Then, when annotating model class properties, use guid_binary instead of guid:

@Column(type="guid_binary")

More Information

For more information on getting started with Doctrine, check out the "Getting Started with Doctrine" tutorial.

Contributing

Contributions are welcome! Please read CONTRIBUTING for details.

Copyright and License

The gubler/guid-doctrine library is copyright © Daryl Gubler and licensed for use under the MIT License (MIT). Please see LICENSE for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固