X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHooks.php;h=f4f86be68bb0a0077351de0a82794d7f6257b65d;hb=165041b4e4314fb0f2d57ac999b58c694d9bfa00;hp=cd38a7d45e909b8cac48f1d0020559b0e5988404;hpb=9ab6887c8c93014a17afd6ab81f6bac3bf5effd6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Hooks.php b/includes/Hooks.php index cd38a7d45e..f4f86be68b 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -36,7 +36,7 @@ class Hooks { * Array of events mapped to an array of callbacks to be run * when that event is triggered. */ - protected static $handlers = array(); + protected static $handlers = []; /** * Attach an event handler to a given hook. @@ -48,7 +48,7 @@ class Hooks { */ public static function register( $name, $callback ) { if ( !isset( self::$handlers[$name] ) ) { - self::$handlers[$name] = array(); + self::$handlers[$name] = []; } self::$handlers[$name][] = $callback; @@ -64,7 +64,7 @@ class Hooks { * @throws MWException If not in testing mode. */ public static function clear( $name ) { - if ( !defined( 'MW_PHPUNIT_TEST' ) ) { + if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) { throw new MWException( 'Cannot reset hooks in operation.' ); } @@ -98,7 +98,7 @@ class Hooks { global $wgHooks; if ( !self::isRegistered( $name ) ) { - return array(); + return []; } elseif ( !isset( self::$handlers[$name] ) ) { return $wgHooks[$name]; } elseif ( !isset( $wgHooks[$name] ) ) { @@ -128,11 +128,11 @@ class Hooks { * processing to continue. Not returning a value (or explicitly * returning null) is equivalent to returning true. */ - public static function run( $event, array $args = array(), $deprecatedVersion = null ) { + public static function run( $event, array $args = [], $deprecatedVersion = null ) { foreach ( self::getHandlers( $event ) as $hook ) { // Turn non-array values into an array. (Can't use casting because of objects.) if ( !is_array( $hook ) ) { - $hook = array( $hook ); + $hook = [ $hook ]; } if ( !array_filter( $hook ) ) { @@ -163,7 +163,7 @@ class Hooks { } $func = get_class( $object ) . '::' . $method; - $callback = array( $object, $method ); + $callback = [ $object, $method ]; } elseif ( is_string( $hook[0] ) ) { $func = $callback = array_shift( $hook ); } else { @@ -176,22 +176,13 @@ class Hooks { throw new MWException( 'Invalid callback ' . $func . ' in hooks for ' . $event . "\n" ); } - /* - * Call the hook. The documentation of call_user_func_array says - * false is returned on failure. However, if the function signature - * does not match the call signature, PHP will issue an warning and - * return null instead. The following code catches that warning and - * provides better error message. - */ - $retval = null; - $badhookmsg = null; - $hook_args = array_merge( $hook, $args ); - // mark hook as deprecated, if deprecation version is specified if ( $deprecatedVersion !== null ) { wfDeprecated( "$event hook (used in $func)", $deprecatedVersion ); } + // Call the hook. + $hook_args = array_merge( $hook, $args ); $retval = call_user_func_array( $callback, $hook_args ); // Process the return value.