* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class SiteList extends GenericArrayObject {
-
/**
* Internal site identifiers pointing to their sites offset value.
*
* @since 1.21
*
- * @var array of integer
+ * @var array Array of integer
*/
protected $byInternalId = array();
*
* @since 1.21
*
- * @var array of string
+ * @var array Array of string
*/
protected $byGlobalId = array();
+ /**
+ * Navigational site identifiers alias inter-language prefixes
+ * pointing to their sites offset value.
+ *
+ * @since 1.23
+ *
+ * @var array Array of string
+ */
+ protected $byNavigationId = array();
+
/**
* @see GenericArrayObject::getObjectType
*
* @param int|string $index
* @param Site $site
*
- * @return boolean
+ * @return bool
*/
protected function preSetElement( $index, $site ) {
if ( $this->hasSite( $site->getGlobalId() ) ) {
$this->byGlobalId[$site->getGlobalId()] = $index;
$this->byInternalId[$site->getInternalId()] = $index;
+ $ids = $site->getNavigationIds();
+ foreach ( $ids as $navId ) {
+ $this->byNavigationId[$navId] = $index;
+ }
+
return true;
}
unset( $this->byGlobalId[$site->getGlobalId()] );
unset( $this->byInternalId[$site->getInternalId()] );
+
+ $ids = $site->getNavigationIds();
+ foreach ( $ids as $navId ) {
+ unset( $this->byNavigationId[$navId] );
+ }
}
parent::offsetUnset( $index );
*
* @param string $globalSiteId
*
- * @return boolean
+ * @return bool
*/
public function hasSite( $globalSiteId ) {
return array_key_exists( $globalSiteId, $this->byGlobalId );
*
* @since 1.21
*
- * @return boolean
+ * @return bool
*/
public function isEmpty() {
return $this->byGlobalId === array();
/**
* Returns if the list contains the site with the provided site id.
*
- * @param integer $id
+ * @param int $id
*
- * @return boolean
+ * @return bool
*/
public function hasInternalId( $id ) {
return array_key_exists( $id, $this->byInternalId );
*
* @since 1.21
*
- * @param integer $id
+ * @param int $id
*
* @return Site
*/
*
* @since 1.21
*
- * @param integer $id
+ * @param int $id
*/
public function removeSiteByInternalId( $id ) {
$this->offsetUnset( $this->byInternalId[$id] );
}
+ /**
+ * Returns if the list contains the site with the provided navigational site id.
+ *
+ * @param string $id
+ *
+ * @return bool
+ */
+ public function hasNavigationId( $id ) {
+ return array_key_exists( $id, $this->byNavigationId );
+ }
+
+ /**
+ * Returns the Site with the provided navigational site id.
+ * The site needs to exist, so if not sure, call has first.
+ *
+ * @since 1.23
+ *
+ * @param string $id
+ *
+ * @return Site
+ */
+ public function getSiteByNavigationId( $id ) {
+ return $this->offsetGet( $this->byNavigationId[$id] );
+ }
+
+ /**
+ * Removes the site with the specified navigational site id.
+ * The site needs to exist, so if not sure, call has first.
+ *
+ * @since 1.23
+ *
+ * @param string $id
+ */
+ public function removeSiteByNavigationId( $id ) {
+ $this->offsetUnset( $this->byNavigationId[$id] );
+ }
+
/**
* Sets a site in the list. If the site was not there,
* it will be added. If it was, it will be updated.
* @var string A string uniquely identifying the version of the serialization structure,
* not including any sub-structures.
*/
- const SERIAL_VERSION_ID = '2013-02-07';
+ const SERIAL_VERSION_ID = '2014-03-17';
/**
* Returns the version ID that identifies the serialization structure used by
array(
'internalIds' => $this->byInternalId,
'globalIds' => $this->byGlobalId,
+ 'navigationIds' => $this->byNavigationId
)
);
}
$this->byInternalId = $serializationData['internalIds'];
$this->byGlobalId = $serializationData['globalIds'];
+ $this->byNavigationId = $serializationData['navigationIds'];
return $serializationData;
}
-
}
/**
* @deprecated
*/
-class SiteArray extends SiteList {}
+class SiteArray extends SiteList {
+}