Symfony2 API
Class

Symfony\Component\Security\Core\Authentication\Token\AbstractToken

abstract class AbstractToken implements TokenInterface

Base class for Token instances.

Methods

__construct(array $roles = array())

Constructor.

RoleInterface[] getRoles()

Returns the user roles.

string getUsername()

Returns the username.

mixed getUser()

Returns a user representation.

setUser(mixed $user)

Sets the user in the token.

Boolean 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 getAttributes()

Returns the token attributes.

setAttributes(array $attributes)

Sets the token attributes.

Boolean hasAttribute(string $name)

Returns true if the attribute exists.

mixed getAttribute(string $name)

Returns an attribute value.

setAttribute(string $name, mixed $value)

Sets a attribute.

string __toString()

Returns a string representation of the Token.

Details

at line 40
public __construct(array $roles = array())

Constructor.

Parameters

array $roles An array of roles

Exceptions

InvalidArgumentException

at line 60
public RoleInterface[] getRoles()

Returns the user roles.

Return Value

RoleInterface[] An array of RoleInterface instances.

at line 68
public string getUsername()

Returns the username.

Return Value

string

at line 77
public mixed getUser()

Returns a user representation.

Return Value

mixed either returns an object which implements __toString(), or a primitive string is returned.

at line 91
public setUser(mixed $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

mixed $user The user

Exceptions

InvalidArgumentException

at line 121
public Boolean isAuthenticated()

Returns whether the user is authenticated or not.

Return Value

Boolean true if the token has been authenticated, false otherwise

at line 129
public setAuthenticated($authenticated)

Sets the authenticated flag.

Parameters

$authenticated

at line 137
public eraseCredentials()

Removes sensitive information from the token.

at line 147
public serialize()

{@inheritdoc}

at line 155
public unserialize($serialized)

{@inheritdoc}

Parameters

$serialized

at line 165
public array getAttributes()

Returns the token attributes.

Return Value

array The token attributes

at line 175
public setAttributes(array $attributes)

Sets the token attributes.

Parameters

array $attributes The token attributes

at line 187
public Boolean hasAttribute(string $name)

Returns true if the attribute exists.

Parameters

string $name The attribute name

Return Value

Boolean true if the attribute exists, false otherwise

at line 201
public 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 216
public setAttribute(string $name, mixed $value)

Sets a attribute.

Parameters

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

at line 224
public string __toString()

Returns a string representation of the Token.

This is only to be used for debugging purposes.

Return Value

string