<?php
+use Composer\Semver\Semver;
+
/**
* ExtensionRegistry class
*
/**
* Bump whenever the registration cache needs resetting
*/
- const CACHE_VERSION = 6;
+ const CACHE_VERSION = 7;
/**
* Special key that defines the merge strategy
// been loaded
$cacheId = ObjectCache::detectLocalServerCache();
$cache = ObjectCache::newFromId( $cacheId );
- } catch ( MWException $e ) {
+ } catch ( InvalidArgumentException $e ) {
$cache = new EmptyBagOStuff();
}
// See if this queue is in APC
/**
* Whether a thing has been loaded
* @param string $name
+ * @param string $constraint The required version constraint for this dependency
+ * @throws LogicException if a specific contraint is asked for,
+ * but the extension isn't versioned
* @return bool
*/
- public function isLoaded( $name ) {
- return isset( $this->loaded[$name] );
+ public function isLoaded( $name, $constraint = '*' ) {
+ $isLoaded = isset( $this->loaded[$name] );
+ if ( $constraint === '*' || !$isLoaded ) {
+ return $isLoaded;
+ }
+ // if a specific constraint is requested, but no version is set, throw an exception
+ if ( !isset( $this->loaded[$name]['version'] ) ) {
+ $msg = "{$name} does not expose its version, but an extension or a skin"
+ . " requires: {$constraint}.";
+ throw new LogicException( $msg );
+ }
+
+ return SemVer::satisfies( $this->loaded[$name]['version'], $constraint );
}
/**
* @return array
*/
public function getAttribute( $name ) {
- if ( isset( $this->attributes[$name] ) ) {
- return $this->attributes[$name];
- } else {
- return [];
- }
+ return $this->attributes[$name] ?? [];
}
/**