class User extends ORM implements AuthorizableInterface, MemberInterface, UserEntityInterface

User.

Traits

Authorizable trait.
Timestamped trait.

Constants

PRIMARY_KEY_TYPE_INCREMENTING

Incrementing primary key.

PRIMARY_KEY_TYPE_UUID

UUID primary key.

PRIMARY_KEY_TYPE_CUSTOM

Custom primary key.

PRIMARY_KEY_TYPE_NONE

No primary key.

Properties

protected string $connectionName Connection name to use for the model. from ORM
static protected ConnectionManager $connectionManager Connection manager instance. from ORM
static protected array $traitHooks ORM query builder hooks. from ORM
static protected array $traitCasts Trait casts. from ORM
protected string $tableName Table name.
protected string $foreignKeyName Foreign key name. from ORM
protected string $primaryKey Primary key. from ORM
protected int $primaryKeyType Does this table have an auto increment primary index? from ORM
protected bool $isPersisted Has the record been loaded from/saved to a database? from ORM
protected array $columns Column values. from ORM
protected array $original Original column values. from ORM
protected array $including Relations to eager load. from ORM
$related Related records. from ORM
protected array $cast Type casting.
protected array $assignable Columns that can be set through mass assignment. from ORM
protected array $protected Columns and relations that are excluded from the array and json representations of the record. from ORM
protected string $dateOutputFormat Date format used when returning array and json representations of the record. from ORM
protected AuthorizerInterface $authorizer Authorizer. from AuthorizableTrait
int $id
Time $created_at
Time $updated_at
string $email
string $username
string $password
string $ip
string $action_token
string $access_token
int $activated
int $banned
int $failed_attempts
Time|null $last_fail_at
Time|null $locked_until
ResultSet $groups

Methods

__construct(array $columns = [], bool $raw = false, bool $whitelist = true, bool $isPersisted = false)

Constructor.

from ORM
__clone()

Making sure that cloning returns a "fresh copy" of the record.

from ORM
static 
setConnectionManager(ConnectionManager $connectionManager)

Set the connection manager.

from ORM
getConnection()

Returns the connection of the model.

from ORM
bool
isPersisted()

Has the record been loaded from/saved to a database?

from ORM
synchronize()

Synchronizes the original values with the modified values.

from ORM
string
getDateFormat()

Gets the date format from the query builder compiler.

from ORM
registerHooksAndCasts()

Registers hooks and casts.

from ORM
array
bindHooks(array $hooks)

Binds the hooks to the current instance of "$this".

from ORM
array
getHooks(string $event)

Returns hooks for the chosen event.

from ORM
string
getClassShortName(string|null $className = null)

Returns the short name of a class.

from ORM
string
getTable()

Returns the table name of the model.

from ORM
string
getPrimaryKey()

Returns the primary key of the table.

from ORM
int
getPrimaryKeyType()

Returns the primary key type.

from ORM
mixed
getPrimaryKeyValue()

Returns the primary key value.

from ORM
string
getForeignKey()

Returns the foreign key of the table.

from ORM
string
getClass()

Returns the namespaced class name of the model.

from ORM
setIncludes(array $includes)

Sets the relations to eager load.

from ORM
array
getIncludes()

Returns the relations to eager load.

from ORM
setRelated(string $relation, mixed $related)

Sets eagerly loaded related records.

from ORM
bool
includes(string $relation)

Returns TRUE if the model has included the relationship and FALSE if not.

from ORM
$this
include(array|string $includes)

Eager loads relations on the model.

from ORM
array
getRelated()

Returns the related records array.

from ORM
mixed
cast(string $name, mixed $value)

Cast value to the appropriate type.

from ORM
setRawColumnValue(string $name, mixed $value)

Sets a raw column value.

from ORM
setColumnValue(string $name, mixed $value)

Sets a column value.

from ORM
mixed
getRawColumnValue(string $name)

Gets a raw column value.

from ORM
mixed
getColumnValue(string $name)

Returns a column value.

from ORM
bool
isRelation(string $name)

Returns TRUE if it's probable that $name is a relation and FALSE if not.

