Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / site / HashSiteStore.php
blobd4e78aeadd83a1a91cbfef6955b78831a6afa45a
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 namespace MediaWiki\Site;
23 /**
24 * In-memory SiteStore implementation, stored in an associative array.
26 * @since 1.25
27 * @ingroup Site
28 * @author Daniel Kinzler
29 * @author Katie Filbert < aude.wiki@gmail.com >
31 class HashSiteStore implements SiteStore {
32 /** @var Site[] */
33 private $sites = [];
35 /**
36 * @param Site[] $sites
38 public function __construct( array $sites = [] ) {
39 $this->saveSites( $sites );
42 /**
43 * Save the provided site.
45 * @since 1.25
46 * @param Site $site
47 * @return bool Success indicator
49 public function saveSite( Site $site ) {
50 $this->sites[$site->getGlobalId()] = $site;
52 return true;
55 /**
56 * Save the provided sites.
58 * @since 1.25
59 * @param Site[] $sites
60 * @return bool Success indicator
62 public function saveSites( array $sites ) {
63 foreach ( $sites as $site ) {
64 $this->saveSite( $site );
67 return true;
70 /**
71 * Return the site with provided global ID, or null if there is no such site.
73 * @since 1.25
74 * @param string $globalId
75 * @param string $source either 'cache' or 'recache'.
76 * If 'cache', the values can (but not obliged) come from a cache.
77 * @return Site|null
79 public function getSite( $globalId, $source = 'cache' ) {
80 return $this->sites[$globalId] ?? null;
83 /**
84 * Return a list of all sites.
86 * By default this list is fetched from the cache, which can be changed to loading
87 * the list from the database using the $useCache parameter.
89 * @since 1.25
90 * @param string $source either 'cache' or 'recache'.
91 * If 'cache', the values can (but not obliged) come from a cache.
92 * @return SiteList
94 public function getSites( $source = 'cache' ) {
95 return new SiteList( $this->sites );
98 /**
99 * Delete all sites from the database.
101 * After calling clear(), getSites() will return an empty list and getSite() will
102 * return null until saveSite() or saveSites() is called.
104 * @return bool
106 public function clear() {
107 $this->sites = [];
108 return true;
113 /** @deprecated class alias since 1.42 */
114 class_alias( HashSiteStore::class, 'HashSiteStore' );