当前位置: 首页>>代码示例>>PHP>>正文


PHP DocumentManager::getUnitOfWork方法代码示例

本文整理汇总了PHP中Doctrine\ODM\PHPCR\DocumentManager::getUnitOfWork方法的典型用法代码示例。如果您正苦于以下问题:PHP DocumentManager::getUnitOfWork方法的具体用法?PHP DocumentManager::getUnitOfWork怎么用?PHP DocumentManager::getUnitOfWork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ODM\PHPCR\DocumentManager的用法示例。


在下文中一共展示了DocumentManager::getUnitOfWork方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Initializes a new <tt>DocumentRepository</tt>.
  *
  * @param DocumentManager $dm The DocumentManager to use.
  * @param ClassMetadata $classMetadata The class descriptor.
  */
 public function __construct($dm, Mapping\ClassMetadata $class)
 {
     $this->dm = $dm;
     $this->class = $class;
     $this->uow = $this->dm->getUnitOfWork();
     $this->className = $class->name;
 }
开发者ID:richardmiller,项目名称:phpcr-odm,代码行数:13,代码来源:DocumentRepository.php

示例2: getContentId

 /**
  * {@inheritDoc}
  */
 public function getContentId($content)
 {
     if (!is_object($content)) {
         return null;
     }
     try {
         return $this->documentManager->getUnitOfWork()->getDocumentId($content);
     } catch (\Exception $e) {
         return null;
     }
 }
开发者ID:symfony-cmf,项目名称:routing-extra-bundle,代码行数:14,代码来源:ContentRepository.php

示例3: testFindTranslationWithUntranslatedChildren

 /**
  * Test that children are retrieved in the parent locale
  */
 public function testFindTranslationWithUntranslatedChildren()
 {
     $this->dm->persist($this->doc);
     $this->dm->bindTranslation($this->doc, 'en');
     $this->doc->topic = 'Un autre sujet';
     $this->dm->bindTranslation($this->doc, 'fr');
     $this->dm->flush();
     $testNode = $this->node->getNode($this->testNodeName);
     $testNode->addNode('new-comment');
     $this->session->save();
     $this->dm->clear();
     $this->doc = $this->dm->findTranslation($this->class, '/functional/' . $this->testNodeName, 'fr');
     $this->assertEquals('fr', $this->doc->locale);
     $children = $this->doc->getChildren();
     $this->assertCount(1, $children);
     foreach ($children as $comment) {
         $this->assertInstanceOf('Doctrine\\ODM\\PHPCR\\Document\\Generic', $comment);
         $this->assertNull($this->dm->getUnitOfWork()->getCurrentLocale($comment));
     }
     $this->dm->clear();
     $this->doc = $this->dm->findTranslation($this->class, '/functional/' . $this->testNodeName, 'en');
     $children = $this->dm->getChildren($this->doc);
     $this->assertCount(1, $children);
     foreach ($children as $comment) {
         $this->assertInstanceOf('Doctrine\\ODM\\PHPCR\\Document\\Generic', $comment);
         $this->assertNull($this->dm->getUnitOfWork()->getCurrentLocale($comment));
     }
 }
开发者ID:steffenbrem,项目名称:phpcr-odm,代码行数:31,代码来源:DocumentManagerTest.php

示例4: testPersistRepository

 public function testPersistRepository()
 {
     $doc = new RepositoryIdStrategy();
     $doc->title = 'repository strategy';
     $this->dm->persist($doc);
     $this->dm->flush();
     $id = $this->dm->getUnitOfWork()->getDocumentId($doc);
     $this->dm->clear();
     $this->assertInstanceOf('\\Doctrine\\Tests\\ODM\\PHPCR\\Functional\\Mapping\\RepositoryIdStrategy', $this->dm->find(null, $id));
 }
开发者ID:steffenbrem,项目名称:phpcr-odm,代码行数:10,代码来源:AnnotationMappingTest.php

