/** * Get an ID for the given data * * @return string */ public function getId() { $values = []; foreach ($this->metadata->getIdColumns() as $column) { $values[] = $this->getPropertyValue($column->getProperty()); } if (!count($values)) { throw new InvalidEntityException('Entity "' . $this->metadata->getClassName() . '" has no ID column'); } return implode(self::ID_DELIMITER, $values); }
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"); } }