MediaWiki master
HashSiteStore.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Site;
8
17class HashSiteStore implements SiteStore {
19 private $sites = [];
20
24 public function __construct( array $sites = [] ) {
25 $this->saveSites( $sites );
26 }
27
35 public function saveSite( Site $site ) {
36 $this->sites[$site->getGlobalId()] = $site;
37
38 return true;
39 }
40
48 public function saveSites( array $sites ) {
49 foreach ( $sites as $site ) {
50 $this->saveSite( $site );
51 }
52
53 return true;
54 }
55
65 public function getSite( $globalId, $source = 'cache' ) {
66 return $this->sites[$globalId] ?? null;
67 }
68
80 public function getSites( $source = 'cache' ) {
81 return new SiteList( $this->sites );
82 }
83
92 public function clear() {
93 $this->sites = [];
94 return true;
95 }
96
97}
98
100class_alias( HashSiteStore::class, 'HashSiteStore' );
In-memory SiteStore implementation, stored in an associative array.
saveSite(Site $site)
Save the provided site.
getSite( $globalId, $source='cache')
Return the site with provided global ID, or null if there is no such site.
getSites( $source='cache')
Return a list of all sites.
clear()
Delete all sites from the database.
saveSites(array $sites)
Save the provided sites.
Array-like collection of Site objects.
Definition SiteList.php:23
Represents a single site.
Definition Site.php:22
getGlobalId()
Returns the global site identifier (ie enwiktionary).
Definition Site.php:133
Interface for storing and retrieving Site objects.
Definition SiteStore.php:18
$source