Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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];
 }
 /**
  * @test
  */
 public function loadMetadataCreateNewClassMetadata()
 {
     $expectedResult = new ClassMetadata\ClassMetadata('Kassko\\DataMapperTest\\ClassMetadata\\Fixture\\SampleClass');
     $cacheKey = 'testCacheKey';
     $this->objectKeyMock->expects($this->once())->method('getKey')->willReturn($cacheKey);
     $this->objectKeyMock->expects($this->once())->method('getClass')->willReturn('Kassko\\DataMapperTest\\ClassMetadata\\Fixture\\SampleClass');
     $this->loaderMock->expects($this->once())->method('loadClassMetadata')->with($expectedResult, $this->loadingCriteriaMock, $this->configurationMock);
     $this->cacheMock->expects($this->once())->method('save')->with($cacheKey);
     $this->eventDispatcherMock->expects($this->once())->method('dispatch')->with(ClassMetadata\Events::POST_LOAD_METADATA);
     $result = $this->classMetadataFactory->loadMetadata($this->objectKeyMock, $this->loadingCriteriaMock, $this->configurationMock);
     $this->assertEquals($expectedResult, $result);
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
0
 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);
 }