from ORM
mixed
getValue(string $name)

Gets a column value or relation.

from ORM
array
getRawColumnValues()

Returns the columns array.

from ORM
setColumValues(array $columns, bool $raw)

Sets column values.

from ORM
$this
assign(array $columns, bool $raw = false, bool $whitelist = true)

Assigns the column values to the model.

from ORM
__set(string $name, mixed $value)

Set column value using overloading.

from ORM
mixed
__get(string $name)

Get column value or relation using overloading.

from ORM
bool
__isset(string $name)

Checks if a column or relation is set using overloading.

from ORM
__unset(string $name)

Unset column value or relation using overloading.

from ORM
builder()

Returns a query builder instance.

from ORM
static ORM|null
get(mixed $id, array $columns = [])

Returns a record using the value of its primary key.

from ORM
static ORM
create(array $columns = [], bool $raw = false, bool $whitelist = true)

Creates a new record and returns the model.

from ORM
hasOne(string $model, string|null $foreignKey = null)

Returns a HasOne relation.

from ORM
hasOnePolymorphic(string $model, string $polymorphicType)

Returns a HasOnePolymorphic relation.

from ORM
hasMany(string $model, string|null $foreignKey = null)

Returns a HasMany relation.

from ORM
hasManyPolymorphic(string $model, string $polymorphicType)

Returns a HasManyPolymorphic relation.

from ORM
manyToMany(string $model, string|null $foreignKey = null, string|null $junctionTable = null, string|null $junctionKey = null)

Returns a ManyToMany relation.

from ORM
belongsTo(string $model, string|null $foreignKey = null)

Returns a BelongsTo relation.

from ORM
belongsToPolymorphic(string $model, string $polymorphicType)

Returns a BelongsToPolymorphic relation.

from ORM
bool
isModified()

Has the record been modified?

from ORM
array
getModified()

Returns the modified column values of the record.

from ORM
mixed
generatePrimaryKey()

Generates a primary key.

from ORM
insertRecord(Query $query)

Inserts a new record into the database.

from ORM
bool
updateRecord(Query $query)

Updates an existing record.

from ORM
bool
save()

Saves the record to the database.

from ORM
bool
deleteRecord(Query $query)

Deletes a record from the database.

from ORM
bool
delete()

Deletes a record from the database.

from ORM
$this
protect(array|false|string $column)

Excludes the chosen columns and relations from array and json representations of the record.

from ORM
$this
expose(array|string|true $column)

Exposes the chosen columns and relations in the array and json representations of the record.

from ORM
array
toArray()

Returns an array representation of the record.

from ORM
array
jsonSerialize()

Returns data which can be serialized by json_encode().

from ORM
string
toJson(int $options = 0)

Returns a json representation of the record.

from ORM
string
__toString()

Returns a json representation of the record.

from ORM
mixed
__call(string $name, array $arguments)

Forwards method calls to the query builder.

from ORM
static mixed
__callStatic(string $name, array $arguments)

Forwards static method calls to the query builder.

from ORM
setAuthorizer(AuthorizerInterface $authorizer)

Sets the authorizer.

bool
can(string $action, object|string $entity, mixed ...$parameters)

Returns TRUE if allowed to perform the action on the entity and FALSE if not.

array
getTimestampedTraitHooks()

Returns trait hooks.

array
getTimestampedTraitCasts()

Returns trait casts.

bool
shouldTouchOnInsert()

Should we touch relations on insert?

bool
shouldTouchOnUpdate()

Should we touch relations on update?

bool
shouldTouchOnDelete()

Should we touch relations on delete?

string
getCreatedAtColumn()

Returns the column that holds the "created at" timestamp.

string
getUpdatedAtColumn()

Returns the column that holds the "updated at" timestamp.

array
getRelationsToTouch()

Returns the relations that we should touch.

bool
touch()

Allows you to update the "updated at" timestamp without modifying any data.

touchRelated()

Touches related records.

groups()

User groups.

getHasher()

Returns a hasher instance.

string
passwordMutator(string $password)

Password mutator.

string
generateToken()

Generates a new token.

int
getId()

