【发布时间】:2012-02-14 10:17:50
【问题描述】:
我正在尝试使用 Symfony 2.0.9 实现 Symfony\Component\Serializer\Normalizer\NormalizableInterface。
我添加了这样的实现:
class MRoute implements NormalizableInterface{
...
public function normalize($object, $format = null)
{
$points = array();
foreach ($this->getPoints() as $point) {
$points[] = $point->normalize();
}
return array(
'id' => $this->getId(),
'name' => $this->getName(),
'points' => $points
);
}
/**
* @see
*/
function denormalize(NormalizerInterface $normalizer, $data, $format = null)
{
if (isset($data['name']))
{
$this->setName($data['name']);
}
if (isset($data['id']))
{
$this->setId($data['id']);
}
}
但是当我尝试访问网络服务时,我收到如下错误:
致命错误:MyGIS\GISBundle\Entity\MRoute::normalize() 的声明必须与 C:\NetbeansProjects\mroute_rest_service\src\ 中的 Symfony\Component\Serializer\Normalizer\NormalizableInterface::normalize() 的声明兼容第 16 行的 MyGIS\GISBundle\Entity\MRoute.php
我打开 Symfony\Component\Serializer\Normalizer\NormalizableInterface.php 并且签名匹配。
我做错了什么?
【问题讨论】: