Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / site / HashSiteStore.php
blob2c7965c90236264c56289c363131b13cf4730c80
1 <?php
2 /**
3 * In-memory implementation of SiteStore.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 /**
24 * In-memory SiteStore implementation, storing sites in an associative array.
26 * @author Daniel Kinzler
27 * @author Katie Filbert < aude.wiki@gmail.com >
29 * @since 1.25
30 * @ingroup Site
32 class HashSiteStore implements SiteStore {
34 /**
35 * @var Site[]
37 private $sites = [];
39 /**
40 * @param Site[] $sites
42 public function __construct( $sites = [] ) {
43 $this->saveSites( $sites );
46 /**
47 * Saves the provided site.
49 * @since 1.25
51 * @param Site $site
53 * @return bool Success indicator
55 public function saveSite( Site $site ) {
56 $this->sites[$site->getGlobalId()] = $site;
58 return true;
61 /**
62 * Saves the provided sites.
64 * @since 1.25
66 * @param Site[] $sites
68 * @return bool Success indicator
70 public function saveSites( array $sites ) {
71 foreach ( $sites as $site ) {
72 $this->saveSite( $site );
75 return true;
78 /**
79 * Returns the site with provided global id, or null if there is no such site.
81 * @since 1.25
83 * @param string $globalId
84 * @param string $source either 'cache' or 'recache'.
85 * If 'cache', the values can (but not obliged) come from a cache.
87 * @return Site|null
89 public function getSite( $globalId, $source = 'cache' ) {
90 if ( isset( $this->sites[$globalId] ) ) {
91 return $this->sites[$globalId];
92 } else {
93 return null;
97 /**
98 * Returns a list of all sites. By default this site is
99 * fetched from the cache, which can be changed to loading
100 * the list from the database using the $useCache parameter.
102 * @since 1.25
104 * @param string $source either 'cache' or 'recache'.
105 * If 'cache', the values can (but not obliged) come from a cache.
107 * @return SiteList
109 public function getSites( $source = 'cache' ) {
110 return new SiteList( $this->sites );
114 * Deletes all sites from the database. After calling clear(), getSites() will return an empty
115 * list and getSite() will return null until saveSite() or saveSites() is called.
117 public function clear() {
118 $this->sites = [];
120 return true;