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
24 * In-memory SiteStore implementation, storing sites in an associative array.
26 * @author Daniel Kinzler
27 * @author Katie Filbert < aude.wiki@gmail.com >
32 class HashSiteStore
implements SiteStore
{
40 * @param Site[] $sites
42 public function __construct( $sites = [] ) {
43 $this->saveSites( $sites );
47 * Saves the provided site.
53 * @return bool Success indicator
55 public function saveSite( Site
$site ) {
56 $this->sites
[$site->getGlobalId()] = $site;
62 * Saves the provided sites.
66 * @param Site[] $sites
68 * @return bool Success indicator
70 public function saveSites( array $sites ) {
71 foreach ( $sites as $site ) {
72 $this->saveSite( $site );
79 * Returns the site with provided global id, or null if there is no such site.
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.
89 public function getSite( $globalId, $source = 'cache' ) {
90 if ( isset( $this->sites
[$globalId] ) ) {
91 return $this->sites
[$globalId];
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.
104 * @param string $source either 'cache' or 'recache'.
105 * If 'cache', the values can (but not obliged) come from a cache.
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() {