"type": "object"
},
"Hooks": {
- "type": "object",
+ "type": [ "string", "object" ],
"description": "Hooks this extension uses (mapping of hook name to callback)"
},
"JobClasses": {
protected function extractHooks( array $info ) {
if ( isset( $info['Hooks'] ) ) {
foreach ( $info['Hooks'] as $name => $value ) {
- foreach ( (array)$value as $callback ) {
- $this->globals['wgHooks'][$name][] = $callback;
+ if ( is_array( $value ) ) {
+ foreach ( $value as $callback ) {
+ $this->globals['wgHooks'][$name][] = $callback;
+ }
+ } else {
+ $this->globals['wgHooks'][$name][] = $value;
}
}
}
}
public function handleHooks( $realName, $value ) {
- foreach ( $value as $hookName => $handlers ) {
+ foreach ( $value as $hookName => &$handlers ) {
foreach ( $handlers as $func ) {
if ( $func instanceof Closure ) {
$this->error( "Error: Closures cannot be converted to JSON. " .
);
}
}
+ if ( count( $handlers ) === 1 ) {
+ $handlers = $handlers[0];
+ }
}
$this->json[$realName] = $value;
}
self::$default,
$merge,
],
- // No current hooks, adding one for "FooBaz"
+ // No current hooks, adding one for "FooBaz" in string format
[
[],
[ 'Hooks' => [ 'FooBaz' => 'FooBazCallback' ] ] + self::$default,
[ 'Hooks' => [ 'FooBaz' => 'FooBazCallback' ] ] + self::$default,
[ 'FooBaz' => [ 'PriorCallback', 'FooBazCallback' ] ] + $merge,
],
+ // No current hooks, adding one for "FooBaz" in verbose array format
+ [
+ [],
+ [ 'Hooks' => [ 'FooBaz' => [ 'FooBazCallback' ] ] ] + self::$default,
+ [ 'FooBaz' => [ 'FooBazCallback' ] ] + $merge,
+ ],
// Hook for "BarBaz", adding one for "FooBaz"
[
[ 'BarBaz' => [ 'BarBazCallback' ] ],