StrictList
extends SplDoublyLinkedList
in package
implements
ArrayAccess, Countable, Iterator, Serializable
Uses
Getter
A type-sensitive, taversable list.
Extends \SplDoublyLinkedList with an option to restrict the allowed data types for list items by providing the constructor with an array of atomic types or fully qualified class names.
Tags
Table of Contents
Interfaces
- ArrayAccess
- Countable
- Iterator
- Serializable
Properties
- $allowedTypes : array<string|int, string>
Methods
- __construct() : void
- Create a type-sensitive, traversable list of items.
- __get() : mixed
- Read data from an inaccessible property.
- __isset() : bool
- Check if an inaccessible property is set and not empty.
- add() : void
- Add/insert a new item at the specified offset.
- append() : void
- Append items at the end of the list.
- bottom() : AllowedType
- Peek at the item at the beginning of the list.
- clear() : void
- Clear the list of any items.
- count() : int
- Get the number of items on the list.
- current() : AllowedType
- Get the current list item.
- get() : AllowedType
- Get the item at the specified index.
- getAllowedTypes() : array<string|int, string>
- Get allowed data types for list items.
- getIteratorMode() : int
- Get the mode of iteration.
- isAllowedType() : bool
- Check if the item's data type is allowed on the list.
- isEmpty() : bool
- Check if list is empty.
- isList() : true
- Check if this can be considered a list.
- key() : int
- Get the current list index.
- next() : void
- Move the cursor to the next list index.
- offsetExists() : bool
- Check if the specified index exists and is not empty.
- offsetGet() : AllowedType
- Get the item from the specified index.
- offsetSet() : void
- Set the item at the specified offset.
- offsetUnset() : void
- Unset the item at the specified index.
- pop() : AllowedType
- Pops an item from the end of the list.
- prepend() : void
- Prepend items at the start of the list.
- prev() : void
- Move the cursor to the previous list index.
- push() : void
- Push an item at the end of the list.
- remove() : void
- Remove an item from the list.
- rewind() : void
- Rewind the iterator's cursor.
- set() : void
- Set an item at the specified index.
- setIteratorMode() : int
- Set the mode of iteration.
- shift() : AllowedType
- Shift an item from the beginning of the list.
- toArray() : array<string|int, AllowedType>
- Return array representation of list.
- top() : AllowedType
- Peek at the item at the end of the list.
- toStrictCollection() : StrictCollection<string|int, AllowedType>
- Turn list into a type-sensitive collection.
- unshift() : void
- Prepend the list with an item.
- valid() : bool
- Check if current cursor position is valid.
- setAllowedTypes() : void
- Set allowed data types of list items.
Properties
$allowedTypes read-only
public
array<string|int, string>
$allowedTypes
The allowed data types for values.
Methods
__construct()
Create a type-sensitive, traversable list of items.
public
__construct([array<string|int, string> $allowedTypes = [] ]) : void
Parameters
- $allowedTypes : array<string|int, string> = []
-
Allowed data types of items (optional)
If empty, all types are allowed. Possible values are:
- "array"
- "bool"
- "callable"
- "countable"
- "float" or "double"
- "int" or "integer" or "long"
- "iterable"
- "null"
- "numeric"
- "object" or FQCN
- "resource"
- "scalar"
- "string"
Tags
__get()
Read data from an inaccessible property.
public
__get(string $property) : mixed
Parameters
- $property : string
-
The class property to get
Tags
Return values
mixed —The class property's current value
__isset()
Check if an inaccessible property is set and not empty.
public
__isset(string $property) : bool
Parameters
- $property : string
-
The class property to check
Return values
bool —Whether the class property is set and not empty
add()
Add/insert a new item at the specified offset.
public
add(int $offset, AllowedType $value) : void
Parameters
- $offset : int
-
The offset where the new item is to be inserted
- $value : AllowedType
-
The new item for the offset
Tags
append()
Append items at the end of the list.
public
append(AllowedType ...$values) : void
Parameters
- $values : AllowedType
-
One or more items to append
Tags
bottom()
Peek at the item at the beginning of the list.
public
bottom() : AllowedType
Tags
Return values
AllowedType —The first item of the list
clear()
Clear the list of any items.
public
clear() : void
count()
Get the number of items on the list.
public
count() : int
Return values
int —The number of items on the list
current()
Get the current list item.
public
current() : AllowedType
Return values
AllowedType —The current item
get()
Get the item at the specified index.
public
get(int $offset) : AllowedType
Parameters
- $offset : int
-
The item's index
Tags
Return values
AllowedType —The item
getAllowedTypes()
Get allowed data types for list items.
public
getAllowedTypes() : array<string|int, string>
Return values
array<string|int, string> —The list of allowed data types
getIteratorMode()
Get the mode of iteration.
public
getIteratorMode() : int
Return values
int —The set of flags and modes of iteration
isAllowedType()
Check if the item's data type is allowed on the list.
public
isAllowedType(AllowedType $value) : bool
Parameters
- $value : AllowedType
-
The item to check
Return values
bool —Whether the item's data type is allowed
isEmpty()
Check if list is empty.
public
isEmpty() : bool
Return values
bool —Whether the list contains no items
isList()
Check if this can be considered a list.
public
isList() : true
Return values
true —Always TRUE (this exists only for compatibility reasons)
key()
Get the current list index.
public
key() : int
Return values
int —The current list index
next()
Move the cursor to the next list index.
public
next() : void
offsetExists()
Check if the specified index exists and is not empty.
public
offsetExists(int $offset) : bool
Parameters
- $offset : int
-
The index to check
Return values
bool —Whether the index exists and is not empty
offsetGet()
Get the item from the specified index.
public
offsetGet(int $offset) : AllowedType
Parameters
- $offset : int
-
The item's index
Tags
Return values
AllowedType —The item
offsetSet()
Set the item at the specified offset.
public
offsetSet(int|null $offset, AllowedType $value) : void
Parameters
- $offset : int|null
-
The offset being set or NULL to append
- $value : AllowedType
-
The new item for the offset
Tags
offsetUnset()
Unset the item at the specified index.
public
offsetUnset(int $offset) : void
Parameters
- $offset : int
-
The item's index
Tags
pop()
Pops an item from the end of the list.
public
pop() : AllowedType
Tags
Return values
AllowedType —The item from the end of the list
prepend()
Prepend items at the start of the list.
public
prepend(AllowedType ...$values) : void
Parameters
- $values : AllowedType
-
One or more items to prepend
Tags
prev()
Move the cursor to the previous list index.
public
prev() : void
push()
Push an item at the end of the list.
public
push(AllowedType $value) : void
Parameters
- $value : AllowedType
-
The item to push
Tags
remove()
Remove an item from the list.
public
remove(int $offset) : void
Parameters
- $offset : int
-
The item's index
Tags
rewind()
Rewind the iterator's cursor.
public
rewind() : void
set()
Set an item at the specified index.
public
set(int $offset, AllowedType $value) : void
Parameters
- $offset : int
-
The item's index
- $value : AllowedType
-
The item
Tags
setIteratorMode()
Set the mode of iteration.
public
setIteratorMode(int $mode) : int
Parameters
- $mode : int
-
The new iterator mode (0, 1, 2 or 3)
There are two orthogonal sets of modes that can be set.
The direction of iteration (either one or the other):
- StrictList::IT_MODE_FIFO (queue style)
- StrictList::IT_MODE_LIFO (stack style)
The behavior of the iterator (either one or the other):
- StrictList::IT_MODE_DELETE (delete items)
- StrictList::IT_MODE_KEEP (keep items)
The default mode is: IT_MODE_FIFO | IT_MODE_KEEP
Tags
Return values
int —The set of flags and modes of iteration
shift()
Shift an item from the beginning of the list.
public
shift() : AllowedType
Tags
Return values
AllowedType —The first item of the list
toArray()
Return array representation of list.
public
toArray() : array<string|int, AllowedType>
Return values
array<string|int, AllowedType> —Array of list items
top()
Peek at the item at the end of the list.
public
top() : AllowedType
Tags
Return values
AllowedType —The last item of the list
toStrictCollection()
Turn list into a type-sensitive collection.
public
toStrictCollection() : StrictCollection<string|int, AllowedType>
Return values
StrictCollection<string|int, AllowedType> —A type-sensitive collection of the list's items
unshift()
Prepend the list with an item.
public
unshift(AllowedType $value) : void
Parameters
- $value : AllowedType
-
The item to unshift
Tags
valid()
Check if current cursor position is valid.
public
valid() : bool
Return values
bool —Whether the current cursor position is valid
setAllowedTypes()
Set allowed data types of list items.
protected
setAllowedTypes([array<string|int, string> $allowedTypes = [] ]) : void
Parameters
- $allowedTypes : array<string|int, string> = []
-
Allowed data types of items