gpt4 book ai didi

php - 使用 JMSSerializer 序列化特征

转载 作者:可可西里 更新时间:2023-11-01 13:30:25 25 4
gpt4 key购买 nike

当尝试序列化使用特征的模型时,JMSSerializer 不会序列化该特征包含的属性。我正在使用 yaml 配置序列化程序,但它似乎无法正常工作。

trait IdentityTrait
{

protected $id;

public function setId($id)
{
$this->id = $id;

return $this;
}

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

class OurClass {
use IdentityTrait;

protected $test;

public function getTest() {
$this->test;
}
}

使用了 JMSSerializerBundle,以下 yaml 位于 Resources/config/serializer/Model.Traits.IdentityTrait.yml

MyProject\Component\Core\Model\Traits\IdentityTrait:
exclusion_policy: NONE
properties:
id:
expose: true

OurClass配置位于Resources/config/serializer/Model.OurClass.yml

 MyProject\Component\Core\Model\OurClass:
exclusion_policy: NONE
properties:
test:
expose: true

部分代码已被忽略以专注于问题

最佳答案

PHP 5.4.0 以来引入了 PHP 特征,最新的JMSSerializer代码支持PHP 5.3.2 .注意 "require": {"php": ">=5.3.2", 查看代码,不支持此功能(目前)。这个问题与this issue非常相关在 JMSSerializer github 上。

关于php - 使用 JMSSerializer 序列化特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26936138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com