brazanation / document-doctrine-types

提供将文档作为Doctrine类型的库

v0.1.0 2017-08-11 21:39 UTC

This package is auto-updated.

Last update: 2024-09-04 07:44:35 UTC


README

Build Status StyleCI Scrutinizer Code Quality Code Coverage

安装

composer require brazanation/document-doctrine-types ^0.1

如何使用?

首先,在 Doctrine 连接后注册 Document 类型。

// bootstrap.php

// ... other code
$connection = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, new \Doctrine\Common\EventManager());

\Brazanation\Doctrine\TypeExtension::register($connection);

// ... more code

将实体的属性定义为文档

/**
 * @Entity @Table(name="persons")
 */
class Person
{
    /**
     * @Id
     * @Column(type="cpf")
     * @var \Brazanation\Documents\Cpf
     */
    private $cpf;

    public function __construct(\Brazanation\Documents\Cpf $cpf)
    {
        $this->cpf = $cpf;
    }

    public function getCpf()
    {
        return $this->cpf;
    }
}

可用的类型