public function __construct(Entity $metadata, SerialisedData $data, EntityManager $entity_manager)
{
$this->metadata = $metadata;
$this->serialised_data = $data;
$this->entity_manager = $entity_manager;
$conf = new Configuration();
$conf->setProxiesTargetDir($entity_manager->getConfig()->getCacheDir());
$conf->setProxiesNamespace(self::PROXY_NAMESPACE);
$factory = new OrmProxyFactory($conf);
$writer = $this;
// Create the proxy with a Closure responsible for lazy-loading via this instance of the Writer
$this->proxy = $factory->createProxy($metadata->getClassName(), function (LazyLoadingInterface $proxy, $method, array $parameters, &$initializer) use($writer) {
// Hydrate the primitive data
if (!$writer->is_hydrated) {
$writer->hydrate();
}
// Hydrate foreign relatives on request
$this->examineMethodForHydration($method);
return true;
});
if (!$this->proxy) {
throw new \RuntimeException("Unable to create proxy object of entity");
}
}