diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
commit | c9aa36da061816dee256a979c2ff8d2ee41824d9 (patch) | |
tree | 29f7002b80ee984b488bd047dbbd80b36bf892e9 /includes/filebackend/FileBackendGroup.php | |
parent | b4274e0e33eafb5e9ead9d949ebf031a9fb8363b (diff) | |
parent | d1ba966140d7a60cd5ae4e8667ceb27c1a138592 (diff) |
Merge branch 'archwiki'
# Conflicts:
# skins/ArchLinux.php
# skins/ArchLinux/archlogo.gif
Diffstat (limited to 'includes/filebackend/FileBackendGroup.php')
-rw-r--r-- | includes/filebackend/FileBackendGroup.php | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index be8a2076..1b88db7e 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -29,15 +29,14 @@ * @since 1.19 */ class FileBackendGroup { - /** - * @var FileBackendGroup - */ + /** @var FileBackendGroup */ protected static $instance = null; - /** @var Array (name => ('class' => string, 'config' => array, 'instance' => object)) */ + /** @var array (name => ('class' => string, 'config' => array, 'instance' => object)) */ protected $backends = array(); - protected function __construct() {} + protected function __construct() { + } /** * @return FileBackendGroup @@ -47,13 +46,12 @@ class FileBackendGroup { self::$instance = new self(); self::$instance->initFromGlobals(); } + return self::$instance; } /** * Destroy the singleton instance - * - * @return void */ public static function destroySingleton() { self::$instance = null; @@ -61,8 +59,6 @@ class FileBackendGroup { /** * Register file backends from the global variables - * - * @return void */ protected function initFromGlobals() { global $wgLocalFileRepo, $wgForeignFileRepos, $wgFileBackends; @@ -116,20 +112,19 @@ class FileBackendGroup { /** * Register an array of file backend configurations * - * @param Array $configs - * @return void - * @throws MWException + * @param array $configs + * @throws FileBackendException */ protected function register( array $configs ) { foreach ( $configs as $config ) { if ( !isset( $config['name'] ) ) { - throw new MWException( "Cannot register a backend with no name." ); + throw new FileBackendException( "Cannot register a backend with no name." ); } $name = $config['name']; if ( isset( $this->backends[$name] ) ) { - throw new MWException( "Backend with name `{$name}` already registered." ); + throw new FileBackendException( "Backend with name `{$name}` already registered." ); } elseif ( !isset( $config['class'] ) ) { - throw new MWException( "Cannot register backend `{$name}` with no class." ); + throw new FileBackendException( "Backend with name `{$name}` has no class." ); } $class = $config['class']; @@ -147,18 +142,27 @@ class FileBackendGroup { * * @param string $name * @return FileBackend - * @throws MWException + * @throws FileBackendException */ public function get( $name ) { if ( !isset( $this->backends[$name] ) ) { - throw new MWException( "No backend defined with the name `$name`." ); + throw new FileBackendException( "No backend defined with the name `$name`." ); } // Lazy-load the actual backend instance if ( !isset( $this->backends[$name]['instance'] ) ) { $class = $this->backends[$name]['class']; $config = $this->backends[$name]['config']; + $config['wikiId'] = isset( $config['wikiId'] ) + ? $config['wikiId'] + : wfWikiID(); // e.g. "my_wiki-en_" + $config['lockManager'] = + LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] ); + $config['fileJournal'] = isset( $config['fileJournal'] ) + ? FileJournal::factory( $config['fileJournal'], $name ) + : FileJournal::factory( array( 'class' => 'NullFileJournal' ), $name ); $this->backends[$name]['instance'] = new $class( $config ); } + return $this->backends[$name]['instance']; } @@ -166,14 +170,15 @@ class FileBackendGroup { * Get the config array for a backend object with a given name * * @param string $name - * @return Array - * @throws MWException + * @return array + * @throws FileBackendException */ public function config( $name ) { if ( !isset( $this->backends[$name] ) ) { - throw new MWException( "No backend defined with the name `$name`." ); + throw new FileBackendException( "No backend defined with the name `$name`." ); } $class = $this->backends[$name]['class']; + return array( 'class' => $class ) + $this->backends[$name]['config']; } @@ -188,6 +193,7 @@ class FileBackendGroup { if ( $backend !== null && isset( $this->backends[$backend] ) ) { return $this->get( $backend ); } + return null; } } |