本文整理匯總了PHP中Doctrine\ODM\PHPCR\DocumentManager::contains方法的典型用法代碼示例。如果您正苦於以下問題:PHP DocumentManager::contains方法的具體用法?PHP DocumentManager::contains怎麽用?PHP DocumentManager::contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ODM\PHPCR\DocumentManager
的用法示例。
在下文中一共展示了DocumentManager::contains方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testCascadeManagedDocumentReferrerDuringFlush
public function testCascadeManagedDocumentReferrerDuringFlush()
{
$user = new \Doctrine\Tests\Models\CMS\CmsUser();
$user->username = "dbu";
$user->name = "David";
$this->dm->persist($user);
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
$article->text = "foo";
$article->topic = "bar";
$article->id = '/functional/article_referrer';
$user->articlesReferrers->add($article);
$this->assertFalse($this->dm->contains($article));
$this->dm->flush();
$this->assertEquals($user, $article->user);
$this->dm->clear();
$user = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', '/functional/dbu');
$this->assertNotNull($user);
$this->assertTrue(1 <= count($user->articlesReferrers));
$savedArticle = $user->articlesReferrers->first();
$this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsArticle', $savedArticle);
$this->assertEquals($article->id, $savedArticle->id);
$savedArticle->user = null;
$this->dm->flush();
$this->dm->clear();
$removedArticle = $user->articlesReferrers->first();
$this->assertNull($removedArticle->user);
}
示例2: testProxyIsIgnored
public function testProxyIsIgnored()
{
$user = new CmsUser();
$user->name = 'Dominik';
$user->username = 'domnikl';
$user->status = 'developer';
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->getReference(get_class($user), $user->id);
$otherUser = new CmsUser();
$otherUser->name = 'Dominik2';
$otherUser->username = 'domnikl2';
$otherUser->status = 'developer';
$this->dm->persist($otherUser);
$this->dm->flush($user);
$this->assertTrue($this->dm->contains($otherUser), "Other user is contained in DocumentManager");
$this->assertTrue($otherUser->id != null, "other user has no id");
}
示例3: 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);
}