Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2:如何从Web服务构造实体_Php_Web Services_Rest_Symfony_Guzzle - Fatal编程技术网

Php Symfony2:如何从Web服务构造实体

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

我正在开发一个web服务,其中从另一个ReST web服务检索实体

目前,我正在从一个基于控制器中Guzzle的服务中获取数据,并通过使用序列化程序进行非规范化来补充我的实体

$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);