abstract class AbstractToken implements TokenInterface

Base class for Token instances.

Methods

__construct(array $roles = [])

No description

array
getRoleNames()

No description

Role[]
getRoles()

Returns the user roles.

string
getUsername()

Returns the username.

string|object
getUser()

Returns a user representation.

setUser(string|object $user)

Sets the user in the token.

bool
isAuthenticated()

Returns whether the user is authenticated or not.

setAuthenticated($authenticated)

Sets the authenticated flag.

eraseCredentials()

Removes sensitive information from the token.

serialize()

{@inheritdoc}

unserialize($serialized)

{@inheritdoc}

array
getState()

Returns all the necessary state of the object for serialization purposes.

setState(array $data)

Restores the object state from an array given by getState().

array
getAttributes()

Returns the token attributes.

setAttributes(array $attributes)

Sets the token attributes.

bool
hasAttribute(string $name)

Returns true if the attribute exists.

mixed
getAttribute(string $name)

Returns an attribute value.

setAttribute(string $name, mixed $value)

Sets an attribute.

string
__toString()

Returns a string representation of the Token.

Details

at line 38
__construct(array $roles = [])

Parameters

array $roles An array of roles

Exceptions

InvalidArgumentException

at line 52
array getRoleNames()

Return Value

array

at line 60
Role[] getRoles()

Returns the user roles.

Return Value

Role[] An array of Role instances

at line 72
string getUsername()

Returns the username.

Return Value

string

at line 84
string|object getUser()

Returns a user representation.

Return Value

string|object Can be a UserInterface instance, an object implementing a __toString method, or the username as a regular string

at line 92
setUser(string|object $user)

Sets the user in the token.

The user can be a UserInterface instance, or an object implementing a __toString method or the username as a regular string.

Parameters

string|object $user The user

Exceptions

InvalidArgumentException

at line 122
bool isAuthenticated()

Returns whether the user is authenticated or not.

Return Value

bool true if the token has been authenticated, false otherwise

at line 130
setAuthenticated($authenticated)

Sets the authenticated flag.

Parameters

$authenticated

at line 138
eraseCredentials()

Removes sensitive information from the token.

at line 152
serialize()

{@inheritdoc}

at line 171
unserialize($serialized)

{@inheritdoc}

Parameters

$serialized

at line 191
protected array getState()

Returns all the necessary state of the object for serialization purposes.

There is no need to serialize any entry, they should be returned as-is. If you extend this method, keep in mind you MUST guarantee parent data is present in the state. Here is an example of how to extend this method: protected function getState(): array { return [$this->childAttribute, parent::getState()]; }

Return Value

array

See also

setState()

at line 212
protected setState(array $data)

Restores the object state from an array given by getState().

There is no need to unserialize any entry in $data, they are already ready-to-use. If you extend this method, keep in mind you MUST pass the parent data to its respective class. Here is an example of how to extend this method: protected function setState(array $data) { [$this->childAttribute, $parentData] = $data; parent::setState($parentData); }

Parameters

array $data

See also

getState()

at line 222
array getAttributes()

Returns the token attributes.

Return Value

array The token attributes

at line 232
setAttributes(array $attributes)

Sets the token attributes.

Parameters

array $attributes The token attributes

at line 244
bool hasAttribute(string $name)

Returns true if the attribute exists.

Parameters

string $name The attribute name

Return Value

bool true if the attribute exists, false otherwise

at line 258
mixed getAttribute(string $name)

Returns an attribute value.

Parameters

string $name The attribute name

Return Value

mixed The attribute value

Exceptions

InvalidArgumentException When attribute doesn't exist for this token

at line 273
setAttribute(string $name, mixed $value)

Sets an attribute.

Parameters

string $name The attribute name
mixed $value The attribute value

at line 281
string __toString()

Returns a string representation of the Token.

This is only to be used for debugging purposes.

Return Value

string