Documentation

User extends User
in package

Class User

Use $grav['accounts'] instead of static calls. In type hints, use UserInterface.

Table of Contents

Properties

$_media  : MediaCollectionInterface
$blueprints  : Blueprint|callable|null
$gettersVariable  : string
$items  : array<string|int, mixed>
$storage  : FileInterface|null

Methods

__construct()  : mixed
User constructor.
__sleep()  : array<string|int, string>
Serialize user.
__wakeup()  : mixed
Unserialize user.
authenticate()  : bool
Authenticate user.
authorise()  : bool
Checks user authorization to the action.
authorize()  : bool|null
Checks user authorization to the action.
avatarUrl()  : string
Return the User's avatar URL
blueprints()  : Blueprint
Return blueprints.
count()  : int
Implements Countable interface.
exists()  : bool
Returns whether the data already exists in the storage.
extra()  : array<string|int, mixed>
Get extra items which haven't been defined in blueprints.
file()  : FileInterface|null
Set or get the data storage.
filter()  : $this
Filter all items by using blueprints.
find()  : UserInterface
Find a user by username, email, etc
get()  : mixed
getAvatarImage()  : ImageMedium|StaticImageMedium|null
Return media object for the User's avatar.
getAvatarMedia()  : Medium|null
Return media object for the User's avatar.
getAvatarUrl()  : string
Return the User's avatar URL
getDefaults()  : array<string|int, mixed>
Get nested structure containing default values defined in the blueprints.
getJoined()  : array<string|int, mixed>
Get value from the configuration and join it with given data.
getMedia()  : MediaCollectionInterface|Media
Gets the associated media collection.
getMediaFolder()  : string
Get filesystem path to the associated media.
getMediaOrder()  : array<string|int, mixed>
Get display order for the associated media.
isValid()  : bool
join()  : $this
Join nested values together by using blueprints.
joinDefaults()  : $this
Set default values by using blueprints.
jsonSerialize()  : array<string|int, mixed>
load()  : UserInterface
Load user account.
merge()  : $this
Merge two configurations together.
offsetExists()  : bool
offsetGet()  : mixed
raw()  : string
Return unmodified data as raw string.
remove()  : bool
Remove user account.
save()  : void
Save user
set()  : mixed
setDefaults()  : $this
Set default values to the configuration if variables were not set.
setKeepEmptyValues()  : $this
setMissingValuesAsNull()  : $this
undef()  : mixed
update()  : $this
Update object with data
validate()  : $this
Validate by blueprints.
value()  : mixed
Get value by using dot notation for nested arrays/objects.
filterUsername()  : string
generateMultiavatar()  : string
getAvatarFile()  : string|null
getCollection()  : UserCollectionInterface

Properties

$gettersVariable

protected string $gettersVariable = 'items'

$items

protected array<string|int, mixed> $items

$storage

protected FileInterface|null $storage

Methods

__construct()

User constructor.

public __construct([array<string|int, mixed> $items = [] ][, Blueprint|null $blueprints = null ]) : mixed
Parameters
$items : array<string|int, mixed> = []
$blueprints : Blueprint|null = null

__sleep()

Serialize user.

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

__wakeup()

Unserialize user.

public __wakeup() : mixed

authenticate()

Authenticate user.

public authenticate(string $password) : bool

If user password needs to be updated, new information will be saved.

Parameters
$password : string

Plaintext password.

Return values
bool

authorise()

Checks user authorization to the action.

public authorise(string $action) : bool

Use ->authorize() method instead.

Ensures backwards compatibility

Parameters
$action : string
Return values
bool

authorize()

Checks user authorization to the action.

public authorize(string $action[, string|null $scope = null ]) : bool|null
Parameters
$action : string
$scope : string|null = null
Return values
bool|null

avatarUrl()

Return the User's avatar URL

public avatarUrl() : string

Use ->getAvatarUrl() method instead.

Return values
string

count()

Implements Countable interface.

public count() : int

Method makes no sense for user account.

Attributes
#[ReturnTypeWillChange]
Return values
int

exists()

Returns whether the data already exists in the storage.

public exists() : bool

NOTE: This method does not check if the data is current.

Return values
bool

extra()

Get extra items which haven't been defined in blueprints.

public extra() : array<string|int, mixed>
Return values
array<string|int, mixed>

file()

Set or get the data storage.

public file([FileInterface|null $storage = null ]) : FileInterface|null
Parameters
$storage : FileInterface|null = null

Optionally enter a new storage.

Return values
FileInterface|null

filter()

Filter all items by using blueprints.

public filter() : $this
Return values
$this

find()

Find a user by username, email, etc

public static find(string $query[, array<string|int, mixed> $fields = ['username', 'email'] ]) : UserInterface

Use $grav['accounts']->find(...) instead.

Always creates user object. To check if user exists, use $this->exists().

Parameters
$query : string

the query to search for

$fields : array<string|int, mixed> = ['username', 'email']

the fields to search

Return values
UserInterface

get()

