class Queue extends AbstractArray implements QueueInterface (View source)

This class provides a basic implementation of QueueInterface, to minimize the effort required to implement this interface.

Traits

Provides functionality to check values for specific types.
Provides functionality to express a value as string

Properties

protected array $data The items of this array. from AbstractArray
protected int $index The index of the head of the queue.

Methods

__construct(string $queueType, array $data = [])

Constructs a queue object of the specified type, optionally with the specified data.

getIterator()

Returns an iterator for this array.

bool
offsetExists(mixed $offset)

Returns true if the given offset exists in this array.

mixed|null
offsetGet(mixed $offset)

Returns the value at the specified offset.

void
offsetSet(mixed|null $offset, mixed $value)

Sets the given value to the given offset in the queue.

void
offsetUnset(mixed $offset)

Removes the given offset and its value from the array.

string
serialize()

Returns a serialized string representation of this array object.

void
unserialize(string $serialized)

Converts a serialized string representation into an instance object.

int
count()

Returns the number of items in this array.

void
clear()

Removes all items from this array.

array
toArray()

Returns a native PHP array representation of this array object.

bool
isEmpty()

Returns true if this array is empty.

bool
checkType(string $type, mixed $value)

Returns true if value is of the specified type.

from TypeTrait
string
toolValueToString(mixed $value)

Returns a string representation of the value.

bool
add(mixed $element)

Ensures that this queue contains the specified element.

mixed
element()

Retrieves, but does not remove, the head of this queue.

bool
offer(mixed $element)

Inserts the specified element into this queue.

mixed|null
peek()

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

mixed|null
poll()

Retrieves and removes the head of this queue, or returns null if this queue is empty.

mixed
remove()

Retrieves and removes the head of this queue.

string
getType()

Returns the type associated with this queue.

Details

__construct(string $queueType, array $data = [])

Constructs a queue object of the specified type, optionally with the specified data.

Parameters

string $queueType The type (FQCN) associated with this queue.
array $data The initial items to add to this array.

Traversable getIterator()

Returns an iterator for this array.

Return Value

Traversable

bool offsetExists(mixed $offset)

Returns true if the given offset exists in this array.

Parameters

mixed $offset The offset to check.

Return Value

bool

mixed|null offsetGet(mixed $offset)

Returns the value at the specified offset.

Parameters

mixed $offset The offset for which a value should be returned.

Return Value

mixed|null the value stored at the offset, or null if the offset does not exist.

void offsetSet(mixed|null $offset, mixed $value)

Sets the given value to the given offset in the queue.

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

mixed|null $offset The offset to set. If null, the value may be set at a numerically-indexed offset.
mixed $value The value to set at the given offset.

Return Value

void

Exceptions

InvalidArgumentException when the value does not match the specified type for this queue.

void offsetUnset(mixed $offset)

Removes the given offset and its value from the array.

Parameters

mixed $offset The offset to remove from the array.

Return Value

void

string serialize()

Returns a serialized string representation of this array object.

Return Value

string a PHP serialized string.

void unserialize(string $serialized)

Converts a serialized string representation into an instance object.

Parameters

string $serialized A PHP serialized string to unserialize.

Return Value

void

int count()

Returns the number of items in this array.

Return Value

int

void clear()

Removes all items from this array.

Return Value

void

array toArray()

Returns a native PHP array representation of this array object.

Return Value

array

bool isEmpty()

Returns true if this array is empty.

Return Value

bool

protected bool checkType(string $type, mixed $value)

Returns true if value is of the specified type.

Parameters

string $type The type to check the value against.
mixed $value The value to check.

Return Value

bool

protected string toolValueToString(mixed $value)

Returns a string representation of the value.

  • 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

mixed $value the value to return as a string.

Return Value

string

bool add(mixed $element)

Ensures that this queue contains the specified element.

This method differs from offer() only in that it throws an exception if it cannot add the element to the queue.

Parameters

mixed $element The element to add to this queue.

Return Value

bool true if this queue changed as a result of the call.

Exceptions

InvalidArgumentException when the element does not match the specified type for this queue.

See also

Queue::offer

mixed element()

Retrieves, but does not remove, the head of this queue.

This method differs from peek() only in that it throws an exception if this queue is empty.

Return Value

mixed the head of this queue.

Exceptions

NoSuchElementException if this queue is empty.

See also

Queue::peek

bool offer(mixed $element)

Inserts the specified element into this queue.

This method differs from add() only in that it does not throw an exception if it cannot add the element to the queue.

Parameters

mixed $element The element to add to this queue.

Return Value

bool true if the element was added to this queue, else false.

See also

Queue::add

mixed|null peek()

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Return Value

mixed|null the head of this queue, or null if this queue is empty.

See also

Queue::element

mixed|null poll()

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Return Value

mixed|null the head of this queue, or null if this queue is empty.

See also

Queue::remove

mixed remove()

Retrieves and removes the head of this queue.

This method differs from poll() only in that it throws an exception if this queue is empty.

Return Value

mixed the head of this queue.

Exceptions

NoSuchElementException if this queue is empty.

See also

Queue::poll

string getType()

Returns the type associated with this queue.

Return Value

string