No description

setEmail(string $email)

Sets the user email address.

string
getEmail()

Returns the user email address.

setUsername(string $username)

Sets the username.

string
getUsername()

Returns the user username.

setPassword(string $password)

Sets the user password.

string
getPassword()

Returns the user password hash.

setIp(string $ip)

Sets the user IP address.

string
getIp()

Returns the user IP address.

string
generateActionToken()

Generates a new action token.

string
getActionToken()

Returns the user action token.

string
generateAccessToken()

Generates a new access token.

string
getAccessToken()

Returns the user access token.

activate()

Activates the user.

deactivate()

Deactivates the user.

bool
isActivated()

Returns TRUE of the user is activated and FALSE if not.

ban()

Bans the user.

unban()

Unbans the user.

bool
isBanned()

Returns TRUE if the user is banned and FALSE if not.

bool
validatePassword(string $password, bool $autoSave = true)

Returns TRUE if the provided password is correct and FALSE if not.

bool
isMemberOf(array|int|string $group)

Returns TRUE if a user is a member of the group(s) and FALSE if not.

lockUntil(DateTimeInterface $time)

Locks the account until the given date.

lockedUntil()

Returns null if the account isn't locked and a date time instance if it's locked.

unlock()

Unlocks the account.

bool
isLocked()

Returns TRUE if the account is locked and FALSE if not.

int
getFailedAttempts()

Returns the number of failed login attempts.

getLastFailAt()

Gets the time of the last failed attempt.

bool
throttle(int $maxLoginAttempts, int $lockTime, bool $autoSave = true)

Throttles login attempts.

bool
resetThrottle(bool $autoSave = true)

Resets the login throttling.

Details

in ORM at line 203
__construct(array $columns = [], bool $raw = false, bool $whitelist = true, bool $isPersisted = false)

Constructor.

Parameters

array $columns Column values
bool $raw Set raw values?
bool $whitelist Remove columns that are not in the whitelist?
bool $isPersisted Does the record come from a database?

in ORM at line 220
__clone()

Making sure that cloning returns a "fresh copy" of the record.

in ORM at line 237
static setConnectionManager(ConnectionManager $connectionManager)

Set the connection manager.

Parameters

ConnectionManager $connectionManager Connection manager instance

in ORM at line 247
Connection getConnection()

Returns the connection of the model.

Return Value

Connection

in ORM at line 262
bool isPersisted()

Has the record been loaded from/saved to a database?

Return Value

bool

in ORM at line 270
synchronize()

Synchronizes the original values with the modified values.

in ORM at line 280
protected string getDateFormat()

Gets the date format from the query builder compiler.

Return Value

string

in ORM at line 295
protected registerHooksAndCasts()

Registers hooks and casts.

in ORM at line 325
protected array bindHooks(array $hooks)

Binds the hooks to the current instance of "$this".

Parameters

array $hooks Array of hooks

Return Value

array

in ORM at line 343
array getHooks(string $event)

Returns hooks for the chosen event.

Parameters

string $event Event name

Return Value

array

in ORM at line 354
protected string getClassShortName(string|null $className = null)

Returns the short name of a class.

Parameters

string|null $className Class name

Return Value

string

in ORM at line 373
string getTable()

Returns the table name of the model.

Return Value

string

in ORM at line 388
string getPrimaryKey()

Returns the primary key of the table.

Return Value

string

in ORM at line 398
int getPrimaryKeyType()

Returns the primary key type.

Return Value

int

in ORM at line 408
mixed getPrimaryKeyValue()

Returns the primary key value.

Return Value

mixed

in ORM at line 418
string getForeignKey()

Returns the foreign key of the table.

Return Value

string

in ORM at line 433
string getClass()

Returns the namespaced class name of the model.

Return Value

string

in ORM at line 443
setIncludes(array $includes)

Sets the relations to eager load.

Parameters

array $includes Relations to eager load

in ORM at line 453
array getIncludes()

Returns the relations to eager load.

Return Value

array

in ORM at line 464
setRelated(string $relation, mixed $related)

Sets eagerly loaded related records.

Parameters