示例5: buildName

 protected function buildName($document, ClassMetadata $class, DocumentManager $dm, $parent, $name)
 {
     // get the id of the parent document
     $id = $dm->getUnitOfWork()->getDocumentId($parent);
     if (!$id) {
         throw IdException::parentIdCouldNotBeDetermined($document, $class->parentMapping, $parent);
     }
     // edge case parent is root
     if ('/' === $id) {
         $id = '';
     }
     return $id . '/' . $name;
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:13,代码来源:ParentIdGenerator.php

示例6: generate

 /**
  * @param object $document
  * @param ClassMetadata $cm
  * @param DocumentManager $dm
  * @return string
  */
 public function generate($document, ClassMetadata $cm, DocumentManager $dm)
 {
     $parent = $cm->getFieldValue($document, $cm->parentMapping);
     $name = $cm->getFieldValue($document, $cm->nodename);
     $id = $cm->getFieldValue($document, $cm->identifier);
     if ((empty($parent) || empty($name)) && empty($id)) {
         throw new \RuntimeException('ID could not be determined. Make sure the document has a property with Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\ParentDocument and Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\Nodename annotation and that the property is set to the path where the document is to be stored.');
     }
     // use assigned ID by default
     if (!$parent || empty($name)) {
         return $id;
     }
     // determine ID based on the path and the node name
     $id = $dm->getUnitOfWork()->getDocumentId($parent);
     if (!$id) {
         throw new \RuntimeException('Parent ID could not be determined. Make sure to persist the parent document before persisting this document.');
     }
     return $id . '/' . $name;
 }
开发者ID:nicam,项目名称:phpcr-odm,代码行数:25,代码来源:ParentIdGenerator.php

示例7: objToStr

 private static function objToStr($obj, DocumentManager $dm = null)
 {
     $string = method_exists($obj, '__toString') ? (string) $obj : ClassUtils::getClass($obj) . '@' . spl_object_hash($obj);
     if ($dm) {
         try {
             $id = $dm->getUnitOfWork()->determineDocumentId($obj);
             if (!$id) {
                 $id = 'unmanaged or new document without id';
             }
             $string .= " ({$id})";
         } catch (\Exception $e) {
             $id = 'failed to determine id';
             $string .= " ({$id})";
         }
     }
     return $string;
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:17,代码来源:UnitOfWork.php

示例8: let

 function let(DocumentManager $dm, ClassMetadata $class, UnitOfWork $unitOfWork)
 {
     $dm->getUnitOfWork()->shouldBeCalled()->willreturn($unitOfWork);
     $this->beConstructedWith($dm, $class);
 }
开发者ID:Silwereth,项目名称:Sylius,代码行数:5,代码来源:StaticContentRepositorySpec.php

示例9: setUp

 public function setUp()
 {
     $this->dm = $this->createDocumentManager();
     $this->uow = $this->dm->getUnitOfWork();
     $this->resetFunctionalNode($this->dm);
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:6,代码来源:UnitOfWorkTest.php

示例10: testTriggerEvents

 public function testTriggerEvents()
 {
     $this->dm->getEventManager()->addEventListener(array(Event::prePersist, Event::postPersist, Event::preUpdate, Event::postUpdate, Event::preRemove, Event::postRemove, Event::onFlush, Event::postFlush, Event::preFlush, Event::preMove, Event::postMove, Event::endFlush), $this->listener);
     $page = new CmsPage();
     $page->title = "my-page";
     $page->content = "long story";
     $this->dm->persist($page);
     $this->assertTrue($this->listener->pagePrePersist);
     $this->assertFalse($this->listener->itemPrePersist);
     $this->assertFalse($this->listener->postFlush);
     $this->assertFalse($this->listener->endFlush);
     $this->assertFalse($this->listener->preFlush);
     $this->dm->flush();
     $this->assertTrue($this->listener->onFlush);
     $this->assertTrue($this->listener->postFlush);
     $this->assertTrue($this->listener->endFlush);
     $this->assertTrue($this->listener->preFlush);
     $this->assertFalse($this->listener->preUpdate);
     $this->assertFalse($this->listener->postUpdate);
     $this->assertTrue($this->listener->pagePostPersist);
     $this->assertFalse($this->listener->itemPostPersist);
     $this->assertFalse($this->listener->pagePreRemove);
     $this->assertFalse($this->listener->pagePostRemove);
     $this->assertFalse($this->listener->itemPreRemove);
     $this->assertFalse($this->listener->pagePreMove);
     $this->assertFalse($this->listener->pagePostMove);
     $this->assertFalse($this->listener->itemPreMove);
     $this->assertFalse($this->listener->itemPostMove);
     $this->dm->move($page, '/functional/moved-' . $page->title);
     $this->assertFalse($this->listener->pagePreMove);
     $this->assertFalse($this->listener->pagePostMove);
     $this->dm->flush();
     $this->assertTrue($this->listener->pagePreMove);
     $this->assertTrue($this->listener->pagePostMove);
     $this->assertFalse($this->listener->itemPreMove);
     $this->assertFalse($this->listener->itemPostMove);
     $this->dm->flush();
     $item = new CmsItem();
     $item->name = "my-item";
     $item->documentTarget = $page;
     $page->content = "short story";
     $this->dm->persist($item);
     $page->addItem($item);
     $this->dm->flush();
     $this->assertTrue($this->listener->preUpdate);
     $this->assertTrue($this->listener->itemPrePersist);
     $this->assertTrue($this->listener->postUpdate);
     $this->assertTrue($this->listener->itemPostPersist);
     $this->assertEquals('long story is now short story', $page->content);
     $pageId = $this->dm->getUnitOfWork()->getDocumentId($page);
     $itemId = $this->dm->getUnitOfWork()->getDocumentId($item);
     $this->dm->clear();
     $page = $this->dm->find(null, $pageId);
     $item = $this->dm->find(null, $itemId);
     $this->assertEquals('long story is now short story', $page->content);
     $this->dm->remove($item);
     $this->dm->remove($page);
     $this->assertTrue($this->listener->pagePreRemove);
     $this->assertTrue($this->listener->itemPreRemove);
     $this->assertFalse($this->listener->pagePostRemove);
     $this->assertFalse($this->listener->itemPostRemove);
     $this->assertFalse($this->dm->contains($page));
     $this->assertFalse($this->dm->contains($item));
     $this->dm->flush();
     $this->assertFalse($this->dm->contains($page));
     $this->assertFalse($this->dm->contains($item));
     $this->assertTrue($this->listener->pagePostRemove);
     $this->assertTrue($this->listener->itemPostRemove);
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:69,代码来源:EventManagerTest.php


注:本文中的Doctrine\ODM\PHPCR\DocumentManager::getUnitOfWork方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。