序列化与另一个实体有关系的实体时。
如果未设置A circular reference has been detected when serializing the object of class
和setCircularReferenceLimit
,则会发生 setCircularReferenceHandler
。
它解决了symfony3.2之前的问题,但是现在Symofony4.1.6 Error: Maximum execution time of 30 seconds exceeded
发生了,并且超时了。
我应该在哪里检查????
$encoders = array(new XmlEncoder(), new JsonEncoder());
$norm = new ObjectNormalizer();
//// it fixes the problem before Symfony 3.2, but no it causes timeout
$norm->setCircularReferenceLimit(0);
$norm->setCircularReferenceHandler(function ($object) {
return $object->getId();
});
//////////
$normalizers = array($norm);
$serializer = new Serializer($normalizers, $encoders);
/// get entity from doctorine2//
$myEntity = ....
$jsonContent = $serializer->serialize($myEntity, 'json');
我的错误是
in vendor/symfony/property-access/PropertyAccessor.php (line 372)
$result = self::$resultProto;
$object = $zval[self::VALUE];
$access = $this->getReadAccessInfo(\get_class($object), $property);
if (self::ACCESS_TYPE_METHOD === $access[self::ACCESS_TYPE]) {
$result[self::VALUE] = $object->{$access[self::ACCESS_NAME]}();
} elseif (self::ACCESS_TYPE_PROPERTY === $access[self::ACCESS_TYPE]) {
$result[self::VALUE] = $object->{$access[self::ACCESS_NAME]};
if ($access[self::ACCESS_REF] && isset($zval[self::REF])) {
$result[self::REF] = &$object->{$access[self::ACCESS_NAME]};