MediaWiki master
HashSiteStore.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Site;
22
31class HashSiteStore implements SiteStore {
33 private $sites = [];
34
38 public function __construct( array $sites = [] ) {
39 $this->saveSites( $sites );
40 }
41
49 public function saveSite( Site $site ) {
50 $this->sites[$site->getGlobalId()] = $site;
51
52 return true;
53 }
54
62 public function saveSites( array $sites ) {
63 foreach ( $sites as $site ) {
64 $this->saveSite( $site );
65 }
66
67 return true;
68 }
69
79 public function getSite( $globalId, $source = 'cache' ) {
80 return $this->sites[$globalId] ?? null;
81 }
82
94 public function getSites( $source = 'cache' ) {
95 return new SiteList( $this->sites );
96 }
97
106 public function clear() {
107 $this->sites = [];
108 return true;
109 }
110
111}
112
114class_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:37
Represents a single site.
Definition Site.php:36
getGlobalId()
Returns the global site identifier (ie enwiktionary).
Definition Site.php:147
Interface for storing and retrieving Site objects.
Definition SiteStore.php:32
$source