string $relation Relation name
mixed $related Related record(s)

in ORM at line 475
bool includes(string $relation)

Returns TRUE if the model has included the relationship and FALSE if not.

Parameters

string $relation Relation name

Return Value

bool

in ORM at line 486
$this include(array|string $includes)

Eager loads relations on the model.

Parameters

array|string $includes Relation or array of relations to eager load

Return Value

$this

in ORM at line 501
array getRelated()

Returns the related records array.

Return Value

array

in ORM at line 513
protected mixed cast(string $name, mixed $value)

Cast value to the appropriate type.

Parameters

string $name Column name
mixed $value Column value

Return Value

mixed

in ORM at line 543
setRawColumnValue(string $name, mixed $value)

Sets a raw column value.

Parameters

string $name Column name
mixed $value Column value

in ORM at line 554
setColumnValue(string $name, mixed $value)

Sets a column value.

Parameters

string $name Column name
mixed $value Column value

in ORM at line 574
mixed getRawColumnValue(string $name)

Gets a raw column value.

Parameters

string $name Column name

Return Value

mixed

in ORM at line 585
mixed getColumnValue(string $name)

Returns a column value.

Parameters

string $name Column name

Return Value

mixed

in ORM at line 601
protected bool isRelation(string $name)

Returns TRUE if it's probable that $name is a relation and FALSE if not.

Parameters

string $name Relation name

Return Value

bool

in ORM at line 612
mixed getValue(string $name)

Gets a column value or relation.

Parameters

string $name Column name

Return Value

mixed

in ORM at line 643
array getRawColumnValues()

Returns the columns array.

Return Value

array

in ORM at line 654
protected setColumValues(array $columns, bool $raw)

Sets column values.

Parameters

array $columns Column values
bool $raw Set raw values?

in ORM at line 687
$this assign(array $columns, bool $raw = false, bool $whitelist = true)

Assigns the column values to the model.

Parameters

array $columns Column values
bool $raw Set raw values?
bool $whitelist Remove columns that are not in the whitelist?

Return Value

$this

in ORM at line 716
__set(string $name, mixed $value)

Set column value using overloading.

Parameters

string $name Column name
mixed $value Column value

in ORM at line 727
mixed __get(string $name)

Get column value or relation using overloading.

Parameters

string $name Column name

Return Value

mixed

in ORM at line 738
bool __isset(string $name)

Checks if a column or relation is set using overloading.

Parameters

string $name Column or relation name

Return Value

bool

in ORM at line 753
__unset(string $name)

Unset column value or relation using overloading.

Parameters

string $name Column name

in ORM at line 763
Query builder()

Returns a query builder instance.

Return Value

Query

in ORM at line 775
static ORM|null get(mixed $id, array $columns = [])

Returns a record using the value of its primary key.

Parameters

mixed $id Primary key
array $columns Columns to select

Return Value

ORM|null

in ORM at line 788
static ORM create(array $columns = [], bool $raw = false, bool $whitelist = true)

Creates a new record and returns the model.

Parameters

array $columns Column values
bool $raw Set raw values?
bool $whitelist Remove columns that are not in the whitelist?

Return Value

ORM

in ORM at line 804
protected HasOne hasOne(string $model, string|null $foreignKey = null)

Returns a HasOne relation.

Parameters

string $model Related model
string|null $foreignKey Foreign key name

Return Value

HasOne

in ORM at line 818
protected HasOnePolymorphic hasOnePolymorphic(string $model, string $polymorphicType)

Returns a HasOnePolymorphic relation.

Parameters

string $model Related model
string $polymorphicType Polymorphic type

Return Value

HasOnePolymorphic

in ORM at line 832
protected HasMany hasMany(string $model, string|null $foreignKey = null)

Returns a HasMany relation.

Parameters

string $model Related model
string|null $foreignKey Foreign key name

Return Value

HasMany

in ORM at line 846
protected HasManyPolymorphic hasManyPolymorphic(string $model, string $polymorphicType)

Returns a HasManyPolymorphic relation.

Parameters

string $model Related model
string $polymorphicType Polymorphic type

Return Value

