Php Symfony2:如何从Web服务构造实体
我正在开发一个web服务,其中从另一个ReST web服务检索实体 目前,我正在从一个基于控制器中Guzzle的服务中获取数据,并通过使用序列化程序进行非规范化来补充我的实体Php Symfony2:如何从Web服务构造实体,php,web-services,rest,symfony,guzzle,Php,Web Services,Rest,Symfony,Guzzle,我正在开发一个web服务,其中从另一个ReST web服务检索实体 目前,我正在从一个基于控制器中Guzzle的服务中获取数据,并通过使用序列化程序进行非规范化来补充我的实体 $customer_api = $this->container->get('customer_api'); $data = $customer_api->getCustomer([ "customerId" => $id_customer, ]); $customer = Custom
$customer_api = $this->container->get('customer_api');
$data = $customer_api->getCustomer([
"customerId" => $id_customer,
]);
$customer = Customer::hydrate($data);
这是水合物的作用
public static function hydrate($data)
{
$encoders = array(new JsonEncoder());
$normalizers = array(new GetSetMethodNormalizer());
$serializer = new Serializer($normalizers, $encoders);
$entity = $serializer->denormalize($data, get_called_class());
return $entity;
}
随着我对代码的深入,我开始需要一些实体来加载其他实体。但据我所知,让模型访问容器是非常糟糕的
如何重构它,以便使用模型构造函数
$customer = new Customer($id_customer);