/** * @param array|null $data * * @return object|null */ protected function getOrCreateObject(array $data = null) { if ($data === null) { return; } return $this->objectManager->getOrCreateObject($this->getClassName(), $data); }
/** * @see HydratableInterface * * @param array $data * @param \Doctrine\SkeletonMapper\ObjectManagerInterface $objectManager */ public function hydrate(array $data, ObjectManagerInterface $objectManager) { if (isset($data['_id'])) { $this->id = (int) $data['_id']; } if (isset($data['username'])) { $this->username = (string) $data['username']; } if (isset($data['password'])) { $this->password = (string) $data['password']; } if (isset($data['profileId']) && isset($data['profileName'])) { $profileData = array('_id' => (int) $data['profileId'], 'name' => $data['profileName']); $this->profile = function () use($objectManager, $profileData) { return $objectManager->getOrCreateObject('Doctrine\\SkeletonMapper\\Tests\\Model\\Profile', $profileData); }; } elseif (isset($data['profileId'])) { $this->profile = function () use($objectManager, $data) { return $objectManager->find('Doctrine\\SkeletonMapper\\Tests\\Model\\Profile', (int) $data['profileId']); }; } if (isset($data['groupIds'])) { $this->groups = new LazyCollection(function () use($objectManager, $data) { return new ArrayCollection(array_map(function ($groupId) use($objectManager) { return $objectManager->find('Doctrine\\SkeletonMapper\\Tests\\Model\\Group', (int) $groupId); }, explode(',', $data['groupIds']))); }); } }