本文整理汇总了PHP中Doctrine\ODM\PHPCR\DocumentManager::persist方法的典型用法代码示例。如果您正苦于以下问题:PHP DocumentManager::persist方法的具体用法?PHP DocumentManager::persist怎么用?PHP DocumentManager::persist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\PHPCR\DocumentManager
的用法示例。
在下文中一共展示了DocumentManager::persist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: createAction
public function createAction()
{
// bind form to page model
$page = new Page();
$this->form->bind($this->request, $page);
if ($this->form->isValid()) {
try {
// path for page
$parent = $this->form->get('parent')->getData();
$path = $parent . '/' . $page->name;
// save page
$this->dm->persist($page, $path);
$this->dm->flush();
// redirect with message
$this->request->getSession()->setFlash('notice', 'Page created!');
return $this->redirect($this->generateUrl('admin'));
} catch (HTTPErrorException $e) {
$path = new PropertyPath('name');
$this->form->addError(new DataError('Name already in use.'), $path->getIterator());
}
}
return $this->render('SandboxAdminBundle:Admin:create.html.twig', array('form' => $this->form));
}
示例6: setUp
public function setUp()
{
$this->dm = $this->createDocumentManager(array(__DIR__));
$repository = $this->dm->getPhpcrSession()->getRepository();
if (!$repository->getDescriptor('node.type.management.orderable.child.nodes.supported')) {
$this->markTestSkipped('PHPCR repository doesn\'t support orderable child nodes');
}
$this->node = $this->resetFunctionalNode($this->dm);
$parent = $this->dm->find(null, $this->node->getPath());
$node1 = new Generic();
$node1->setParentDocument($parent);
$node1->setNodename('source');
$this->dm->persist($node1);
$this->childrenNames = array('first', 'second', 'third', 'fourth');
foreach ($this->childrenNames as $childName) {
$child = new Generic();
$child->setNodename($childName);
$child->setParentDocument($node1);
$this->dm->persist($child);
}
$node2 = new Generic();
$node2->setNodename('target');
$node2->setParentDocument($parent);
$this->dm->persist($node2);
$this->dm->flush();
$this->dm->clear();
}
示例7: testDetachWithPerist
/**
* @expectedException \Doctrine\ODM\PHPCR\Exception\InvalidArgumentException
*/
public function testDetachWithPerist()
{
$user = $this->dm->find($this->type, '/functional/lsmith');
$user->username = "new-name";
$this->dm->detach($user);
$this->dm->persist($user);
}
示例8: persistGreetingAction
public function persistGreetingAction()
{
$greeting = new Greeting();
$greeting->setContent('Hello World!');
$this->documentManager->persist($greeting);
$this->documentManager->flush();
return array('greeting' => $greeting);
}
示例9: 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());
}
示例10: update
/**
* {@inheritDoc}
*
* @throws ModelManagerException if the document manager throws any exception
*/
public function update($object)
{
try {
$this->dm->persist($object);
$this->dm->flush();
} catch (\Exception $e) {
throw new ModelManagerException('', 0, $e);
}
}
示例11: 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'));
}
示例12: 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);
}
示例13: 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());
}
示例14: testModificationWithProtectedProperty
public function testModificationWithProtectedProperty()
{
$object = new ProtectedPropertyTestObj();
$object->id = '/functional/pp';
try {
$this->dm->persist($object);
$this->dm->flush();
$object->changeme = 'changed';
$this->dm->flush();
$this->dm->clear();
} catch (\PHPCR\NodeType\ConstraintViolationException $e) {
$this->fail(sprintf('A ConstraintViolationException has been thrown when persisting document ("%s").', $e->getMessage()));
}
$this->assertTrue(true);
}
示例15: 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);
}