/** * @param string $eventName * @param object $object */ public function dispatchObjectLifecycleCallback($eventName, $object, array &$args = array()) { $className = get_class($object); $class = $this->objectManager->getClassMetadata($className); if (!empty($class->lifecycleCallbacks[$eventName])) { $class->invokeLifecycleCallbacks($eventName, $object, $args); } }
/** * @param array|null $data * * @return object|null */ protected function getOrCreateObject(array $data = null) { if ($data === null) { return; } return $this->objectManager->getOrCreateObject($this->getClassName(), $data); }
/** * @param string $className * @param array $data * * @return object */ private function createObject($className, array $data) { $repository = $this->objectManager->getRepository($className); $object = $repository->create($className); if ($object instanceof NotifyPropertyChanged) { $object->addPropertyChangedListener($this); } $this->eventDispatcher->dispatchPreLoad($object, $data); $repository->hydrate($object, $data); $this->eventDispatcher->dispatchPostLoad($object); $this->objectIdentityMap->addToIdentityMap($object, $data); return $object; }
/** * @param object $object * * @return array $identifier */ protected function getObjectIdentifier($object) { return $this->objectManager->getRepository(get_class($object))->getObjectIdentifier($object); }
/** * @param object $object * * @return array */ protected function getObjectIdentifier($object) { return $this->objectManager->getRepository($this->getClassName())->getObjectIdentifier($object); }
/** * @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']))); }); } }