From: Antoine Musso Date: Mon, 20 May 2013 10:37:15 +0000 (+0200) Subject: LinkCache singleton can now be altered X-Git-Tag: 1.31.0-rc.0~19522 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=ca934127d7424e0e63ef3515137cf02278ab26ca;p=lhc%2Fweb%2Fwiklou.git LinkCache singleton can now be altered This patch adds the ability to destroy the LinkCache singleton or to replace the instance with a different object. Note the $instance static variable is now at the class level instead of at the method level. Change-Id: Ib110ad061868834a52a6bac651976b3ffab4a6ce --- diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index c101bc9606..68624eb27f 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -97,6 +97,8 @@ production. http://www.oracle-base.com/articles/11g/database-resident-connection-pool-11gr1.php * Add a new parameter $patrolFooterShown to hook ArticleViewFooter so the hook handlers can take further action based on the status of the patrol footer +* LinkCache singleton can now be altered or cleared, letting one to specify + another instance that does not rely on a database backend. === Bug fixes in 1.22 === * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index 31982e0b11..6ac7e7abe4 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -37,16 +37,41 @@ class LinkCache { private $mForUpdate = false; /** - * Get an instance of this class + * @var LinkCache + */ + protected static $instance; + + /** + * Get an instance of this class. * * @return LinkCache */ static function &singleton() { - static $instance; - if ( !isset( $instance ) ) { - $instance = new LinkCache; + if ( self::$instance ) { + return self::$instance; } - return $instance; + self::$instance = new LinkCache; + return self::$instance; + } + + /** + * Destroy the singleton instance, a new one will be created next time + * singleton() is called. + * @since 1.22 + */ + static function destroySingleton() { + self::$instance = null; + } + + /** + * Set the singleton instance to a given object. + * Since we do not have an interface for LinkCache, you have to be sure the + * given object implements all the LinkCache public methods. + * @param LinkCache $instance + * @since 1.22 + */ + static function setSingleton( LinkCache $instance ) { + self::$instance = $instance; } /**