X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fcache%2FCacheDependency.php;h=dd4c49e7b3759f9e73a8edb22da7baad83a6c363;hp=0a45b8ef2619f7679acf24c5396c8f37b4ae5651;hb=dbad540cd37617879aff6f28ce9c016dd8049d4e;hpb=0c8e0c66feb9b8df65bd12cb4136a1410cef8758 diff --git a/includes/cache/CacheDependency.php b/includes/cache/CacheDependency.php index 0a45b8ef26..dd4c49e7b3 100644 --- a/includes/cache/CacheDependency.php +++ b/includes/cache/CacheDependency.php @@ -20,6 +20,7 @@ * @file * @ingroup Cache */ +use MediaWiki\MediaWikiServices; /** * This class stores an arbitrary value along with its dependencies. @@ -33,16 +34,15 @@ class DependencyWrapper { private $deps; /** - * Create an instance. * @param mixed $value The user-supplied value * @param CacheDependency|CacheDependency[] $deps A dependency or dependency * array. All dependencies must be objects implementing CacheDependency. */ - function __construct( $value = false, $deps = array() ) { + function __construct( $value = false, $deps = [] ) { $this->value = $value; if ( !is_array( $deps ) ) { - $deps = array( $deps ); + $deps = [ $deps ]; } $this->deps = $deps; @@ -111,7 +111,7 @@ class DependencyWrapper { * callback was defined. */ static function getValueFromCache( $cache, $key, $expiry = 0, $callback = false, - $callbackParams = array(), $deps = array() + $callbackParams = [], $deps = [] ) { $obj = $cache->get( $key ); @@ -176,7 +176,7 @@ class FileDependency extends CacheDependency { function __sleep() { $this->loadDependencyValues(); - return array( 'filename', 'timestamp' ); + return [ 'filename', 'timestamp' ]; } function loadDependencyValues() { @@ -244,6 +244,34 @@ class GlobalDependency extends CacheDependency { } } +/** + * @ingroup Cache + */ +class MainConfigDependency extends CacheDependency { + private $name; + private $value; + + function __construct( $name ) { + $this->name = $name; + $this->value = $this->getConfig()->get( $this->name ); + } + + private function getConfig() { + return MediaWikiServices::getInstance()->getMainConfig(); + } + + /** + * @return bool + */ + function isExpired() { + if ( !$this->getConfig()->has( $this->name ) ) { + return true; + } + + return $this->getConfig()->get( $this->name ) != $this->value; + } +} + /** * @ingroup Cache */