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


PHP Events::addListener方法代码示例

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


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

示例1: testFire

 /**
  * @todo Implement testFire().
  */
 public function testFire()
 {
     $observer = new EventsTestObserver();
     $this->object->addListener('fire', array($observer, 'invoke'));
     $event = new GenericEvent('dontfire', array('a' => 1, 'b' => 2));
     $this->object->dispatch('dontfire');
     $this->assertEquals(0, $observer->invoked);
     $event = new GenericEvent('fire', array('a' => 18, 'b' => 81));
     $this->object->dispatch('fire', $event);
     $this->assertEquals(1, $observer->invoked);
     $this->assertEquals('81', $observer->event['b']);
 }
开发者ID:masteramuk,项目名称:concrete5,代码行数:15,代码来源:EventsTest.php

示例2: testOverringDefaultFunctionalityWithEvents

 public function testOverringDefaultFunctionalityWithEvents()
 {
     $log = new Logger('emails');
     // should only have a database handler.
     $this->assertEquals(count($log->getHandlers()), 1);
     $this->assertEquals(count(Log::getHandlers()), 2);
     // this should still have the same stream handler from last test.
     $handler = new \Monolog\Handler\TestHandler(Logger::CRITICAL, false);
     $listener = Events::addListener('on_logger_create', function ($event) use($handler) {
         $logger = $event->getLogger();
         $formatter = new \Monolog\Formatter\LineFormatter();
         $handler->setFormatter($formatter);
         $logger->pushHandler($handler);
         return $logger;
     });
     $log2 = new Logger('transactions');
     $log3 = new Logger('testing');
     $this->assertEquals(count($log2->getHandlers()), 2);
     $this->assertEquals(count($log3->getHandlers()), 2);
     $log2->info('This is a test.');
     $log2->debug('This is a test.');
     $log3->debug('This is a test.');
     $log3->critical("oh boy this is big.");
     $log3->alert("Everything is broken.");
     $log3->emergency("Get out of bed.");
     $db = Database::get();
     $r = $db->GetAll('select * from Logs');
     $this->assertEquals(count($r), 3);
     // only the non-critical, non-alert, non-emergency items.
     $this->assertEquals(count($handler->getRecords()), 3);
     $records = $handler->getRecords();
     $this->assertEquals($records[0]['level'], Logger::CRITICAL);
     $this->assertEquals($records[1]['level'], Logger::ALERT);
     $this->assertEquals($records[2]['level'], Logger::EMERGENCY);
     $this->assertEquals($records[2]['message'], 'Get out of bed.');
     $listeners = Events::getListeners('on_logger_create');
     Events::removeListener('on_logger_create', $listeners[0]);
     // AND we pop the stream handler from the previous test
     Log::popHandler();
 }
开发者ID:meixelsberger,项目名称:concrete5-5.7.0,代码行数:40,代码来源:LogTest.php

示例3: testPagePathEvent

 public function testPagePathEvent()
 {
     $blog = self::createPage('Blog');
     $post1 = self::createPage('Post', $blog);
     $pathObject = $post1->getCollectionPathObject();
     $this->assertInstanceOf('\\Concrete\\Core\\Page\\PagePath', $pathObject);
     $this->assertEquals('/blog/post', $pathObject->getPagePath());
     Events::addListener('on_compute_canonical_page_path', function ($event) {
         $parent = Page::getByID($event->getPageObject()->getCollectionParentID());
         if ($parent->getCollectionPath() == '/blog') {
             // strip off the handle
             $path = substr($event->getPagePath(), 0, strrpos($event->getPagePath(), '/'));
             $path .= '/year/month/day/';
             $path .= $event->getPageObject()->getCollectionHandle();
             $event->setPagePath($path);
         }
     });
     $post2 = self::createPage('Another Post', $blog);
     $this->assertEquals('/blog/year/month/day/another-post', $post2->getCollectionPath());
     $post2Object = Page::getByPath('/blog/year/month/day/another-post');
     $this->assertEquals(4, $post2Object->getCollectionID());
     $addendum = self::createPage('Addendum', $post2Object);
     $path = $addendum->getCollectionPathObject();
     $this->assertInstanceOf('\\Concrete\\Core\\Page\\PagePath', $path);
     $this->assertEquals('/blog/year/month/day/another-post/addendum', $path->getPagePath());
     $home = Page::getByID(1);
     $addendum->move($home);
     $this->assertEquals('/addendum', $addendum->getCollectionPath());
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:29,代码来源:PagePathTest.php


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