Since: 8.4

final class TokenList implements IteratorAggregate, Countable (View source)

Properties

int $length
string $value

Methods

string|null
item(int $index)

Returns a token from the list

bool
contains(string $token)

Returns whether the list contains a given token

void
add(string ...$tokens)

Adds the given tokens to the list

void
remove(string ...$tokens)

Removes the given tokens from the list

bool
toggle(string $token, bool|null $force = null)

Toggles the presence of a token in the list

bool
replace(string $token, string $newToken)

Replaces a token in the list with another one

bool
supports(string $token)

Returns whether the given token is supported

int
count()

Returns the number of tokens in the list

getIterator()

Returns an iterator over the token list

Details

string|null item(int $index)

Returns a token from the list

Returns a token from the list at index.

Parameters

int $index

The token index.

Return Value

string|null

Returns the token at index or null when the index is out of bounds.

bool contains(string $token)

Returns whether the list contains a given token

Returns whether the list contains token.

Parameters

string $token

The token.

Return Value

bool

Returns true if the list contains token, false otherwise.

void add(string ...$tokens)

Adds the given tokens to the list

Adds the given tokens to the list, but not any that were already present.

Parameters

string ...$tokens

The tokens to add.

Return Value

void

No value is returned.

void remove(string ...$tokens)

Removes the given tokens from the list

Removes the given tokens from the list, but ignores any that were not present.

Parameters

string ...$tokens

The tokens to remove.

Return Value

void

No value is returned.

bool toggle(string $token, bool|null $force = null)

Toggles the presence of a token in the list

Toggles the presence of token in the list.

Parameters

string $token

The token to toggle.

bool|null $force

If force is provided, setting it to true will add the token, and setting it to false will remove the token.

Return Value

bool

Returns true if the token is in the list after the call, false otherwise.

bool replace(string $token, string $newToken)

Replaces a token in the list with another one

Parameters

string $token

The token to replace.

string $newToken

The new token.

Return Value

bool

Returns true if token was in the list, false otherwise.

bool supports(string $token)

Returns whether the given token is supported

Returns whether token is in the associated attribute's supported tokens.

Parameters

string $token

The token.

Return Value

bool

Returns true on success or false on failure.

int count()

Returns the number of tokens in the list

Return Value

int

The custom count as an integer.

The return value is cast to an integer.

Traversable getIterator()

Returns an iterator over the token list

Return Value

Traversable

An instance of an object implementing Iterator or Traversable