mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-23 15:56:55 +00:00
Create HookRunner class and the hook handler interfaces
Bug: T271026 Change-Id: If525e0f950b3a098162b19373edb3b443f559bf2
This commit is contained in:
parent
8811ea784e
commit
2ee5768ef5
40
includes/Hooks/HookRunner.php
Normal file
40
includes/Hooks/HookRunner.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Scribunto\Hooks;
|
||||
|
||||
use MediaWiki\HookContainer\HookContainer;
|
||||
|
||||
/**
|
||||
* This is a hook runner class, see docs/Hooks.md in core.
|
||||
* @internal
|
||||
*/
|
||||
class HookRunner implements
|
||||
ScribuntoExternalLibrariesHook,
|
||||
ScribuntoExternalLibraryPathsHook
|
||||
{
|
||||
private HookContainer $hookContainer;
|
||||
|
||||
public function __construct( HookContainer $hookContainer ) {
|
||||
$this->hookContainer = $hookContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function onScribuntoExternalLibraries( string $engine, array &$extraLibraries ) {
|
||||
return $this->hookContainer->run(
|
||||
'ScribuntoExternalLibraries',
|
||||
[ $engine, &$extraLibraries ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function onScribuntoExternalLibraryPaths( string $engine, array &$extraLibraryPaths ) {
|
||||
return $this->hookContainer->run(
|
||||
'ScribuntoExternalLibraryPaths',
|
||||
[ $engine, &$extraLibraryPaths ]
|
||||
);
|
||||
}
|
||||
}
|
19
includes/Hooks/ScribuntoExternalLibrariesHook.php
Normal file
19
includes/Hooks/ScribuntoExternalLibrariesHook.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Scribunto\Hooks;
|
||||
|
||||
/**
|
||||
* This is a hook handler interface, see docs/Hooks.md in core.
|
||||
* Use the hook name "ScribuntoExternalLibraries" to register handlers implementing this interface.
|
||||
*
|
||||
* @stable to implement
|
||||
* @ingroup Hooks
|
||||
*/
|
||||
interface ScribuntoExternalLibrariesHook {
|
||||
/**
|
||||
* @param string $engine
|
||||
* @param array &$extraLibraries
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onScribuntoExternalLibraries( string $engine, array &$extraLibraries );
|
||||
}
|
19
includes/Hooks/ScribuntoExternalLibraryPathsHook.php
Normal file
19
includes/Hooks/ScribuntoExternalLibraryPathsHook.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Scribunto\Hooks;
|
||||
|
||||
/**
|
||||
* This is a hook handler interface, see docs/Hooks.md in core.
|
||||
* Use the hook name "ScribuntoExternalLibraryPaths" to register handlers implementing this interface.
|
||||
*
|
||||
* @stable to implement
|
||||
* @ingroup Hooks
|
||||
*/
|
||||
interface ScribuntoExternalLibraryPathsHook {
|
||||
/**
|
||||
* @param string $engine
|
||||
* @param array &$extraLibraryPaths
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onScribuntoExternalLibraryPaths( string $engine, array &$extraLibraryPaths );
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
namespace MediaWiki\Extension\Scribunto;
|
||||
|
||||
use MediaWiki\Extension\Scribunto\Hooks\HookRunner;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Parser;
|
||||
use ParserOutput;
|
||||
|
@ -256,8 +257,8 @@ abstract class ScribuntoEngineBase {
|
|||
*/
|
||||
protected function getLibraries( $engine, array $coreLibraries = [] ) {
|
||||
$extraLibraries = [];
|
||||
MediaWikiServices::getInstance()->getHookContainer()
|
||||
->run( 'ScribuntoExternalLibraries', [ $engine, &$extraLibraries ] );
|
||||
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
|
||||
->onScribuntoExternalLibraries( $engine, $extraLibraries );
|
||||
return $coreLibraries + $extraLibraries;
|
||||
}
|
||||
|
||||
|
@ -270,8 +271,8 @@ abstract class ScribuntoEngineBase {
|
|||
*/
|
||||
protected function getLibraryPaths( $engine, array $coreLibraryPaths = [] ) {
|
||||
$extraLibraryPaths = [];
|
||||
MediaWikiServices::getInstance()->getHookContainer()
|
||||
->run( 'ScribuntoExternalLibraryPaths', [ $engine, &$extraLibraryPaths ] );
|
||||
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
|
||||
->onScribuntoExternalLibraryPaths( $engine, $extraLibraryPaths );
|
||||
return array_merge( $coreLibraryPaths, $extraLibraryPaths );
|
||||
}
|
||||
|
||||
|
|
16
tests/phpunit/unit/HookRunnerTest.php
Normal file
16
tests/phpunit/unit/HookRunnerTest.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Scribunto\Tests\Unit;
|
||||
|
||||
use MediaWiki\Extension\Scribunto\Hooks\HookRunner;
|
||||
use MediaWiki\Tests\HookContainer\HookRunnerTestBase;
|
||||
|
||||
/**
|
||||
* @covers \MediaWiki\Extension\Scribunto\Hooks\HookRunner
|
||||
*/
|
||||
class HookRunnerTest extends HookRunnerTestBase {
|
||||
|
||||
public static function provideHookRunners() {
|
||||
yield HookRunner::class => [ HookRunner::class ];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue