Queue
extends AbstractArray
in package
implements
QueueInterface
Uses
TypeTrait, ValueToStringTrait
This class provides a basic implementation of `QueueInterface`, to minimize the effort required to implement this interface.
Interfaces, Classes, Traits and Enums
- QueueInterface
- A queue is a collection in which the entities in the collection are kept in order.
Table of Contents
- $data : array<string|int, mixed>
- The items of this array.
- $index : int
- The index of the head of the queue.
- $queueType : string
- The type of elements stored in this queue.
- __construct() : mixed
- Constructs a queue object of the specified type, optionally with the specified data.
- add() : bool
- Ensures that this queue contains the specified element.
- clear() : void
- Removes all items from this array.
- count() : int
- Returns the number of items in this array.
- element() : mixed
- Retrieves, but does not remove, the head of this queue.
- getIterator() : ArrayIterator<mixed, mixed>
- Returns an iterator for this array.
- getType() : string
- Returns the type associated with this queue.
- isEmpty() : bool
- Returns `true` if this array is empty.
- offer() : bool
- Inserts the specified element into this queue.
- offsetExists() : bool
- Returns `true` if the given offset exists in this array.
- offsetGet() : mixed|null
- Returns the value at the specified offset.
- offsetSet() : void
- Sets the given value to the given offset in the queue.
- offsetUnset() : void
- Removes the given offset and its value from the array.
- peek() : mixed|null
- Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty.
- poll() : mixed|null
- Retrieves and removes the head of this queue, or returns `null` if this queue is empty.
- remove() : mixed
- Retrieves and removes the head of this queue.
- serialize() : string
- Returns a serialized string representation of this array object.
- toArray() : array<string|int, mixed>
- Returns a native PHP array representation of this array object.
- unserialize() : void
- Converts a serialized string representation into an instance object.
- checkType() : bool
- Returns `true` if value is of the specified type.
- toolValueToString() : string
- Returns a string representation of the value.
Properties
$data
The items of this array.
protected
array<string|int, mixed>
$data
= []
$index
The index of the head of the queue.
protected
int
$index
= 0
$queueType
The type of elements stored in this queue.
private
string
$queueType
A queue's type is immutable once it is set. For this reason, this property is set private.
Methods
__construct()
Constructs a queue object of the specified type, optionally with the specified data.
public
__construct(string $queueType[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $queueType : string
-
The type (FQCN) associated with this queue.
- $data : array<string|int, mixed> = []
-
The initial items to store in the collection.
Return values
mixed —add()
Ensures that this queue contains the specified element.
public
add(mixed $element) : bool
This method differs from offer()
only in that it throws an exception if
it cannot add the element to the queue.
Parameters
- $element : mixed
-
The element to add to this queue.
Tags
Return values
bool —true
if this queue changed as a result of the call.
clear()
Removes all items from this array.
public
clear() : void
Return values
void —count()
Returns the number of items in this array.
public
count() : int
Tags
Return values
int —element()
Retrieves, but does not remove, the head of this queue.
public
element() : mixed
This method differs from peek()
only in that it throws an exception if
this queue is empty.
Tags
Return values
mixed —the head of this queue.
getIterator()
Returns an iterator for this array.
public
getIterator() : ArrayIterator<mixed, mixed>
Tags
Return values
ArrayIterator<mixed, mixed> —getType()
Returns the type associated with this queue.
public
getType() : string
Return values
string —isEmpty()
Returns `true` if this array is empty.
public
isEmpty() : bool
Return values
bool —offer()
Inserts the specified element into this queue.
public
offer(mixed $element) : bool
This method differs from add()
only in that it does not throw an
exception if it cannot add the element to the queue.
Parameters
- $element : mixed
-
The element to add to this queue.
Tags
Return values
bool —true
if the element was added to this queue, else false
.
offsetExists()
Returns `true` if the given offset exists in this array.
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
-
The offset to check.
Tags
Return values
bool —offsetGet()
Returns the value at the specified offset.
public
offsetGet(mixed $offset) : mixed|null
Parameters
- $offset : mixed
-
The offset for which a value should be returned.
Tags
Return values
mixed|null —the value stored at the offset, or null if the offset does not exist.
offsetSet()
Sets the given value to the given offset in the queue.
public
offsetSet(mixed|null $offset, mixed $value) : void
Since arbitrary offsets may not be manipulated in a queue, this method
serves only to fulfill the ArrayAccess
interface requirements. It is
invoked by other operations when adding values to the queue.
Parameters
- $offset : mixed|null
-
The offset is ignored and is treated as
null
. - $value : mixed
-
The value to set at the given offset.
Tags
Return values
void —offsetUnset()
Removes the given offset and its value from the array.
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
-
The offset to remove from the array.
Tags
Return values
void —peek()
Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty.
public
peek() : mixed|null
Tags
Return values
mixed|null —the head of this queue, or null
if this queue is empty.
poll()
Retrieves and removes the head of this queue, or returns `null` if this queue is empty.
public
poll() : mixed|null
Tags
Return values
mixed|null —the head of this queue, or null
if this queue is empty.
remove()
Retrieves and removes the head of this queue.
public
remove() : mixed
This method differs from poll()
only in that it throws an exception if
this queue is empty.
Tags
Return values
mixed —the head of this queue.
serialize()
Returns a serialized string representation of this array object.
public
serialize() : string
Tags
Return values
string —a PHP serialized string.
toArray()
Returns a native PHP array representation of this array object.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —unserialize()
Converts a serialized string representation into an instance object.
public
unserialize(string $serialized) : void
Parameters
- $serialized : string
-
A PHP serialized string to unserialize.
Tags
Return values
void —checkType()
Returns `true` if value is of the specified type.
protected
checkType(string $type, mixed $value) : bool
Parameters
- $type : string
-
The type to check the value against.
- $value : mixed
-
The value to check.
Return values
bool —toolValueToString()
Returns a string representation of the value.
protected
toolValueToString(mixed $value) : string
- null value:
'NULL'
- boolean:
'TRUE'
,'FALSE'
- array:
'Array'
- scalar: converted-value
- resource:
'(type resource #number)'
- object with
__toString()
: result of__toString()
- object DateTime: ISO 8601 date
- object:
'(className Object)'
- anonymous function: same as object
Parameters
- $value : mixed
-
the value to return as a string.