HasManyPolymorphic

in ORM at line 862
protected ManyToMany manyToMany(string $model, string|null $foreignKey = null, string|null $junctionTable = null, string|null $junctionKey = null)

Returns a ManyToMany relation.

Parameters

string $model Related model
string|null $foreignKey Foreign key name
string|null $junctionTable Junction table name
string|null $junctionKey Junction key name

Return Value

ManyToMany

in ORM at line 876
protected BelongsTo belongsTo(string $model, string|null $foreignKey = null)

Returns a BelongsTo relation.

Parameters

string $model Related model
string|null $foreignKey Foreign key name

Return Value

BelongsTo

in ORM at line 890
protected BelongsToPolymorphic belongsToPolymorphic(string $model, string $polymorphicType)

Returns a BelongsToPolymorphic relation.

Parameters

string $model Related model
string $polymorphicType Polymorphic type

Return Value

BelongsToPolymorphic

in ORM at line 902
bool isModified()

Has the record been modified?

Return Value

bool

in ORM at line 912
array getModified()

Returns the modified column values of the record.

Return Value

array

in ORM at line 932
protected mixed generatePrimaryKey()

Generates a primary key.

Return Value

mixed

in ORM at line 942
protected insertRecord(Query $query)

Inserts a new record into the database.

Parameters

Query $query Query builder

in ORM at line 970
protected bool updateRecord(Query $query)

Updates an existing record.

Parameters

Query $query Query builder

Return Value

bool

in ORM at line 982
bool save()

Saves the record to the database.

Return Value

bool

in ORM at line 1017
protected bool deleteRecord(Query $query)

Deletes a record from the database.

Parameters

Query $query Query builder

Return Value

bool

in ORM at line 1027
bool delete()

Deletes a record from the database.

Return Value

bool

in ORM at line 1053
$this protect(array|false|string $column)

Excludes the chosen columns and relations from array and json representations of the record.

You expose all fields by passing FALSE.

Parameters

array|false|string $column Column or relation to hide from the

Return Value

$this

in ORM at line 1067
$this expose(array|string|true $column)

Exposes the chosen columns and relations in the array and json representations of the record.

You can expose all fields by passing TRUE.

Parameters

array|string|true $column Column or relation to hide from the

Return Value

$this

in ORM at line 1079
array toArray()

Returns an array representation of the record.

Return Value

array

in ORM at line 1126
array jsonSerialize()

Returns data which can be serialized by json_encode().

Return Value

array

in ORM at line 1137
string toJson(int $options = 0)

Returns a json representation of the record.

Parameters

int $options JSON encode options

Return Value

string

in ORM at line 1147
string __toString()

Returns a json representation of the record.

Return Value

string

in ORM at line 1159
mixed __call(string $name, array $arguments)

Forwards method calls to the query builder.

Parameters

string $name Method name
array $arguments Method arguments

Return Value

mixed

in ORM at line 1171
static mixed __callStatic(string $name, array $arguments)

Forwards static method calls to the query builder.

Parameters

string $name Method name
array $arguments Method arguments

Return Value

mixed

in AuthorizableTrait at line 29
setAuthorizer(AuthorizerInterface $authorizer)

Sets the authorizer.

Parameters

AuthorizerInterface $authorizer Authorizer

in AuthorizableTrait at line 42
bool can(string $action, object|string $entity, mixed ...$parameters)

Returns TRUE if allowed to perform the action on the entity and FALSE if not.

Parameters

string $action Action
object|string $entity Entity
mixed ...$parameters Additional parameters

Return Value

bool

in TimestampedTrait at line 26
protected array getTimestampedTraitHooks()

Returns trait hooks.

Return Value

array

in TimestampedTrait at line 98
protected array getTimestampedTraitCasts()

Returns trait casts.

Return Value

array

in TimestampedTrait at line 108
protected bool shouldTouchOnInsert()

Should we touch relations on insert?

Return Value

bool

in TimestampedTrait at line 118
protected bool shouldTouchOnUpdate()

Should we touch relations on update?

Return Value

bool

in TimestampedTrait at line 128
protected bool shouldTouchOnDelete()

