public static function createFromConfiguration(Configuration $configuration, ObjectKey $objectKey) { $key = $objectKey->getKey(); $instance = (new static())->setResourcePath($configuration->getClassMetadataResource($key))->setResourceType($configuration->getClassMetadataResourceType($key))->setResourceClass($objectKey->getClass()); $resourceMethod = $configuration->getClassMetadataProviderMethod($key); if (isset($resourceMethod)) { $instance->setResourceMethod($resourceMethod); } return $instance; }
public function loadMetadata(ObjectKey $objectKey, LoadingCriteriaInterface $loadingCriteria, Configuration $configuration) { $cacheKey = $objectKey->getKey(); if (!isset($this->loadedMetadata[$cacheKey])) { if ($this->cache->contains($cacheKey)) { $this->loadedMetadata[$cacheKey] = $this->cache->fetch($cacheKey); } else { $classMetadata = new ClassMetadata($objectKey->getClass()); $this->metadataLoader->loadClassMetadata($classMetadata, $loadingCriteria, $configuration); $classMetadata->compile(); $this->loadedMetadata[$cacheKey] = $classMetadata; $this->cache->save($cacheKey, $classMetadata); if ($this->eventManager) { $this->eventManager->dispatch(Events::POST_LOAD_METADATA, new ClassMetadataEvent(new ClassMetadataBuilder($classMetadata))); } } } return $this->loadedMetadata[$cacheKey]; }
/** * Return the class metadata. * * @param string $className FQCN without a leading back slash as does get_class() * * @return \Kassko\DataMapper\ClassMetadata\ClassMetadata */ public function getMetadata($objectClass) { if (!$objectClass instanceof ObjectKey) { $objectClass = new ObjectKey($objectClass); } $key = $objectClass->getKey(); return $this->classMetadataFactory->loadMetadata($objectClass, LoadingCriteria::createFromConfiguration($this->configuration, $objectClass), $this->configuration); }
protected function prepare($object, ObjectKey $objectKey = null) { if (isset($object)) { if (null === $objectKey) { $this->metadata = $this->objectManager->getMetadata(get_class($object)); } else { $this->metadata = $this->objectManager->getMetadata($objectKey->getKey()); } } $this->doPrepare($object); }