MediaWiki
REL1_30
GenericArrayObject.php
Go to the documentation of this file.
1
<?php
2
35
abstract
class
GenericArrayObject
extends
ArrayObject {
43
abstract
public
function
getObjectType
();
44
50
protected
$indexOffset
= 0;
51
61
protected
function
getNewOffset
() {
62
while
( $this->offsetExists( $this->indexOffset ) ) {
63
$this->indexOffset++;
64
}
65
66
return
$this->indexOffset
;
67
}
68
78
public
function
__construct
(
$input
=
null
,
$flags
= 0, $iterator_class =
'ArrayIterator'
) {
79
parent::__construct( [],
$flags
, $iterator_class );
80
81
if
( !is_null(
$input
) ) {
82
foreach
(
$input
as $offset =>
$value
) {
83
$this->
offsetSet
( $offset,
$value
);
84
}
85
}
86
}
87
95
public
function
append
(
$value
) {
96
$this->
setElement
(
null
,
$value
);
97
}
98
107
public
function
offsetSet
( $index,
$value
) {
108
$this->
setElement
( $index,
$value
);
109
}
110
121
protected
function
hasValidType
(
$value
) {
122
$class = $this->
getObjectType
();
123
return
$value
instanceof $class;
124
}
125
142
protected
function
setElement
( $index,
$value
) {
143
if
( !$this->
hasValidType
(
$value
) ) {
144
throw
new
InvalidArgumentException(
145
'Can only add '
. $this->
getObjectType
() .
' implementing objects to '
146
. static::class .
'.'
147
);
148
}
149
150
if
( is_null( $index ) ) {
151
$index = $this->
getNewOffset
();
152
}
153
154
if
( $this->
preSetElement
( $index,
$value
) ) {
155
parent::offsetSet( $index,
$value
);
156
}
157
}
158
175
protected
function
preSetElement
( $index,
$value
) {
176
return
true
;
177
}
178
186
public
function
serialize
() {
187
return
serialize
( $this->
getSerializationData
() );
188
}
189
199
protected
function
getSerializationData
() {
200
return
[
201
'data'
=> $this->getArrayCopy(),
202
'index'
=>
$this->indexOffset
,
203
];
204
}
205
215
public
function
unserialize
( $serialization ) {
216
$serializationData =
unserialize
( $serialization );
217
218
foreach
( $serializationData[
'data'
] as $offset =>
$value
) {
219
// Just set the element, bypassing checks and offset resolving,
220
// as these elements have already gone through this.
221
parent::offsetSet( $offset,
$value
);
222
}
223
224
$this->indexOffset = $serializationData[
'index'
];
225
226
return
$serializationData;
227
}
228
236
public
function
isEmpty
() {
237
return
$this->count() === 0;
238
}
239
}
GenericArrayObject
Definition
GenericArrayObject.php:35
GenericArrayObject\offsetSet
offsetSet( $index, $value)
Definition
GenericArrayObject.php:107
GenericArrayObject\setElement
setElement( $index, $value)
Method that actually sets the element and holds all common code needed for set operations,...
Definition
GenericArrayObject.php:142
GenericArrayObject\append
append( $value)
Definition
GenericArrayObject.php:95
GenericArrayObject\preSetElement
preSetElement( $index, $value)
Gets called before a new element is added to the ArrayObject.
Definition
GenericArrayObject.php:175
GenericArrayObject\__construct
__construct( $input=null, $flags=0, $iterator_class='ArrayIterator')
Definition
GenericArrayObject.php:78
GenericArrayObject\serialize
serialize()
Definition
GenericArrayObject.php:186
GenericArrayObject\getNewOffset
getNewOffset()
Finds a new offset for when appending an element.
Definition
GenericArrayObject.php:61
GenericArrayObject\$indexOffset
int $indexOffset
Definition
GenericArrayObject.php:50
GenericArrayObject\getSerializationData
getSerializationData()
Returns an array holding all the data that should go into serialization calls.
Definition
GenericArrayObject.php:199
GenericArrayObject\isEmpty
isEmpty()
Returns if the ArrayObject has no elements.
Definition
GenericArrayObject.php:236
GenericArrayObject\unserialize
unserialize( $serialization)
Definition
GenericArrayObject.php:215
GenericArrayObject\getObjectType
getObjectType()
Returns the name of an interface/class that the element should implement/extend.
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:121
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition
hooks.txt:2805
$input
if(is_array($mode)) switch( $mode) $input
Definition
postprocess-phan.php:141
$value
$value
Definition
styleTest.css.php:45
includes
libs
GenericArrayObject.php
Generated on Mon Nov 25 2024 15:42:27 for MediaWiki by
1.10.0