[LockManager] Added support for a default lock manager.
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 23 Jun 2012 18:26:46 +0000 (11:26 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Sat, 23 Jun 2012 18:53:36 +0000 (11:53 -0700)
Change-Id: I730c8b078b9f3a0ad73b1b0887a8c991c9d81bde

includes/filerepo/backend/lockmanager/LockManagerGroup.php

index b830855..8c8c940 100644 (file)
 
 /**
  * Class to handle file lock manager registration
- * 
+ *
  * @ingroup LockManager
  * @author Aaron Schulz
  * @since 1.19
  */
 class LockManagerGroup {
-
        /**
         * @var LockManagerGroup
         */
@@ -61,7 +60,7 @@ class LockManagerGroup {
 
        /**
         * Register lock managers from the global variables
-        * 
+        *
         * @return void
         */
        protected function initFromGlobals() {
@@ -115,4 +114,30 @@ class LockManagerGroup {
                }
                return $this->managers[$name]['instance'];
        }
+
+       /**
+        * Get the default lock manager configured for the site.
+        * Returns NullLockManager if no lock manager could be found.
+        *
+        * @return LockManager
+        */
+       public function getDefault() {
+               return isset( $this->managers['default'] )
+                       ? $this->get( 'default' )
+                       : new NullLockManager( array() );
+       }
+
+       /**
+        * Get the default lock manager configured for the site
+        * or at least some other effective configured lock manager.
+        * Throws an exception if no lock manager could be found.
+        *
+        * @return LockManager
+        * @throws MWException
+        */
+       public function getAny() {
+               return isset( $this->managers['default'] )
+                       ? $this->get( 'default' )
+                       : $this->get( 'fsLockManager' );
+       }
 }