Add release note for Ieec65c90
[mediawiki.git] / includes / site / SiteArray.php
blob141629e050b6e402cdc74873f7038e3006bc1e14
1 <?php
3 /**
4 * Implementation of SiteList using GenericArrayObject.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @since 1.21
23 * @file
24 * @ingroup Site
26 * @license GNU GPL v2+
27 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
29 class SiteArray extends GenericArrayObject implements SiteList {
31 /**
32 * Internal site identifiers pointing to their sites offset value.
34 * @since 1.21
36 * @var array of integer
38 protected $byInternalId = array();
40 /**
41 * Global site identifiers pointing to their sites offset value.
43 * @since 1.21
45 * @var array of string
47 protected $byGlobalId = array();
49 /**
50 * @see GenericArrayObject::getObjectType
52 * @since 1.21
54 * @return string
56 public function getObjectType() {
57 return 'Site';
60 /**
61 * @see GenericArrayObject::preSetElement
63 * @since 1.21
65 * @param int|string $index
66 * @param Site $site
68 * @return boolean
70 protected function preSetElement( $index, $site ) {
71 if ( $this->hasSite( $site->getGlobalId() ) ) {
72 $this->removeSite( $site->getGlobalId() );
75 $this->byGlobalId[$site->getGlobalId()] = $index;
76 $this->byInternalId[$site->getInternalId()] = $index;
78 return true;
81 /**
82 * @see ArrayObject::offsetUnset()
84 * @since 1.21
86 * @param mixed $index
88 public function offsetUnset( $index ) {
89 /**
90 * @var Site $site
92 $site = $this->offsetGet( $index );
94 if ( $site !== false ) {
95 unset( $this->byGlobalId[$site->getGlobalId()] );
96 unset( $this->byInternalId[$site->getInternalId()] );
99 parent::offsetUnset( $index );
103 * @see SiteList::getGlobalIdentifiers
105 * @since 1.21
107 * @return array
109 public function getGlobalIdentifiers() {
110 return array_keys( $this->byGlobalId );
114 * @see SiteList::hasSite
116 * @param string $globalSiteId
118 * @return boolean
120 public function hasSite( $globalSiteId ) {
121 return array_key_exists( $globalSiteId, $this->byGlobalId );
125 * @see SiteList::getSite
127 * @since 1.21
129 * @param string $globalSiteId
131 * @return Site
133 public function getSite( $globalSiteId ) {
134 return $this->offsetGet( $this->byGlobalId[$globalSiteId] );
138 * @see SiteList::removeSite
140 * @since 1.21
142 * @param string $globalSiteId
144 public function removeSite( $globalSiteId ) {
145 $this->offsetUnset( $this->byGlobalId[$globalSiteId] );
149 * @see SiteList::isEmpty
151 * @since 1.21
153 * @return boolean
155 public function isEmpty() {
156 return $this->byGlobalId === array();
160 * @see SiteList::hasInternalId
162 * @param integer $id
164 * @return boolean
166 public function hasInternalId( $id ) {
167 return array_key_exists( $id, $this->byInternalId );
171 * @see SiteList::getSiteByInternalId
173 * @since 1.21
175 * @param integer $id
177 * @return Site
179 public function getSiteByInternalId( $id ) {
180 return $this->offsetGet( $this->byInternalId[$id] );
184 * @see SiteList::removeSiteByInternalId
186 * @since 1.21
188 * @param integer $id
190 public function removeSiteByInternalId( $id ) {
191 $this->offsetUnset( $this->byInternalId[$id] );
195 * @see SiteList::setSite
197 * @since 1.21
199 * @param Site $site
201 public function setSite( Site $site ) {
202 $this[] = $site;