I'm developing a web-service where the entities are retrieved from another ReST web-service.
For now I'm getting the data from a service based on Guzzle in the controller and hydrate my entities by denormalizing with the Serializer
$customer_api = $this->container->get('customer_api');
$data = $customer_api->getCustomer([
"customerId" => $id_customer,
]);
$customer = Customer::hydrate($data);
Here's the hydrate function
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;
}
As I'm getting deeper in the code I'm starting to need some entities to load other entities. But as far as I've read it's pretty bad to give access to the container to the Models
How would refactor this so I could use the model constructor instead
$customer = new Customer($id_customer);