本文整理匯總了PHP中Doctrine\ODM\PHPCR\DocumentManager::clear方法的典型用法代碼示例。如果您正苦於以下問題:PHP DocumentManager::clear方法的具體用法?PHP DocumentManager::clear怎麽用?PHP DocumentManager::clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ODM\PHPCR\DocumentManager
的用法示例。
在下文中一共展示了DocumentManager::clear方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testComputingBetweenEventsWithTranslation
public function testComputingBetweenEventsWithTranslation()
{
$this->dm->getEventManager()->addEventListener(array(Event::preCreateTranslation, Event::postLoadTranslation, Event::preRemoveTranslation, Event::postRemoveTranslation), $this->listener);
$this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
// Create initial user
$user = new \Doctrine\Tests\Models\CMS\CmsUserTranslatable();
$user->name = 'mdekrijger';
$user->username = 'mdekrijger';
$user->status = 'active';
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsUserTranslatable', $user->id, 'en');
// username should be changed after loading the translation
$this->assertEquals('loadTranslation', $user->username);
// name had been changed pre binding translation
$this->assertEquals('preCreateTranslation', $user->name);
$this->dm->name = 'neuer Name';
$this->dm->bindTranslation($user, 'de');
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsUserTranslatable', $user->id, 'en');
$this->dm->removeTranslation($user, 'en');
$this->assertEquals('preRemoveTranslation', $user->name);
$this->dm->flush();
$this->dm->clear();
$this->assertEquals('postRemoveTranslation', $user->username);
}
示例2: testLoadMany
public function testLoadMany()
{
$user1 = new CmsUser();
$user1->username = "beberlei";
$user1->status = "active";
$user1->name = "Benjamin";
$user2 = new CmsUser();
$user2->username = "lsmith";
$user2->status = "active";
$user2->name = "Lukas";
$this->dm->persist($user1);
$this->dm->persist($user2);
$this->dm->flush();
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id));
$this->assertSame($user1, $users['/functional/beberlei']);
$this->assertSame($user2, $users['/functional/lsmith']);
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->node->getIdentifier(), substr($user2->id, 1)));
$this->assertSame($user1, $users['/functional/beberlei']);
$this->assertSame($user2, $users['/functional/lsmith']);
$this->dm->clear();
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id));
$this->assertTrue(isset($users['/functional/beberlei']));
$this->assertTrue(isset($users['/functional/lsmith']));
$this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsUser', $users['/functional/beberlei']);
$this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsUser', $users['/functional/lsmith']);
$this->assertEquals($user1->username, $users['/functional/beberlei']->username);
$this->assertEquals($user2->username, $users['/functional/lsmith']->username);
$this->dm->clear();
// read second document into memory
$this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->find($user2->id);
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id));
$this->assertEquals('/functional/beberlei', $users->key(), 'Documents are not returned in the order they were requested');
}
示例3: testResetEvents
public function testResetEvents()
{
$page = new CmsPage();
$page->title = "my-page";
$pageContent = new CmsPageContent();
$pageContent->id = 1;
$pageContent->content = "long story";
$pageContent->formatter = "plaintext";
$page->content = $pageContent;
$this->dm->persist($page);
$this->assertEquals(serialize(array('id' => $pageContent->id)), $page->content);
$this->dm->flush();
$this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content);
// This is required as the originalData in the UnitOfWork doesn’t set the node of the Document
$this->dm->clear();
$pageLoaded = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsPage')->find($page->id);
$pageLoaded->title = "my-page-changed";
$this->assertEquals('my-page-changed', $pageLoaded->title);
$this->dm->flush();
$this->assertEquals('my-page', $pageLoaded->title);
$pageLoaded->content = $pageContent;
$this->dm->persist($pageLoaded);
$this->dm->flush();
$this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content);
}
示例4: testReferenceOneDifferentTargetDocuments
public function testReferenceOneDifferentTargetDocuments()
{
$ref1 = new RefType1TestObj();
$ref1->id = '/functional/ref1';
$ref1->name = 'Ref1';
$ref2 = new RefType2TestObj();
$ref2->id = '/functional/ref2';
$ref2->name = 'Ref2';
$this->dm->persist($ref1);
$this->dm->persist($ref2);
$referer1 = new ReferenceOneObj();
$referer1->id = '/functional/referer1';
$referer1->reference = $ref1;
$this->dm->persist($referer1);
$referer2 = new ReferenceOneObj();
$referer2->id = '/functional/referer2';
$referer2->reference = $ref2;
$this->dm->persist($referer2);
$this->dm->flush();
$this->dm->clear();
$referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer1');
$this->assertTrue($referer->reference instanceof RefType1TestObj);
$referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer2');
$this->assertTrue($referer->reference instanceof RefType2TestObj);
}
示例5: testMenuNode
public function testMenuNode()
{
$data = array('name' => 'test-node', 'label' => 'label_foobar', 'uri' => 'http://www.example.com/foo', 'route' => 'foo_route', 'linkType' => 'route', 'content' => $this->content, 'publishable' => false, 'publishStartDate' => new \DateTime('2013-06-18'), 'publishEndDate' => new \DateTime('2013-06-18'), 'attributes' => array('attr_foobar_1' => 'barfoo', 'attr_foobar_2' => 'barfoo'), 'childrenAttributes' => array('child_foobar_1' => 'barfoo', 'child_foobar_2' => 'barfoo'), 'linkAttributes' => array('link_foobar_1' => 'barfoo', 'link_foobar_2' => 'barfoo'), 'labelAttributes' => array('label_foobar_1' => 'barfoo', 'label_foobar_2' => 'barfoo'), 'extras' => array('extra_foobar_1' => 'barfoo', 'extra_foobar_2' => 'barfoo'), 'routeParameters' => array('route_param_foobar_1' => 'barfoo', 'route_param_foobar_2' => 'barfoo'), 'routeAbsolute' => true, 'display' => false, 'displayChildren' => false);
$startDateString = $data['publishStartDate']->format('Y-m-d');
$endDateString = $data['publishEndDate']->format('Y-m-d');
$menuNode = new MenuNode();
$refl = new \ReflectionClass($menuNode);
$menuNode->setParentDocument($this->rootDocument);
foreach ($data as $key => $value) {
$refl = new \ReflectionClass($menuNode);
$prop = $refl->getProperty($key);
$prop->setAccessible(true);
$prop->setValue($menuNode, $value);
}
$menuNode->addChild($this->child1);
$this->dm->persist($menuNode);
$this->dm->flush();
$this->dm->clear();
$menuNode = $this->dm->find(null, '/test/test-node');
$this->assertNotNull($menuNode);
foreach ($data as $key => $value) {
$prop = $refl->getProperty($key);
$prop->setAccessible(true);
$v = $prop->getValue($menuNode);
if (!is_object($value)) {
$this->assertEquals($value, $v);
}
}
// test objects
$prop = $refl->getProperty('content');
$prop->setAccessible(true);
$content = $prop->getValue($menuNode);
$this->assertEquals('fake_weak_content', $content->getName());
// test children
$this->assertCount(1, $menuNode->getChildren());
// test publish start and end
$publishStartDate = $menuNode->getPublishStartDate();
$publishEndDate = $menuNode->getPublishEndDate();
$this->assertInstanceOf('\\DateTime', $publishStartDate);
$this->assertInstanceOf('\\DateTime', $publishEndDate);
$this->assertEquals($startDateString, $publishStartDate->format('Y-m-d'));
$this->assertEquals($endDateString, $publishEndDate->format('Y-m-d'));
// test multi-lang
$menuNode->setLocale('fr');
$this->dm->persist($menuNode);
$this->dm->flush();
$this->dm->clear();
$menuNode = $this->dm->findTranslation(null, '/test/test-node', 'fr');
$this->assertEquals('fr', $menuNode->getLocale());
$child = $this->dm->find(null, '/test/test-node/child1');
$menuNode = $child->getParent();
$this->assertCount(1, $menuNode->getChildren());
$menuNode->removeChild($child);
$this->dm->flush();
$this->dm->clear();
$menuNode = $this->dm->find(null, '/test/test-node');
$this->assertCount(0, $menuNode->getChildren());
}
示例6: testDetach
public function testDetach()
{
$user = $this->dm->find($this->type, '/functional/lsmith');
$user->username = "new-name";
$this->dm->detach($user);
$this->dm->flush();
$this->dm->clear();
$newUser = $this->dm->find($this->type, '/functional/lsmith');
$this->assertEquals('lsmith', $newUser->username);
}
示例7: testCreateFromFile
public function testCreateFromFile()
{
$parent = new FixPHPCR1TestObj();
$parent->id = '/functional/filetest';
$this->dm->persist($parent);
$parent->file = new File();
$parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt');
$this->dm->flush();
$this->dm->clear();
$this->assertTrue($this->node->getNode('filetest')->hasNode('file'));
$this->assertTrue($this->node->getNode('filetest')->getNode('file')->hasNode('jcr:content'));
$this->assertTrue($this->node->getNode('filetest')->getNode('file')->getNode('jcr:content')->hasProperty('jcr:data'));
}
示例8: testCreateCascade
public function testCreateCascade()
{
$folder = new Folder();
$folder->setId('/functional/folder');
$file = new File();
$file->setFileContent(self::FILE_CONTENT);
$file->setNodename('file');
$folder->addChild($file);
$this->dm->persist($folder);
$this->dm->flush();
$this->dm->clear();
$this->assertFolderAndFile($this->node);
}
示例9: testCreatedDate
public function testCreatedDate()
{
$parent = new FileTestObj();
$parent->file = new File();
$parent->id = '/functional/filetest';
$parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt');
$this->dm->persist($parent);
$this->dm->flush();
$this->dm->clear();
$file = $this->dm->find('Doctrine\\ODM\\PHPCR\\Document\\File', '/functional/filetest/file');
$this->assertNotNull($file);
$this->assertNotNull($file->getCreated());
}
示例10: testTriggerTranslationEvents
public function testTriggerTranslationEvents()
{
$this->dm->getEventManager()->addEventListener(array(Event::preCreateTranslation, Event::postLoadTranslation, Event::preRemoveTranslation, Event::postRemoveTranslation), $this->listener);
$this->dm->setLocaleChooserStrategy(new LocaleChooser($this->localePrefs, 'en'));
$page = new CmsPageTranslatable();
$page->title = "my-page";
$page->content = "long story";
$this->dm->persist($page);
$this->assertFalse($this->listener->preCreateTranslation);
$this->assertFalse($this->listener->postLoadTranslation);
$this->assertFalse($this->listener->postRemoveTranslation);
$this->assertFalse($this->listener->postRemoveTranslation);
$this->dm->bindTranslation($page, 'en');
$this->assertTrue($this->listener->preCreateTranslation);
$this->assertFalse($this->listener->postLoadTranslation);
$this->assertFalse($this->listener->postRemoveTranslation);
$this->dm->flush();
$this->dm->clear();
$page = $this->dm->findTranslation('Doctrine\\Tests\\Models\\CMS\\CmsPageTranslatable', $page->id, 'en');
$this->assertTrue($this->listener->postLoadTranslation);
$page->title = 'neuer Titel';
$this->dm->bindTranslation($page, 'de');
$this->dm->flush();
$this->dm->removeTranslation($page, 'en');
$this->assertFalse($this->listener->postRemoveTranslation);
$this->assertTrue($this->listener->preRemoveTranslation);
$this->dm->flush();
$this->assertTrue($this->listener->postRemoveTranslation);
}
示例11: testComputeChangesetTranslatableFind
public function testComputeChangesetTranslatableFind()
{
$this->dm->getEventManager()->addEventListener(array(Event::postUpdate), $this->listener);
// Create initial user
$user1 = new \Doctrine\Tests\Models\CMS\CmsUserTranslatable();
$user1->name = 'david';
$user1->username = 'dbu';
$user1->status = 'activ';
$this->dm->persist($user1);
$this->dm->bindTranslation($user1, 'en');
$user1->status = 'actif';
$this->dm->bindTranslation($user1, 'fr');
$this->dm->flush();
$this->assertEquals(0, $this->listener->count);
$this->dm->clear();
$user1 = $this->dm->findTranslation(null, $user1->id, 'en');
$this->dm->findTranslation(null, $user1->id, 'fr');
$this->dm->flush();
$this->assertEquals(0, $this->listener->count);
$user1 = $this->dm->findTranslation(null, $user1->id, 'en');
$user1->status = 'active';
$this->dm->findTranslation(null, $user1->id, 'fr');
$this->dm->flush();
$this->assertEquals(1, $this->listener->count);
$this->dm->clear();
$user1 = $this->dm->findTranslation(null, $user1->id, 'en');
$this->assertEquals('active', $user1->status);
}
示例12: getTranslationNode
protected function getTranslationNode($parentNode, $locale)
{
$subNode = $parentNode->addNode(Translation::LOCALE_NAMESPACE . ":{$locale}");
$this->session->save();
$this->dm->clear();
return $subNode;
}
示例13: testProxyImplicit
public function testProxyImplicit()
{
$user = new CmsUser();
$user->name = 'Dominik';
$user->username = 'domnikl';
$user->status = 'developer';
$assistant = new CmsUser();
$assistant->username = 'bimbo';
$user->child = $assistant;
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->find(null, $user->id);
$assistant = $this->dm->find(null, $user->id . '/assistant');
$this->assertSame($assistant, $user->child);
}
示例14: testCascadeRemoveByCollection
public function testCascadeRemoveByCollection()
{
$referrerRefManyTestObj = new ReferrerRefTestObj2();
$referrerRefManyTestObj->id = "/functional/referrerRefManyTestObj";
$max = 5;
for ($i = 0; $i < $max; $i++) {
$newReferrerTestObj = new ReferrerTestObj2();
$newReferrerTestObj->id = "/functional/referrerTestObj{$i}";
$newReferrerTestObj->name = "referrerTestObj{$i}";
$newReferrerTestObj->reference = $referrerRefManyTestObj;
$this->dm->persist($newReferrerTestObj);
}
$this->dm->persist($referrerRefManyTestObj);
$this->dm->flush();
$this->dm->clear();
$referenced = $this->dm->find(null, "/functional/referrerRefManyTestObj");
$this->assertCount($max, $referenced->referrers);
$referenced->referrers->remove(0);
$referenced->referrers->remove(3);
$this->assertCount($max - 2, $referenced->referrers);
$this->dm->flush();
$this->dm->clear();
$referenced = $this->dm->find(null, "/functional/referrerRefManyTestObj");
$this->assertCount($max - 2, $referenced->referrers);
}
示例15: testInheritance
/**
* TypeUser is a superclass of TypeTeamUser
*/
public function testInheritance()
{
$user = new TypeTeamUser();
$user->username = "test";
$user->numbers = array(1, 2, 3);
$user->id = '/functional/test';
$user->name = 'inheritance';
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();
$userNew = $this->dm->find($this->type, '/functional/test');
$this->assertNotNull($userNew, "Have to hydrate user object!");
$this->assertEquals($user->username, $userNew->username);
$this->assertEquals($user->numbers, $userNew->numbers);
$this->assertEquals($user->name, $userNew->name);
}