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' ],
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';
66 Hooks::register(
'MediaWikiHooksTest001', $hook );
67 Hooks::run(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
69 $this->assertSame( $expectedFoo, $foo, $msg );
70 $this->assertSame( $expectedBar, $bar, $msg );
81 Hooks::getHandlers(
'MediaWikiHooksTest001' ),
88 $wgHooks[
'MediaWikiHooksTest001'][] = $a;
92 Hooks::getHandlers(
'MediaWikiHooksTest001' ),
93 'Hook registered by $wgHooks'
96 Hooks::register(
'MediaWikiHooksTest001', $b );
99 Hooks::getHandlers(
'MediaWikiHooksTest001' ),
100 'Hooks::getHandlers() should return hooks registered via wgHooks as well as Hooks::register'
103 Hooks::clear(
'MediaWikiHooksTest001' );
104 unset(
$wgHooks[
'MediaWikiHooksTest001'] );
106 Hooks::register(
'MediaWikiHooksTest001', $b );
109 Hooks::getHandlers(
'MediaWikiHooksTest001' ),
110 'Hook registered by Hook::register'
126 $wgHooks[
'MediaWikiHooksTest001'][] = $a;
128 Hooks::isRegistered(
'MediaWikiHooksTest001' ),
129 'Hook registered via $wgHooks should be noticed by Hooks::isRegistered'
132 Hooks::register(
'MediaWikiHooksTest001', $b );
135 count( Hooks::getHandlers(
'MediaWikiHooksTest001' ) ),
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'
161 Hooks::register(
'MediaWikiHooksTest001',
'ThisFunctionDoesntExist' );
162 Hooks::run(
'MediaWikiHooksTest001', [] );
170 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
173 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
179 Hooks::run(
'MediaWikiHooksTest001', [ &$foo ] );
180 $this->assertSame(
'original', $foo,
'Hooks abort after a false return.' );
187 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
190 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
196 Hooks::run(
'MediaWikiHooksTest001', [ &$foo ] );
197 $this->assertSame(
'test', $foo,
'Hooks continue after a null return.' );
204 Hooks::register(
'MediaWikiHooksTest001',
false );
205 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
211 Hooks::run(
'MediaWikiHooksTest001', [ &$foo ] );
212 $this->assertSame(
'test', $foo,
'Hooks that are falsey are skipped.' );
220 Hooks::register(
'MediaWikiHooksTest001', 12345 );
221 Hooks::run(
'MediaWikiHooksTest001' );
229 Hooks::register(
'MediaWikiHooksTest001',
'NothingClass::someStatic' );
230 Hooks::run(
'MediaWikiHooksTest001', [],
'1.31' );
239 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
243 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
247 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
252 Hooks::runWithoutAbort(
'MediaWikiHooksTest001', [ &$list ] );
253 $this->assertSame( [ 1, 2, 3 ], $list,
'All hooks ran.' );
261 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
264 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
270 $this->setExpectedException(
271 UnexpectedValueException::class,
272 'Invalid return from hook-MediaWikiHooksTest001-closure for ' .
273 'unabortable MediaWikiHooksTest001'
275 Hooks::runWithoutAbort(
'MediaWikiHooksTest001', [ &$foo ] );
283 Hooks::register(
'MediaWikiHooksTest001',
function () {
286 Hooks::run(
'MediaWikiHooksTest001', [] );
291 $foo =
'changed-func';
306 $foo =
'changed-static';
313 $foo =
'changed-nonstatic';
314 $bar =
'changed-nonstatic';
321 $foo =
'changed-onevent';
NothingFunction(&$foo, &$bar)
NothingFunctionData( $data, &$foo, &$bar)
testFatalError()
FatalError Hooks::run.
testUncallableFunction()
MWException Hooks::run Hooks::callHook.
testCallHook_Deprecated()
Hooks::callHook PHPUnit_Framework_Error_Deprecated.
testFalseReturn()
Hooks::run Hooks::callHook.
testNewStyleHookInteraction()
Hooks::isRegistered Hooks::register Hooks::run Hooks::callHook.
testNewStyleHooks( $msg, $hook, $expectedFoo, $expectedBar)
provideHooks Hooks::register Hooks::run Hooks::callHook
testRunWithoutAbortWarning()
Hooks::runWithoutAbort Hooks::callHook.
testCallHook_UnknownDatatype()
Hooks::callHook MWException.
testNullReturn()
Hooks::run.
testGetHandlers()
Hooks::getHandlers.
testRunWithoutAbort()
Hooks::runWithoutAbort Hooks::callHook.
testCallHook_FalseHook()
Hooks::callHook.
static someStatic(&$foo, &$bar)
someNonStaticWithData( $data, &$foo, &$bar)
someNonStatic(&$foo, &$bar)
onMediaWikiHooksTest001(&$foo, &$bar)
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
$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