Documentation

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.

Tags
template

T

extends

AbstractArray<T>

implements

QueueInterface<T>

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<array-key, T>
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.
__serialize()  : array<array-key, T>
Returns data suitable for PHP serialization.
__unserialize()  : void
Adds unserialized data to the object.
add()  : bool
Ensures that this queue contains the specified element (optional operation).
clear()  : void
Removes all items from this array.
count()  : int
Returns the number of items in this array.
element()  : T
Retrieves, but does not remove, the head of this queue.
getIterator()  : Traversable<array-key, T>
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 if it is possible to do so immediately without violating capacity restrictions.
offsetExists()  : bool
Returns `true` if the given offset exists in this array.
offsetGet()  : T|null
Returns the value at the specified offset.
offsetSet()  : void
Sets the given value to the given offset in the array.
offsetUnset()  : void
Removes the given offset and its value from the array.
peek()  : T|null
Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty.
poll()  : T|null
Retrieves and removes the head of this queue, or returns `null` if this queue is empty.
remove()  : T
Retrieves and removes the head of this queue.
serialize()  : string
Returns a serialized string representation of this array object.
toArray()  : array<array-key, T>
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<array-key, T> $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<array-key, T$data = [] ]) : mixed
Parameters
$queueType : string

The type (FQCN) associated with this queue.

$data : array<array-key, T> = []

The initial items to store in the collection.

Return values
mixed

__unserialize()

Adds unserialized data to the object.

public __unserialize(array<array-key, T$data) : void
Parameters
$data : array<array-key, T>
Return values
void

add()

Ensures that this queue contains the specified element (optional operation).

public add(mixed $element) : bool
Parameters
$element : mixed

The element to add to this queue.

Tags
inheritDoc
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

element()

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

public element() : T
Tags
inheritDoc
Return values
T

the head of this queue.

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 if it is possible to do so immediately without violating capacity restrictions.

public offer(mixed $element) : bool
Parameters
$element : mixed

The element to add to this queue.

Tags
inheritDoc
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(string|int $offset) : bool
Parameters
$offset : string|int

The offset to check.

Tags
link

ArrayAccess::offsetExists()

Return values
bool

offsetGet()

Returns the value at the specified offset.

public offsetGet(string|int $offset) : T|null
Parameters
$offset : string|int

The offset for which a value should be returned.

Tags
link

ArrayAccess::offsetGet()

psalm-suppress

InvalidAttribute

Return values
T|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 array.

public offsetSet(mixed $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

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

$value : mixed

The value to set at the given offset.

Return values
void

offsetUnset()

Removes the given offset and its value from the array.

public offsetUnset(string|int $offset) : void
Parameters
$offset : string|int

The offset to remove from the array.

Tags
link

ArrayAccess::offsetUnset()

Return values
void

peek()

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

public peek() : T|null
Tags
inheritDoc
Return values
T|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() : T|null
Tags
inheritDoc
Return values
T|null

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

remove()

Retrieves and removes the head of this queue.

public remove() : T
Tags
inheritDoc
Return values
T

the head of this queue.

serialize()

Returns a serialized string representation of this array object.

public serialize() : string
Tags
deprecated

The Serializable interface will go away in PHP 9.

link

Serializable::serialize()

Return values
string

a PHP serialized string.

toArray()

Returns a native PHP array representation of this array object.

public toArray() : array<array-key, T>
Tags
inheritDoc
Return values
array<array-key, T>

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
deprecated

The Serializable interface will go away in PHP 9.

link

Serializable::unserialize()

phpcsSuppress

SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint

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.

Return values
string

Search results