*/
private $cacheTimeout = 3600;
+ /**
+ * @var BagOStuff
+ */
+ private $cache;
+
/**
* @since 1.21
*
* @param ORMTable|null $sitesTable
+ * @param BagOStuff|null $cache
*
* @return SiteStore
*/
- public static function newInstance( ORMTable $sitesTable = null ) {
- return new static( $sitesTable );
+ public static function newInstance( ORMTable $sitesTable = null, BagOStuff $cache = null ) {
+ if ( $cache === null ) {
+ $cache = wfGetMainCache();
+ }
+
+ return new static( $cache, $sitesTable );
}
/**
*
* @since 1.21
*
+ * @param BagOStuff $cache
* @param ORMTable|null $sitesTable
*/
- protected function __construct( ORMTable $sitesTable = null ) {
+ protected function __construct( BagOStuff $cache, ORMTable $sitesTable = null ) {
if ( $sitesTable === null ) {
$sitesTable = $this->newSitesTable();
}
+ $this->cache = $cache;
$this->sitesTable = $sitesTable;
}
if ( $source === 'cache' ) {
if ( $this->sites === null ) {
- $cache = wfGetMainCache();
- $sites = $cache->get( $this->getCacheKey() );
+ $sites = $this->cache->get( $this->getCacheKey() );
if ( is_object( $sites ) ) {
$this->sites = $sites;
}
}
- $cache = wfGetMainCache();
- $cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout );
+ $this->cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout );
wfProfileOut( __METHOD__ );
}
public function reset() {
wfProfileIn( __METHOD__ );
// purge cache
- $cache = wfGetMainCache();
- $cache->delete( $this->getCacheKey() );
+ $this->cache->delete( $this->getCacheKey() );
$this->sites = null;
wfProfileOut( __METHOD__ );
strcmp( $hexIP, $end ) <= 0 );
}
+ /**
+ * Determines if an IP address is a list of CIDR a.b.c.d/n ranges.
+ *
+ * @since 1.25
+ *
+ * @param string $ip the IP to check
+ * @param array $ranges the IP ranges, each element a range
+ *
+ * @return bool true if the specified adress belongs to the specified range; otherwise, false.
+ */
+ public static function isInRanges( $ip, $ranges ) {
+ foreach ( $ranges as $range ) {
+ if ( self::isInRange( $ip, $range ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Convert some unusual representations of IPv4 addresses to their
* canonical dotted quad representation.