public abstract get(mixed $name[, mixed $default = null ][, mixed $separator = null ]) : mixed
Parameters
$name : mixed
$default : mixed = null
$separator : mixed = null

getAvatarMedia()

Return media object for the User's avatar.

public getAvatarMedia() : Medium|null

Use ->getAvatarImage() method instead.

Return values
Medium|null

getAvatarUrl()

Return the User's avatar URL

public getAvatarUrl() : string
Return values
string

getDefaults()

Get nested structure containing default values defined in the blueprints.

public getDefaults() : array<string|int, mixed>

Fields without default value are ignored in the list.

Return values
array<string|int, mixed>

getJoined()

Get value from the configuration and join it with given data.

public getJoined(string $name, array<string|int, mixed>|object $value[, string $separator = '.' ]) : array<string|int, mixed>
Parameters
$name : string

Dot separated path to the requested value.

$value : array<string|int, mixed>|object

Value to be joined.

$separator : string = '.'

Separator, defaults to '.'

Tags
throws
RuntimeException
Return values
array<string|int, mixed>

getMediaFolder()

Get filesystem path to the associated media.

public getMediaFolder() : string
Return values
string

getMediaOrder()

Get display order for the associated media.

public getMediaOrder() : array<string|int, mixed>
Return values
array<string|int, mixed>

isValid()

public isValid() : bool
Return values
bool

join()

Join nested values together by using blueprints.

public join(string $name, mixed $value[, string $separator = '.' ]) : $this
Parameters
$name : string

Dot separated path to the requested value.

$value : mixed

Value to be joined.

$separator : string = '.'

Separator, defaults to '.'

Tags
throws
RuntimeException
Return values
$this

joinDefaults()

Set default values by using blueprints.

public joinDefaults(string $name, mixed $value[, string $separator = '.' ]) : $this
Parameters
$name : string

Dot separated path to the requested value.

$value : mixed

Value to be joined.

$separator : string = '.'

Separator, defaults to '.'

Return values
$this

jsonSerialize()

public jsonSerialize() : array<string|int, mixed>
Attributes
#[ReturnTypeWillChange]
Return values
array<string|int, mixed>

load()

Load user account.

public static load(string $username) : UserInterface

Use $grav['accounts']->load(...) instead.

Always creates user object. To check if user exists, use $this->exists().

Parameters
$username : string
Return values
UserInterface

merge()

Merge two configurations together.

public merge(array<string|int, mixed> $data) : $this

Use ->update($data) instead (same but with data validation & filtering, file upload support).

Parameters
$data : array<string|int, mixed>
Return values
$this

offsetExists()

public offsetExists(string $offset) : bool
Parameters
$offset : string
Attributes
#[ReturnTypeWillChange]
Return values
bool

offsetGet()

public offsetGet(string $offset) : mixed
Parameters
$offset : string
Attributes
#[ReturnTypeWillChange]

raw()

Return unmodified data as raw string.

public raw() : string

NOTE: This function only returns data which has been saved to the storage.

Return values
string

remove()

Remove user account.

public static remove(string $username) : bool

Use $grav['accounts']->delete(...) instead.

Parameters
$username : string
Return values
bool

True if the action was performed

save()

Save user

public save() : void

set()

public abstract set(mixed $name, mixed $value[, mixed $separator = null ]) : mixed
Parameters
$name : mixed
$value : mixed
$separator : mixed = null

setDefaults()

Set default values to the configuration if variables were not set.

public setDefaults(array<string|int, mixed> $data) : $this
Parameters
$data : array<string|int, mixed>
Return values
$this

setKeepEmptyValues()

public setKeepEmptyValues(bool $value) : $this
Parameters
$value : bool
Return values
$this

setMissingValuesAsNull()

public setMissingValuesAsNull(bool $value) : $this
Parameters
$value : bool
Return values
$this

undef()

public abstract undef(mixed $name[, mixed $separator = null ]) : mixed
Parameters
$name : mixed
$separator : mixed = null

update()

Update object with data

public update(array<string|int, mixed> $data[, array<string|int, mixed> $files = [] ]) : $this
Parameters
$data : array<string|int, mixed>
$files : array<string|int, mixed> = []
Return values
$this

validate()

Validate by blueprints.

public validate() : $this
Tags
throws
Exception
Return values
$this

value()

Get value by using dot notation for nested arrays/objects.

public value(string $name[, mixed $default = null ][, string $separator = '.' ]) : mixed
Parameters
$name : string

Dot separated path to the requested value.

$default : mixed = null

Default value (or null).

$separator : string = '.'

Separator, defaults to '.'

Tags
example

$value = $data->value('this.is.my.nested.variable');

Return values
mixed

Value.

filterUsername()

protected filterUsername(string $username) : string
Parameters
$username : string
Return values
string

generateMultiavatar()

protected generateMultiavatar(string $hash) : string
Parameters
$hash : string
Return values
string

getAvatarFile()

protected getAvatarFile() : string|null
Return values
string|null

        
On this page

Search results