From: Kunal Mehta Date: Fri, 29 Jul 2016 00:01:08 +0000 (-0700) Subject: MediaHandlerFactory: Don't use any global state X-Git-Tag: 1.31.0-rc.0~6171^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/categories/modifier.php?a=commitdiff_plain;h=20bd328eb0f7d1418f9801be07307fd4ab279ca7;p=lhc%2Fweb%2Fwiklou.git MediaHandlerFactory: Don't use any global state Instead inject the configured MediaHandlers in the service constructor. Change-Id: I039c01ef531389c74524cb7adcb8cf1229d9a95d --- diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 438f667c37..21c6377320 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -159,7 +159,9 @@ return [ }, 'MediaHandlerFactory' => function( MediaWikiServices $services ) { - return new MediaHandlerFactory(); + return new MediaHandlerFactory( + $services->getMainConfig()->get( 'MediaHandlers' ) + ); }, 'LinkCache' => function( MediaWikiServices $services ) { diff --git a/includes/media/MediaHandlerFactory.php b/includes/media/MediaHandlerFactory.php index 1deecd7b09..543dc80dfd 100644 --- a/includes/media/MediaHandlerFactory.php +++ b/includes/media/MediaHandlerFactory.php @@ -49,6 +49,11 @@ class MediaHandlerFactory { 'image/x-djvu' => DjVuHandler::class, // compat ]; + /** + * @var array + */ + private $registry; + /** * Instance cache of MediaHandler objects by mimetype * @@ -56,12 +61,13 @@ class MediaHandlerFactory { */ private $handlers; - protected function getHandlerClass( $type ) { - global $wgMediaHandlers; + public function __construct( array $registry ) { + $this->registry = $registry + self::$coreHandlers; + } - $registry = $wgMediaHandlers + self::$coreHandlers; - if ( isset( $registry[$type] ) ) { - return $registry[$type]; + protected function getHandlerClass( $type ) { + if ( isset( $this->registry[$type] ) ) { + return $this->registry[$type]; } else { return false; } diff --git a/tests/phpunit/mocks/media/MockMediaHandlerFactory.php b/tests/phpunit/mocks/media/MockMediaHandlerFactory.php index 0bcc6eba45..54d46b0271 100644 --- a/tests/phpunit/mocks/media/MockMediaHandlerFactory.php +++ b/tests/phpunit/mocks/media/MockMediaHandlerFactory.php @@ -36,6 +36,10 @@ class MockMediaHandlerFactory extends MediaHandlerFactory { 'application/ogg' => MockOggHandler::class, ]; + public function __construct() { + // override parent + } + protected function getHandlerClass( $type ) { if ( isset( self::$overrides[$type] ) ) { return self::$overrides[$type];