本文整理匯總了PHP中Doctrine\ODM\PHPCR\DocumentManager::getEventManager方法的典型用法代碼示例。如果您正苦於以下問題:PHP DocumentManager::getEventManager方法的具體用法?PHP DocumentManager::getEventManager怎麽用?PHP DocumentManager::getEventManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ODM\PHPCR\DocumentManager
的用法示例。
在下文中一共展示了DocumentManager::getEventManager方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setUp
public function setUp()
{
$this->listener = new TestResetListener();
$this->dm = $this->createDocumentManager();
$this->node = $this->resetFunctionalNode($this->dm);
$this->dm->getEventManager()->addEventListener(array('prePersist', 'postPersist', 'preUpdate', 'postUpdate'), $this->listener);
}
示例2: 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);
}
示例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: __construct
/**
* Creates a new factory instance that uses the given DocumentManager instance.
*
* @param DocumentManager $dm The DocumentManager instance
*/
public function __construct(DocumentManager $dm)
{
$this->dm = $dm;
$conf = $this->dm->getConfiguration();
$this->setCacheDriver($conf->getMetadataCacheImpl());
$this->driver = $conf->getMetadataDriverImpl();
$this->evm = $this->dm->getEventManager();
}
示例5: 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);
}
示例6: testLoadClassMetadataEvent
public function testLoadClassMetadataEvent()
{
$listener = new Listener();
$evm = $this->dm->getEventManager();
$evm->addEventListener(array(Event::loadClassMetadata), $listener);
$meta = $this->getMetadataFor('Doctrine\\Tests\\ODM\\PHPCR\\Mapping\\Model\\DefaultMappingObject');
$this->assertTrue($listener->called);
$this->assertSame($this->dm, $listener->dm);
$this->assertSame($meta, $listener->meta);
}
示例7: testComputingBetweenEvents
public function testComputingBetweenEvents()
{
$this->dm->getEventManager()->addEventListener(array(Event::postLoad, Event::prePersist, Event::preUpdate, Event::postPersist, Event::postUpdate), $this->listener);
$entity = new SomeEntity();
$entity->id = '/functional/test';
$entity->status = new \stdClass();
$entity->status->value = 'active';
$entity->status->foo = 'bar';
$entity->text = 'test1';
$this->dm->persist($entity);
$this->dm->flush();
$this->assertInstanceOf('stdClass', $entity->status);
$this->assertAttributeNotEmpty('value', $entity->status);
$this->assertEquals($entity->status->value, 'active');
$this->assertObjectNotHasAttribute('foo', $entity->status);
$entity->status->value = 'inactive';
$entity->status->foo = 'bar2';
$entity->text = 'test2';
$this->dm->flush();
$this->assertInstanceOf('stdClass', $entity->status);
$this->assertAttributeNotEmpty('value', $entity->status);
$this->assertEquals($entity->status->value, 'inactive');
$this->assertObjectNotHasAttribute('foo', $entity->status);
$this->assertEquals($entity->text, 'test2');
$this->dm->clear();
$entity = $this->dm->find(null, $entity->id);
$this->assertInstanceOf('stdClass', $entity->status);
$this->assertAttributeNotEmpty('value', $entity->status);
$this->assertEquals($entity->status->value, 'inactive');
$this->assertObjectNotHasAttribute('foo', $entity->status);
$this->assertEquals($entity->text, 'test2');
$entity->status->value = 'active';
$this->dm->flush();
$this->assertInstanceOf('stdClass', $entity->status);
$this->assertAttributeNotEmpty('value', $entity->status);
$this->assertEquals($entity->status->value, 'active');
$this->assertEquals($entity->text, 'test2');
}
示例8: testResetReorderChildren
/**
* Reorder the children but reset the order in the preUpdate event
* Tests that the previously compute document change set gets overwritten
*
* @depends testReorderChildren
*/
public function testResetReorderChildren()
{
$this->createChildren();
$this->listener = new TestResetReorderingListener();
$this->dm->getEventManager()->addEventListener(array('preUpdate'), $this->listener);
/** @var $parent ChildrenTestObj */
$parent = $this->dm->find($this->type, '/functional/parent');
$this->assertEquals("Child A", $parent->allChildren->first()->name);
$parent->allChildren->remove('Child A');
$newChild = new ChildrenTestObj();
$newChild->name = 'Child A';
$parent->allChildren->add($newChild);
$this->dm->flush();
$this->dm->clear();
$parent = $this->dm->find($this->type, '/functional/parent');
$this->assertEquals("Child A", $parent->allChildren->first()->name);
$this->dm->getEventManager()->removeEventListener(array('preUpdate'), $this->listener);
}
示例9: __construct
/**
* @param DocumentManager $dm
*/
public function __construct(DocumentManager $dm)
{
$this->dm = $dm;
$this->session = $dm->getPhpcrSession();
$this->eventListenersInvoker = new ListenersInvoker($dm);
$this->eventManager = $dm->getEventManager();
$config = $dm->getConfiguration();
$this->documentClassMapper = $config->getDocumentClassMapper();
$this->validateDocumentName = $config->getValidateDoctrineMetadata();
$this->writeMetadata = $config->getWriteDoctrineMetadata();
$this->uuidGenerator = $config->getUuidGenerator();
if ($this->session instanceof JackalopeSession) {
$this->useFetchDepth = 'jackalope.fetch_depth';
}
}
示例10: __construct
/**
* @param DocumentManager $dm
*/
public function __construct(DocumentManager $dm)
{
$this->dm = $dm;
$this->session = $dm->getPhpcrSession();
$this->evm = $dm->getEventManager();
$config = $dm->getConfiguration();
$this->documentClassMapper = $config->getDocumentClassMapper();
$this->validateDocumentName = $config->getValidateDoctrineMetadata();
$this->writeMetadata = $config->getWriteDoctrineMetadata();
}
示例11: __construct
/**
* Initializes a new ListenersInvoker instance.
*
* @param DocumentManager $dm
*/
public function __construct(DocumentManager $dm)
{
$this->eventManager = $dm->getEventManager();
$this->dm = $dm;
}