本文整理汇总了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');
}
示例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;
}