getMetadataFor() public method

public getMetadataFor ( $className )
Esempio n. 1
0
 /**
  * {@inheritDoc}
  */
 protected function walkSourceDocument(SourceDocument $node)
 {
     $alias = $node->getAlias();
     $documentFqn = $node->getDocumentFqn();
     // cache the metadata for this document
     /** @var $meta ClassMetadata */
     $meta = $this->mdf->getMetadataFor($documentFqn);
     if (null === $meta->getName()) {
         throw new \RuntimeException(sprintf('%s is not a mapped document', $documentFqn));
     }
     $this->aliasMetadata[$alias] = $meta;
     if ($this->locale && $meta->translator) {
         $this->translator[$alias] = $this->dm->getTranslationStrategy($meta->translator);
     }
     $nodeType = $meta->getNodeType();
     // make sure we add the phpcr:{class,classparents} constraints
     // unless the document has a unique type; From is dispatched first,
     // so these will always be the primary constraints.
     if (!$meta->hasUniqueNodeType()) {
         $this->sourceDocumentNodes[$alias] = $node;
     }
     // get the PHPCR Alias
     $alias = $this->qomf->selector($alias, $nodeType);
     return $alias;
 }
 public function testGetMapping()
 {
     $cmf = new ClassMetadataFactory($this->dm);
     $cm = new \Doctrine\ODM\PHPCR\Mapping\ClassMetadata('stdClass');
     $cmf->setMetadataFor('stdClass', $cm);
     $this->assertTrue($cmf->hasMetadataFor('stdClass'));
     $this->assertSame($cm, $cmf->getMetadataFor('stdClass'));
 }
 /**
  * Gets a reference to the document identified by the given type and identifier
  * without actually loading it.
  *
  * If partial objects are allowed, this method will return a partial object that only
  * has its identifier populated. Otherwise a proxy is returned that automatically
  * loads itself on first access.
  *
  * @param string $documentName
  * @param string|object $id
  * @return mixed|object The document reference.
  */
 public function getReference($documentName, $id)
 {
     $class = $this->metadataFactory->getMetadataFor($documentName);
     // Check identity map first, if its already in there just return it.
     $document = $this->unitOfWork->getDocumentById($id);
     if ($document) {
         return $document;
     }
     $document = $this->proxyFactory->getProxy($class->name, $id);
     $this->unitOfWork->registerDocument($document, $id);
     return $document;
 }
 private function doUpdate(ClassMetadataFactory $metadataFactory, PhpcrMetadata $odmMetadata, CtMetadata $ctMetadata, $document)
 {
     $documentId = $odmMetadata->getIdentifierValue($document);
     foreach ($odmMetadata->childrenMappings as $childrenField) {
         // if the children field is not managed by the CT component,
         // continue
         if (!isset($ctMetadata->propertyMetadata[$childrenField])) {
             continue;
         }
         $children = $odmMetadata->getFieldValue($document, $childrenField);
         // note that we do not preserve array keys. PHPCR ODM will return a
         // children collection using the PHPCR property names as keys, so
         // we currently have no control over how these keys populated.
         $index = 0;
         foreach ($children as $child) {
             $childMetadata = $metadataFactory->getMetadataFor(ClassUtils::getRealClass(get_class($child)));
             $newId = sprintf('%s/%s', $documentId, $this->encoder->encode($childrenField, $index++));
             $childMetadata->setIdentifierValue($child, $newId);
         }
     }
 }
Esempio n. 5
0
 /**
  * Test that using the Version annotation on non-versionable documents will not work
  * @expectedException \Doctrine\ODM\PHPCR\Mapping\MappingException
  */
 public function testLoadInconsistentAnnotations()
 {
     $factory = new ClassMetadataFactory($this->dm);
     $factory->getMetadataFor('Doctrine\\Tests\\Models\\Versioning\\InconsistentVersionableArticle');
 }
Esempio n. 6
0
 /**
  * Test loading of a translatable document missing the @Locale annotation.
  * @expectedException Doctrine\ODM\PHPCR\Mapping\MappingException
  */
 public function testLoadMissingLocaleAnnotation()
 {
     $factory = new ClassMetadataFactory($this->dm);
     $metadata = $factory->getMetadataFor('Doctrine\\Tests\\Models\\Translation\\NoLocalePropertyArticle');
 }
 public function testStringExtendedMapping()
 {
     $className = 'Doctrine\\Tests\\ODM\\PHPCR\\Mapping\\Model\\StringMappingObject';
     $this->loadMetadataForClassname($className);
     $className = 'Doctrine\\Tests\\ODM\\PHPCR\\Mapping\\Model\\StringExtendedMappingObject';
     $session = $this->getMock('PHPCR\\SessionInterface');
     $dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session);
     $dm->getConfiguration()->setMetadataDriverImpl($this->loadDriver());
     $cmf = new ClassMetadataFactory($dm);
     $class = $cmf->getMetadataFor($className);
     $this->assertEquals('stringAssoc', $class->mappings['stringAssoc']['fieldName']);
     $this->assertEquals('string', $class->mappings['stringAssoc']['type']);
     $this->assertTrue($class->mappings['stringAssoc']['translated']);
     $this->assertTrue($class->mappings['stringAssoc']['multivalue']);
     $this->assertEquals('stringAssocKeys', $class->mappings['stringAssoc']['assoc']);
     $this->assertEquals('stringAssocNulls', $class->mappings['stringAssoc']['assocNulls']);
 }
Esempio n. 8
0
 /**
  * @param  string $class
  * @return ClassMetadata
  */
 public function getClassMetadata($class)
 {
     return $this->metadataFactory->getMetadataFor($class);
 }