MediaWiki  REL1_21
SiteList.php
Go to the documentation of this file.
00001 <?php
00002 
00029 class SiteList extends GenericArrayObject {
00030 
00038         protected $byInternalId = array();
00039 
00047         protected $byGlobalId = array();
00048 
00056         public function getObjectType() {
00057                 return 'Site';
00058         }
00059 
00070         protected function preSetElement( $index, $site ) {
00071                 if ( $this->hasSite( $site->getGlobalId() ) ) {
00072                         $this->removeSite( $site->getGlobalId() );
00073                 }
00074 
00075                 $this->byGlobalId[$site->getGlobalId()] = $index;
00076                 $this->byInternalId[$site->getInternalId()] = $index;
00077 
00078                 return true;
00079         }
00080 
00088         public function offsetUnset( $index ) {
00089                 if ( $this->offsetExists( $index ) ) {
00093                         $site = $this->offsetGet( $index );
00094 
00095                         unset( $this->byGlobalId[$site->getGlobalId()] );
00096                         unset( $this->byInternalId[$site->getInternalId()] );
00097                 }
00098 
00099                 parent::offsetUnset( $index );
00100         }
00101 
00110         public function getGlobalIdentifiers() {
00111                 return array_keys( $this->byGlobalId );
00112         }
00113 
00121         public function hasSite( $globalSiteId ) {
00122                 return array_key_exists( $globalSiteId, $this->byGlobalId );
00123         }
00124 
00135         public function getSite( $globalSiteId ) {
00136                 return $this->offsetGet( $this->byGlobalId[$globalSiteId] );
00137         }
00138 
00147         public function removeSite( $globalSiteId ) {
00148                 $this->offsetUnset( $this->byGlobalId[$globalSiteId] );
00149         }
00150 
00158         public function isEmpty() {
00159                 return $this->byGlobalId === array();
00160         }
00161 
00169         public function hasInternalId( $id ) {
00170                 return array_key_exists( $id, $this->byInternalId );
00171         }
00172 
00183         public function getSiteByInternalId( $id ) {
00184                 return $this->offsetGet( $this->byInternalId[$id] );
00185         }
00186 
00195         public function removeSiteByInternalId( $id ) {
00196                 $this->offsetUnset( $this->byInternalId[$id] );
00197         }
00198 
00207         public function setSite( Site $site ) {
00208                 $this[] = $site;
00209         }
00210 
00220         public function getGroup( $groupName ) {
00221                 $group = new self();
00222 
00226                 foreach ( $this as $site ) {
00227                         if ( $site->getGroup() === $groupName ) {
00228                                 $group[] = $site;
00229                         }
00230                 }
00231 
00232                 return $group;
00233         }
00234 
00243         const SERIAL_VERSION_ID = '2013-02-07';
00244 
00254         public static function getSerialVersionId() {
00255                 return self::SERIAL_VERSION_ID . '+Site:' . Site::SERIAL_VERSION_ID;
00256         }
00257 
00265         protected function getSerializationData() {
00266                 //NOTE: When changing the structure, either implement unserialize() to handle the
00267                 //      old structure too, or update SERIAL_VERSION_ID to kill any caches.
00268                 return array_merge(
00269                         parent::getSerializationData(),
00270                         array(
00271                                 'internalIds' => $this->byInternalId,
00272                                 'globalIds' => $this->byGlobalId,
00273                         )
00274                 );
00275         }
00276 
00286         public function unserialize( $serialization ) {
00287                 $serializationData = parent::unserialize( $serialization );
00288 
00289                 $this->byInternalId = $serializationData['internalIds'];
00290                 $this->byGlobalId = $serializationData['globalIds'];
00291 
00292                 return $serializationData;
00293         }
00294 
00295 }
00296 
00300 class SiteArray extends SiteList {}