getDocumentId() public method

Get the object ID for the given document
public getDocumentId ( object | string $document, $throw = true ) : string | null
$document object | string document instance or document object hash
return string | null
Example #1
0
 public function testGetOrCreateDocument()
 {
     $user = $this->uow->getOrCreateDocument($this->type, $this->createNode('/somepath', 'foo'));
     $this->assertInstanceOf($this->type, $user);
     $this->assertEquals('foo', $user->username);
     $method = new \ReflectionMethod($this->uow, 'getDocumentState');
     $method->setAccessible(true);
     $state = $method->invoke($this->uow, $user);
     $method->setAccessible(false);
     $this->assertEquals(UnitOfWork::STATE_MANAGED, $state);
     $this->assertEquals('/somepath', $this->uow->getDocumentId($user));
 }
Example #2
0
 public function testFetchingMultipleHierarchicalObjectsWithChildIdFirst()
 {
     $parent = new ParentTestObj();
     $parent->nodename = 'parent';
     $parent->name = 'parent';
     $parent->parent = $this->dm->find(null, 'functional');
     $child = new ParentTestObj();
     $child->nodename = 'child';
     $child->name = 'child';
     $child->parent = $parent;
     $this->dm->persist($parent);
     $this->dm->persist($child);
     $parentId = $this->uow->getDocumentId($parent);
     $childId = $this->uow->getDocumentId($child);
     $this->dm->flush();
     $this->dm->clear();
     // this forces the objects to be loaded in an order where the $parent will become a proxy
     $documents = $this->dm->findMany('Doctrine\\Tests\\Models\\References\\ParentTestObj', array($childId, $parentId));
     $this->assertCount(2, $documents);
     /* @var $child ParentTestObj */
     /* @var $parent ParentTestObj */
     $child = $documents->first();
     $parent = $documents->last();
     $this->assertSame($child->parent, $parent);
     $this->assertSame('parent', $parent->nodename);
 }
Example #3
0
 /**
  * Refresh the given document by querying the PHPCR to get the current state.
  *
  * @param object $document
  * @return object Document instance
  */
 public function refresh($document)
 {
     $this->errorIfClosed();
     $this->session->refresh(true);
     $node = $this->session->getNode($this->unitOfWork->getDocumentId($document));
     $hints = array('refresh' => true);
     return $this->unitOfWork->createDocument(get_class($document), $node, $hints);
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function getNodeForDocument($document)
 {
     if (!is_object($document)) {
         throw new InvalidArgumentException('Parameter $document needs to be an object, ' . gettype($document) . ' given');
     }
     $path = $this->unitOfWork->getDocumentId($document);
     return $this->session->getNode($path);
 }
 /**
  * Refresh the given document by querying the PHPCR to get the current state.
  *
  * @param object $document
  * @return object Document instance
  */
 public function refresh($document)
 {
     if (!is_object($document)) {
         throw new \InvalidArgumentException(gettype($document));
     }
     $this->errorIfClosed();
     $this->session->refresh(true);
     $node = $this->session->getNode($this->unitOfWork->getDocumentId($document));
     $hints = array('refresh' => true);
     return $this->unitOfWork->createDocument(get_class($document), $node, $hints);
 }