Doctrine\ODM\PHPCR\Mapping\ClassMetadata::getIdentifierValue PHP Method

getIdentifierValue() public method

Gets the document identifier.
public getIdentifierValue ( object $document ) : string
$document object
return string $id
    public function getIdentifierValue($document)
    {
        if (!$this->identifier) {
            throw new PHPCRException(sprintf('Class %s has no identifier field mapped. Please use $documentManager->getUnitOfWork()->getDocumentId($document) to get the id of arbitrary documents.', $this->name));
        }
        return (string) $this->getFieldValue($document, $this->identifier);
    }

Usage Example

 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);
         }
     }
 }
All Usage Examples Of Doctrine\ODM\PHPCR\Mapping\ClassMetadata::getIdentifierValue
ClassMetadata