Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / site / HashSiteStore.php
blob38528d6fe6caf7fa9f7b1c092d89b3645da44567
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 = array();
39 /**
40 * @param array $sites
42 public function __construct( $sites = array() ) {
43 $this->saveSites( $sites );
46 /**
47 * Saves the provided site.
49 * @since 1.25
51 * @param Site $site
53 * @return boolean Success indicator
55 public function saveSite( Site $site ) {
56 $this->sites[$site->getGlobalId()] = $site;
59 /**
60 * Saves the provided sites.
62 * @since 1.25
64 * @param Site[] $sites
66 * @return boolean Success indicator
68 public function saveSites( array $sites ) {
69 foreach ( $sites as $site ) {
70 $this->saveSite( $site );
74 /**
75 * Returns the site with provided global id, or null if there is no such site.
77 * @since 1.25
79 * @param string $globalId
80 * @param string $source either 'cache' or 'recache'.
81 * If 'cache', the values can (but not obliged) come from a cache.
83 * @return Site|null
85 public function getSite( $globalId, $source = 'cache' ) {
86 if ( isset( $this->sites[$globalId] ) ) {
87 return $this->sites[$globalId];
88 } else {
89 return null;
93 /**
94 * Returns a list of all sites. By default this site is
95 * fetched from the cache, which can be changed to loading
96 * the list from the database using the $useCache parameter.
98 * @since 1.25
100 * @param string $source either 'cache' or 'recache'.
101 * If 'cache', the values can (but not obliged) come from a cache.
103 * @return SiteList
105 public function getSites( $source = 'cache' ) {
106 return new SiteList( $this->sites );
110 * Deletes all sites from the database. After calling clear(), getSites() will return an empty
111 * list and getSite() will return null until saveSite() or saveSites() is called.
113 public function clear() {
114 $this->sites = array();