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


PHP Hooks::getHandlers方法代码示例

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


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

示例1: testNewStyleHookInteraction

 /**
  * @covers Hooks::isRegistered
  * @covers Hooks::register
  * @covers Hooks::getHandlers
  * @covers Hooks::run
  */
 public function testNewStyleHookInteraction()
 {
     global $wgHooks;
     $a = new NothingClass();
     $b = new NothingClass();
     $wgHooks['MediaWikiHooksTest001'][] = $a;
     $this->assertTrue(Hooks::isRegistered('MediaWikiHooksTest001'), 'Hook registered via $wgHooks should be noticed by Hooks::isRegistered');
     Hooks::register('MediaWikiHooksTest001', $b);
     $this->assertEquals(2, count(Hooks::getHandlers('MediaWikiHooksTest001')), 'Hooks::getHandlers() should return hooks registered via wgHooks as well as Hooks::register');
     $foo = 'quux';
     $bar = 'qaax';
     Hooks::run('MediaWikiHooksTest001', array(&$foo, &$bar));
     $this->assertEquals(1, $a->calls, 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register');
     $this->assertEquals(1, $b->calls, 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register');
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:21,代码来源:HooksTest.php

示例2: runLegacyHooks

 /**
  * Call a legacy hook that uses text instead of Content objects.
  * Will log a warning when a matching hook function is registered.
  * If the textual representation of the content is changed by the
  * hook function, a new Content object is constructed from the new
  * text.
  *
  * @param string $event Event name
  * @param array $args Parameters passed to hook functions
  * @param bool $warn Whether to log a warning.
  *                    Default to self::$enableDeprecationWarnings.
  *                    May be set to false for testing.
  *
  * @return bool True if no handler aborted the hook
  *
  * @see ContentHandler::$enableDeprecationWarnings
  */
 public static function runLegacyHooks($event, $args = array(), $warn = null)
 {
     if ($warn === null) {
         $warn = self::$enableDeprecationWarnings;
     }
     if (!Hooks::isRegistered($event)) {
         return true;
         // nothing to do here
     }
     if ($warn) {
         // Log information about which handlers are registered for the legacy hook,
         // so we can find and fix them.
         $handlers = Hooks::getHandlers($event);
         $handlerInfo = array();
         wfSuppressWarnings();
         foreach ($handlers as $handler) {
             if (is_array($handler)) {
                 if (is_object($handler[0])) {
                     $info = get_class($handler[0]);
                 } else {
                     $info = $handler[0];
                 }
                 if (isset($handler[1])) {
                     $info .= '::' . $handler[1];
                 }
             } elseif (is_object($handler)) {
                 $info = get_class($handler[0]);
                 $info .= '::on' . $event;
             } else {
                 $info = $handler;
             }
             $handlerInfo[] = $info;
         }
         wfRestoreWarnings();
         wfWarn("Using obsolete hook {$event} via ContentHandler::runLegacyHooks()! Handlers: " . implode(', ', $handlerInfo), 2);
     }
     // convert Content objects to text
     $contentObjects = array();
     $contentTexts = array();
     foreach ($args as $k => $v) {
         if ($v instanceof Content) {
             /* @var Content $v */
             $contentObjects[$k] = $v;
             $v = $v->serialize();
             $contentTexts[$k] = $v;
             $args[$k] = $v;
         }
     }
     // call the hook functions
     $ok = wfRunHooks($event, $args);
     // see if the hook changed the text
     foreach ($contentTexts as $k => $orig) {
         /* @var Content $content */
         $modified = $args[$k];
         $content = $contentObjects[$k];
         if ($modified !== $orig) {
             // text was changed, create updated Content object
             $content = $content->getContentHandler()->unserializeContent($modified);
         }
         $args[$k] = $content;
     }
     return $ok;
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:80,代码来源:ContentHandler.php


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