我可以覆盖标签对象的序列化方式吗?目前一切都返回了,我想排除 id、created_at、updated_at 和标记。我正在使用 JMS Serializer 包,Doctrine Extensions Taggable with FPN Tag Bundle。
这是我的设置,当实体的命名空间实际上是 DoctrineExtensions 时,我正在考虑将 Tag Bundle 的父级设置为 FPN。
大多数实体参数位于 DoctrineExtensions\Taggable\Entity\Tag(id、name、created_at 等)中。我正在覆盖扩展 DoctrineExtensions 的 FPN 包。DoctrineExtensions 是一个库而不是一个包。
我怎样才能做到这一点?
# app/config/config.yml
# ...
jms_serializer:
metadata:
auto_detection: true
directories:
TagBundle:
namespace_prefix: "FPN\\TagBundle"
path: "@MYTagBundle/Resources/config/serializer/fpn"
# MY\TagBundle\Resources\config\serializer\fpn\Entity.Tag.yml
FPN\TagBundle\Entity\Tag:
exclusion_policy: ALL
properties:
id:
expose: false
name:
expose: true
created_at:
expose: false
updated_at:
expose: false
tagging:
expose: false
# src/MY/TagBundle/Entity/Tag.php
<?php
namespace MY\TagBundle\Entity;
use FPN\TagBundle\Entity\Tag as BaseTag;
class Tag extends BaseTag
{
}
# vendor/fpn/tag-bundle/FPN/TagBundle/Entity/Tag.php
<?php
namespace FPN\TagBundle\Entity;
use DoctrineExtensions\Taggable\Entity\Tag as BaseTag;
class Tag extends BaseTag
{
....
}
# src/MY/TagBundle/MYTagBundle.php
<?php
namespace MY\TagBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class MYTagBundle extends Bundle
{
// Is this unnecessary due to config.yml?
public function getParent()
{
return 'FPNTagBundle';
}
}