paneedesign/discriminator-map-bundle

Symfony 的 Doctrine ORM 动态 DiscriminatorMap 扩展器

v1.0.4 2019-07-26 11:03 UTC

This package is auto-updated.

Last update: 2024-09-26 22:14:40 UTC


README

Version Documentation Twitter: dr_thief

Symfony 的 Doctrine ORM 动态 DiscriminatorMap 扩展器。

🏠 主页

安装

步骤 1: 下载 Bundle

通过 Composer 安装

composer require paneedesign/discriminator-map-bundle

或者将以下内容添加到你的 composer.json 并运行 composer update

"require": {
    "paneedesign/discriminator-map-bundle": "^1.0"
}

此命令需要你全局安装 Composer,如 Composer 文档中的 安装章节 所述。

步骤 2: 启用 Bundle

然后,通过将 Bundle 添加到项目中的 app/AppKernel.php 文件中注册的 Bundle 列表来启用 Bundle

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new \PaneeDesign\DiscriminatorMapBundle\PedDiscriminatorMapBundle(),
        );

        // ...
    }

    // ...
}

步骤 3: 配置

添加配置

// app/config/config.yml
//...
ped_discriminator_map:
    maps:
        user:
            entity: PaneeDesign\UserBundle\Entity\User
            children:
                admin:    AppBundle\Entity\Admin
                owner:    AppBundle\Entity\Owner
                customer: AppBundle\Entity\Customer
                ...

其中父类实现此注解

/**
 * @ORM\Entity()
 * @ORM\Table(name="user")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="user_grant", type="string", length="10")
 * @ORM\DiscriminatorMap({"user" = "User"})
 */
abstract class User
{
    ...
}

子类实现这些注解

/**
 * Class Admin
 *
 * @package AppBundle\Entity
 * @ORM\Entity
 * @ORM\Table(name="user_admin")
 */
class Admin extends User
{
    ...
}
/**
 * Class Owner
 *
 * @package AppBundle\Entity
 * @ORM\Entity()
 * @ORM\Table(name="user_owner")
 */
class Owner
{
    ...
}
/**
 * Class Customer
 *
 * @package AppBundle\Entity
 * @ORM\Entity()
 * @ORM\Table(name="user_customer")
 */
class Customer
{
    ...
}

作者

👤 Fabiano Roberto

🤝 贡献

欢迎贡献、问题和功能请求!
请随意查看 问题页面

显示您的支持

如果此项目对您有帮助,请给一个 ⭐️!

此 README 是由 readme-md-generator 用 ❤️ 生成的