Should we touch relations on delete?

Return Value

bool

in TimestampedTrait at line 138
string getCreatedAtColumn()

Returns the column that holds the "created at" timestamp.

Return Value

string

in TimestampedTrait at line 148
string getUpdatedAtColumn()

Returns the column that holds the "updated at" timestamp.

Return Value

string

in TimestampedTrait at line 158
protected array getRelationsToTouch()

Returns the relations that we should touch.

Return Value

array

in TimestampedTrait at line 168
bool touch()

Allows you to update the "updated at" timestamp without modifying any data.

Return Value

bool

in TimestampedTrait at line 183
protected touchRelated()

Touches related records.

at line 70
ManyToMany groups()

User groups.

Return Value

ManyToMany

at line 80
protected HasherInterface getHasher()

Returns a hasher instance.

Return Value

HasherInterface

at line 91
protected string passwordMutator(string $password)

Password mutator.

Parameters

string $password Password

Return Value

string

at line 101
protected string generateToken()

Generates a new token.

Return Value

string

at line 46
int getId()

Return Value

int

at line 119
setEmail(string $email)

Sets the user email address.

Parameters

string $email Email address

at line 129
string getEmail()

Returns the user email address.

Return Value

string

at line 139
setUsername(string $username)

Sets the username.

Parameters

string $username Username

at line 147
string getUsername()

Returns the user username.

Return Value

string

at line 157
setPassword(string $password)

Sets the user password.

Parameters

string $password Password

at line 167
string getPassword()

Returns the user password hash.

Return Value

string

at line 177
setIp(string $ip)

Sets the user IP address.

Parameters

string $ip IP address

at line 187
string getIp()

Returns the user IP address.

Return Value

string

at line 197
string generateActionToken()

Generates a new action token.

Return Value

string

at line 207
string getActionToken()

Returns the user action token.

Return Value

string

at line 217
string generateAccessToken()

Generates a new access token.

Return Value

string

at line 227
string getAccessToken()

Returns the user access token.

Return Value

string

at line 235
activate()

Activates the user.

at line 243
deactivate()

Deactivates the user.

at line 253
bool isActivated()

Returns TRUE of the user is activated and FALSE if not.

Return Value

bool

at line 261
ban()

Bans the user.

at line 269
unban()

Unbans the user.

at line 279
bool isBanned()

Returns TRUE if the user is banned and FALSE if not.

Return Value

bool

at line 291
bool validatePassword(string $password, bool $autoSave = true)

Returns TRUE if the provided password is correct and FALSE if not.

Parameters

string $password Provided password
bool $autoSave Autosave rehashed password?

Return Value

bool

at line 317
bool isMemberOf(array|int|string $group)

Returns TRUE if a user is a member of the group(s) and FALSE if not.

Parameters

array|int|string $group Group name, group id or an array of group names or group ids

Return Value

bool

at line 343
lockUntil(DateTimeInterface $time)

Locks the account until the given date.

Parameters

DateTimeInterface $time Date

at line 353
DateTimeInterface|Time|null lockedUntil()

Returns null if the account isn't locked and a date time instance if it's locked.

Return Value

DateTimeInterface|Time|null

at line 361
unlock()

Unlocks the account.

at line 371
bool isLocked()

Returns TRUE if the account is locked and FALSE if not.

Return Value

bool

at line 381
int getFailedAttempts()

Returns the number of failed login attempts.

Return Value

int

at line 391
DateTimeInterface|Time|null getLastFailAt()

Gets the time of the last failed attempt.

Return Value

DateTimeInterface|Time|null

at line 404
bool throttle(int $maxLoginAttempts, int $lockTime, bool $autoSave = true)

Throttles login attempts.

Parameters

int $maxLoginAttempts Maximum number of failed login attempts
int $lockTime Number of seconds for which the account gets locked after reaching the maximum number of login attempts
bool $autoSave Autosave changes?

Return Value

bool

at line 442
bool resetThrottle(bool $autoSave = true)

Resets the login throttling.

Parameters

bool $autoSave Autosave changes?

Return Value

bool