简体   繁体   English

Doctrine MappedSuperClass,覆盖自定义注释

[英]Doctrine MappedSuperClass, override custom annotation

I am wondering if there is a way to change (or define inside) annotations in a child class inheriting a MappedSuperClass, for example, let say we have a class BaseUser (mappedsuperclass), a child class User : 我想知道是否有一种方法可以在继承MappedSuperClass的子类中更改(或定义内部)注释,例如,假设我们有一个类BaseUser(mappedsuperclass),一个子类User:

<?php
...
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
...


/**
* @ORM\MappedSuperclass 
*/
class BaseUser
{
    /**
     * @ORM\Column(name="firstname", type="string", length=100)
     * @Serializer\SerializedName("First_Name")
     * @Serializer\Expose
     * @Serializer\Type("string")
     * @Serializer\Groups({"Basic"})
     */
    protected $firstName;
}

/**
* @ORM\Entity
*/
class User extends BaseUser
{
    /**
     * @ORM\Column(name="sign", type="string", length=50)
     */
    private $sign;
}

What I would like to do is either defining the "Serializer" annotations from User class directly (but let the property firstName to be defined in the BaseUser class), OR, overriding the definition of Serialize from the User class. 我想要做的是直接从User类定义“Serializer”注释(但是让属性firstName在BaseUser类中定义),或者从User类覆盖Serialize的定义。

I did not found anything about this topic, has someone already figured it out? 我没有找到关于这个话题的任何内容,有人已经弄清楚了吗? Thanks 谢谢

You can tell the JMS Serializer what to expose or not in your config. 您可以告诉JMS Serializer在配置中公开或不公开的内容。

app/config/config.yml: 应用程序/配置/ config.yml:

jms_serializer:
metadata:
    directories:
        - { path: %kernel.root_dir%/Resources/FOSUserBundle/serializer, namespace_prefix: 'FOS\UserBundle' }

app/Resources/FOSUserBundle/serializer/Model.User.yml: 应用程序/资源/ FOSUserBundle /串行器/ Model.User.yml:

FOS\UserBundle\Model\User:
exclusion_policy: ALL
properties:
    id:
        expose: true
    email:
        expose: true
    username:
        expose: true
    enabled:
        expose: true
    locked:
        expose: true

Source: https://github.com/schmittjoh/JMSSerializerBundle/issues/78#issuecomment-31831236 资料来源: https//github.com/schmittjoh/JMSSerializerBundle/issues/78#issuecomment-31831236

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM