MediaWiki  1.23.0
GenericArrayObject.php
Go to the documentation of this file.
1 <?php
2 
35 abstract class GenericArrayObject extends ArrayObject {
36 
44  abstract public function getObjectType();
45 
51  protected $indexOffset = 0;
52 
62  protected function getNewOffset() {
63  while ( $this->offsetExists( $this->indexOffset ) ) {
64  $this->indexOffset++;
65  }
66 
67  return $this->indexOffset;
68  }
69 
80  public function __construct( $input = null, $flags = 0, $iterator_class = 'ArrayIterator' ) {
81  parent::__construct( array(), $flags, $iterator_class );
82 
83  if ( !is_null( $input ) ) {
84  foreach ( $input as $offset => $value ) {
85  $this->offsetSet( $offset, $value );
86  }
87  }
88  }
89 
97  public function append( $value ) {
98  $this->setElement( null, $value );
99  }
100 
109  public function offsetSet( $index, $value ) {
110  $this->setElement( $index, $value );
111  }
112 
123  protected function hasValidType( $value ) {
124  $class = $this->getObjectType();
125  return $value instanceof $class;
126  }
127 
144  protected function setElement( $index, $value ) {
145  if ( !$this->hasValidType( $value ) ) {
146  throw new InvalidArgumentException(
147  'Can only add ' . $this->getObjectType() . ' implementing objects to ' . get_called_class() . '.'
148  );
149  }
150 
151  if ( is_null( $index ) ) {
152  $index = $this->getNewOffset();
153  }
154 
155  if ( $this->preSetElement( $index, $value ) ) {
156  parent::offsetSet( $index, $value );
157  }
158  }
159 
176  protected function preSetElement( $index, $value ) {
177  return true;
178  }
179 
187  public function serialize() {
188  return serialize( $this->getSerializationData() );
189  }
190 
200  protected function getSerializationData() {
201  return array(
202  'data' => $this->getArrayCopy(),
203  'index' => $this->indexOffset,
204  );
205  }
206 
216  public function unserialize( $serialization ) {
217  $serializationData = unserialize( $serialization );
218 
219  foreach ( $serializationData['data'] as $offset => $value ) {
220  // Just set the element, bypassing checks and offset resolving,
221  // as these elements have already gone through this.
222  parent::offsetSet( $offset, $value );
223  }
224 
225  $this->indexOffset = $serializationData['index'];
226 
227  return $serializationData;
228  }
229 
237  public function isEmpty() {
238  return $this->count() === 0;
239  }
240 
241 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
GenericArrayObject\__construct
__construct( $input=null, $flags=0, $iterator_class='ArrayIterator')
Constructor.
Definition: GenericArrayObject.php:79
GenericArrayObject
Definition: GenericArrayObject.php:35
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2113
GenericArrayObject\isEmpty
isEmpty()
Returns if the ArrayObject has no elements.
Definition: GenericArrayObject.php:236
GenericArrayObject\unserialize
unserialize( $serialization)
Definition: GenericArrayObject.php:215
GenericArrayObject\offsetSet
offsetSet( $index, $value)
Definition: GenericArrayObject.php:108
GenericArrayObject\setElement
setElement( $index, $value)
Method that actually sets the element and holds all common code needed for set operations,...
Definition: GenericArrayObject.php:143
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
GenericArrayObject\hasValidType
hasValidType( $value)
Returns if the provided value has the same type as the elements that can be added to this ArrayObject...
Definition: GenericArrayObject.php:122
GenericArrayObject\getObjectType
getObjectType()
Returns the name of an interface/class that the element should implement/extend.
$value
$value
Definition: styleTest.css.php:45
GenericArrayObject\getSerializationData
getSerializationData()
Returns an array holding all the data that should go into serialization calls.
Definition: GenericArrayObject.php:199
GenericArrayObject\preSetElement
preSetElement( $index, $value)
Gets called before a new element is added to the ArrayObject.
Definition: GenericArrayObject.php:175
GenericArrayObject\getNewOffset
getNewOffset()
Finds a new offset for when appending an element.
Definition: GenericArrayObject.php:61
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
GenericArrayObject\serialize
serialize()
Definition: GenericArrayObject.php:186
GenericArrayObject\append
append( $value)
Definition: GenericArrayObject.php:96
GenericArrayObject\$indexOffset
integer $indexOffset
Definition: GenericArrayObject.php:50