8 Hooks::clear(
'MediaWikiHooksTest001' );
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' ],
36 [
'Global function', [
'NothingFunction' ],
'changed-func',
'original' ],
37 [
'Global function with data', [
'NothingFunctionData',
'data' ],
'data',
'original' ],
38 [
'Closure', [
function ( &$foo, $bar ) {
39 $foo =
'changed-closure';
42 } ],
'changed-closure',
'original' ],
43 [
'Closure with data', [
function ( $data, &$foo, $bar ) {
47 },
'data' ],
'data',
'original' ]
59 $foo = $bar =
'original';
61 $wgHooks[
'MediaWikiHooksTest001'][] = $hook;
62 wfRunHooks(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
64 $this->assertSame( $expectedFoo, $foo, $msg );
65 $this->assertSame( $expectedBar, $bar, $msg );
75 $foo = $bar =
'original';
77 Hooks::register(
'MediaWikiHooksTest001', $hook );
78 Hooks::run(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
80 $this->assertSame( $expectedFoo, $foo, $msg );
81 $this->assertSame( $expectedBar, $bar, $msg );
97 $wgHooks[
'MediaWikiHooksTest001'][] = $a;
99 Hooks::isRegistered(
'MediaWikiHooksTest001' ),
100 'Hook registered via $wgHooks should be noticed by Hooks::isRegistered'
103 Hooks::register(
'MediaWikiHooksTest001', $b );
106 count( Hooks::getHandlers(
'MediaWikiHooksTest001' ) ),
107 'Hooks::getHandlers() should return hooks registered via wgHooks as well as Hooks::register'
113 Hooks::run(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
117 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'
122 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'
132 Hooks::register(
'MediaWikiHooksTest001',
'ThisFunctionDoesntExist' );
133 Hooks::run(
'MediaWikiHooksTest001', [] );
141 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
144 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
150 Hooks::run(
'MediaWikiHooksTest001', [ &$foo ] );
151 $this->assertSame(
'original', $foo,
'Hooks abort after a false return.' );
160 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
164 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
168 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
173 Hooks::runWithoutAbort(
'MediaWikiHooksTest001', [ &$list ] );
174 $this->assertSame( [ 1, 2, 3 ], $list,
'All hooks ran.' );
182 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
185 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
191 $this->setExpectedException(
192 UnexpectedValueException::class,
193 'Invalid return from hook-MediaWikiHooksTest001-closure for ' .
194 'unabortable MediaWikiHooksTest001'
196 Hooks::runWithoutAbort(
'MediaWikiHooksTest001', [ &$foo ] );
204 Hooks::register(
'MediaWikiHooksTest001',
function () {
207 Hooks::run(
'MediaWikiHooksTest001', [] );
212 $foo =
'changed-func';
227 $foo =
'changed-static';
234 $foo =
'changed-nonstatic';
235 $bar =
'changed-nonstatic';
242 $foo =
'changed-onevent';
wfRunHooks( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
NothingFunction(&$foo, &$bar)
NothingFunctionData( $data, &$foo, &$bar)
testFatalError()
FatalError Hooks::run.
testUncallableFunction()
MWException Hooks::run Hooks::callHook.
testOldStyleHooks( $msg, array $hook, $expectedFoo, $expectedBar)
provideHooks wfRunHooks
testFalseReturn()
Hooks::run Hooks::callHook.
testNewStyleHookInteraction()
Hooks::isRegistered Hooks::register Hooks::getHandlers Hooks::run Hooks::callHook.
testNewStyleHooks( $msg, $hook, $expectedFoo, $expectedBar)
provideHooks Hooks::register Hooks::run Hooks::callHook
testRunWithoutAbortWarning()
Hooks::runWithoutAbort Hooks::callHook.
testRunWithoutAbort()
Hooks::runWithoutAbort Hooks::callHook.
static someStatic(&$foo, &$bar)
someNonStaticWithData( $data, &$foo, &$bar)
someNonStatic(&$foo, &$bar)
onMediaWikiHooksTest001(&$foo, &$bar)
when a variable name is used in a it is silently declared as a new local masking the global
the array() calling protocol came about after MediaWiki 1.4rc1.
$wgHooks['ArticleShow'][]
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