PHP Basics

StrictQueue extends StrictList
in package
implements ArrayAccess, Countable, Iterator, Serializable

A type-sensitive, taversable First In, First Out queue (FIFO).

Extends \SplQueue with an option to specify the allowed data types for list items.

Tags
author

Sebastian Meyer sebastian.meyer@opencultureconsulting.com

template

AllowedType of mixed

Table of Contents

Interfaces

ArrayAccess
Countable
Iterator
Serializable

Properties

$allowedTypes  : array<string|int, string>

Methods

__construct()  : void
Create a type-sensitive, traversable queue of items.
add()  : void
Add/insert a new value at the specified offset.
append()  : void
Append values at the end of the list.
bottom()  : AllowedType
Peek at the value at the beginning of the list.
dequeue()  : AllowedType
Dequeue an item from the queue.
enqueue()  : void
Add an item to the queue.
getAllowedTypes()  : array<string|int, string>
Get allowed data types for list values.
getIteratorMode()  : int
Get the mode of iteration.
isAllowedType()  : bool
Check if the value's data type is allowed on the list.
offsetSet()  : void
Set the value at the specified offset.
pop()  : AllowedType
Pops an value from the end of the list.
prepend()  : void
Prepend values at the start of the list.
push()  : void
Push an value at the end of the list.
setIteratorMode()  : int
Set the mode of iteration.
shift()  : AllowedType
Shift an value from the beginning of the list.
top()  : AllowedType
Peek at the value at the end of the list.
unshift()  : void
Prepend the list with an value.
setAllowedTypes()  : void
Set allowed data types of list values.

Properties

$allowedTypes read-only

public array<string|int, string> $allowedTypes

The allowed data types for values.

Methods

__construct()

Create a type-sensitive, traversable queue 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
throws
InvalidArgumentException

add()

Add/insert a new value at the specified offset.

public add(int $offset, AllowedType $value) : void
APIYes
Parameters
$offset : int

The offset where the new value is to be inserted

$value : AllowedType

The new value for the offset

Tags
throws
InvalidArgumentException

append()

Append values at the end of the list.

public append(AllowedType ...$values) : void
APIYes
Parameters
$values : AllowedType

One or more values to append

Tags
throws
InvalidArgumentException

bottom()

Peek at the value at the beginning of the list.

public bottom() : AllowedType
APIYes
Tags
throws
RuntimeException
Return values
AllowedType

The first value of the list

dequeue()

Dequeue an item from the queue.

public dequeue() : AllowedType
APIYes
Return values
AllowedType

The dequeued item

enqueue()

Add an item to the queue.

public enqueue(AllowedType $item) : void
APIYes
Parameters
$item : AllowedType

The item to enqueue

Tags
throws
InvalidArgumentException

getAllowedTypes()

Get allowed data types for list values.

public getAllowedTypes() : array<string|int, string>
APIYes
Return values
array<string|int, string>

The list of allowed data types

getIteratorMode()

Get the mode of iteration.

public getIteratorMode() : int
APIYes
Return values
int

The set of flags and modes of iteration

isAllowedType()

Check if the value's data type is allowed on the list.

public isAllowedType(AllowedType $value) : bool
APIYes
Parameters
$value : AllowedType

The value to check

Return values
bool

Whether the value's data type is allowed

offsetSet()

Set the value at the specified offset.

public offsetSet(int|null $offset, AllowedType $value) : void
APIYes
Parameters
$offset : int|null

The offset being set or NULL to append

$value : AllowedType

The new value for the offset

Tags
throws
InvalidArgumentException

pop()

Pops an value from the end of the list.

public pop() : AllowedType
APIYes
Tags
throws
RuntimeException
Return values
AllowedType

The value from the end of the list

prepend()

Prepend values at the start of the list.

public prepend(AllowedType ...$values) : void
APIYes
Parameters
$values : AllowedType

One or more values to prepend

Tags
throws
InvalidArgumentException

push()

Push an value at the end of the list.

public push(AllowedType $value) : void
APIYes
Parameters
$value : AllowedType

The value to push

Tags
throws
InvalidArgumentException

setIteratorMode()

Set the mode of iteration.

public final setIteratorMode(int $mode) : int
APIYes
Parameters
$mode : int

The new iterator mode (0 or 1)

There are two orthogonal sets of modes that can be set.

The direction of iteration (fixed for StrictQueue):

  • StrictQueue::IT_MODE_FIFO (queue style)

The behavior of the iterator (either one or the other):

  • StrictQueue::IT_MODE_DELETE (delete items)
  • StrictQueue::IT_MODE_KEEP (keep items)

The default mode is: IT_MODE_FIFO | IT_MODE_KEEP

Tags
throws
RuntimeException
Return values
int

The set of flags and modes of iteration

shift()

Shift an value from the beginning of the list.

public shift() : AllowedType
APIYes
Tags
throws
RuntimeException
Return values
AllowedType

The first value of the list

top()

Peek at the value at the end of the list.

public top() : AllowedType
APIYes
Tags
throws
RuntimeException
Return values
AllowedType

The last value of the list

unshift()

Prepend the list with an value.

public unshift(AllowedType $value) : void
APIYes
Parameters
$value : AllowedType

The value to unshift

Tags
throws
InvalidArgumentException

setAllowedTypes()

Set allowed data types of list values.

protected setAllowedTypes([array<string|int, string> $allowedTypes = [] ]) : void
Parameters
$allowedTypes : array<string|int, string> = []

Allowed data types of values

Tags
throws
InvalidArgumentException

        
On this page

Search results