Go to the documentation of this file.
9 unset(
$wgHooks[
'MediaWikiHooksTest001'] );
18 [ $i,
'someNonStatic' ],
22 [
'Object and no method', [ $i ],
'changed-onevent',
'original' ],
24 'Object and method with data',
25 [ $i,
'someNonStaticWithData',
'data' ],
29 [
'Object and static method', [ $i,
'someStatic' ],
'changed-static',
'original' ],
31 'Class::method static call',
32 [
'NothingClass::someStatic' ],
37 'Class::method static call as array',
38 [ [
'NothingClass::someStatic' ] ],
42 [
'Global function', [
'NothingFunction' ],
'changed-func',
'original' ],
43 [
'Global function with data', [
'NothingFunctionData',
'data' ],
'data',
'original' ],
44 [
'Closure', [
function ( &$foo, $bar ) {
45 $foo =
'changed-closure';
48 } ],
'changed-closure',
'original' ],
49 [
'Closure with data', [
function ( $data, &$foo, $bar ) {
53 },
'data' ],
'data',
'original' ]
64 $foo = $bar =
'original';
67 Hooks::run(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
69 $this->assertSame( $expectedFoo, $foo, $msg );
70 $this->assertSame( $expectedBar, $bar, $msg );
88 $wgHooks[
'MediaWikiHooksTest001'][] = $a;
93 'Hook registered by $wgHooks'
100 'Hooks::getHandlers() should return hooks registered via wgHooks as well as Hooks::register'
104 unset(
$wgHooks[
'MediaWikiHooksTest001'] );
110 'Hook registered by Hook::register'
126 $wgHooks[
'MediaWikiHooksTest001'][] = $a;
129 'Hook registered via $wgHooks should be noticed by Hooks::isRegistered'
136 'Hooks::getHandlers() should return hooks registered via wgHooks as well as Hooks::register'
142 Hooks::run(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
146 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'
151 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'
179 Hooks::run(
'MediaWikiHooksTest001', [ &$foo ] );
180 $this->assertSame(
'original', $foo,
'Hooks abort after a false return.' );
196 Hooks::run(
'MediaWikiHooksTest001', [ &$foo ] );
197 $this->assertSame(
'test', $foo,
'Hooks continue after a null return.' );
211 Hooks::run(
'MediaWikiHooksTest001', [ &$foo ] );
212 $this->assertSame(
'test', $foo,
'Hooks that are falsey are skipped.' );
229 Hooks::register(
'MediaWikiHooksTest001',
'NothingClass::someStatic' );
230 Hooks::run(
'MediaWikiHooksTest001', [],
'1.31' );
253 $this->assertSame( [ 1, 2, 3 ], $list,
'All hooks ran.' );
270 $this->setExpectedException(
272 'Invalid return from hook-MediaWikiHooksTest001-closure for ' .
273 'unabortable MediaWikiHooksTest001'
291 $foo =
'changed-func';
306 $foo =
'changed-static';
313 $foo =
'changed-nonstatic';
314 $bar =
'changed-nonstatic';
321 $foo =
'changed-onevent';
testFalseReturn()
Hooks::run Hooks::callHook.
static getHandlers( $name)
Returns an array of all the event functions attached to a hook This combines functions registered via...
someNonStatic(&$foo, &$bar)
testFatalError()
FatalError Hooks::run.
NothingFunctionData( $data, &$foo, &$bar)
static clear( $name)
Clears hooks registered via Hooks::register().
testNullReturn()
Hooks::run.
testUncallableFunction()
MWException Hooks::run Hooks::callHook.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
testCallHook_UnknownDatatype()
Hooks::callHook MWException.
NothingFunction(&$foo, &$bar)
testRunWithoutAbortWarning()
Hooks::runWithoutAbort Hooks::callHook.
static someStatic(&$foo, &$bar)
testRunWithoutAbort()
Hooks::runWithoutAbort Hooks::callHook.
testCallHook_Deprecated()
Hooks::callHook PHPUnit_Framework_Error_Deprecated.
onMediaWikiHooksTest001(&$foo, &$bar)
testGetHandlers()
Hooks::getHandlers.
static runWithoutAbort( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static register( $name, $callback)
Attach an event handler to a given hook.
testCallHook_FalseHook()
Hooks::callHook.
static isRegistered( $name)
Returns true if a hook has a function registered to it.
testNewStyleHooks( $msg, $hook, $expectedFoo, $expectedBar)
provideHooks Hooks::register Hooks::run Hooks::callHook
$wgHooks['ArticleShow'][]
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
someNonStaticWithData( $data, &$foo, &$bar)
testNewStyleHookInteraction()
Hooks::isRegistered Hooks::register Hooks::run Hooks::callHook.