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
$_media
protected
MediaCollectionInterface
$_media
$blueprints
protected
Blueprint|callable|null
$blueprints
$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
boolauthorise()
Checks user authorization to the action.
public
authorise(string $action) : bool
Use ->authorize() method instead.
Ensures backwards compatibility
Parameters
- $action : string
Return values
boolauthorize()
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|nullavatarUrl()
Return the User's avatar URL
public
avatarUrl() : string
Use ->getAvatarUrl() method instead.
Return values
stringblueprints()
Return blueprints.
public
blueprints() : Blueprint
Return values
Blueprintcount()
Implements Countable interface.
public
count() : int
Method makes no sense for user account.
Attributes
- #[ReturnTypeWillChange]
Return values
intexists()
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
boolextra()
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|nullfilter()
Filter all items by using blueprints.
public
filter() : $this
Return values
$thisfind()
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
UserInterfaceget()
public
abstract get(mixed $name[, mixed $default = null ][, mixed $separator = null ]) : mixed
Parameters
- $name : mixed
- $default : mixed = null
- $separator : mixed = null
getAvatarImage()
Return media object for the User's avatar.
public
getAvatarImage() : ImageMedium|StaticImageMedium|null
Note: if there's no local avatar image for the user, you should call getAvatarUrl() to get the external avatar URL.
Return values
ImageMedium|StaticImageMedium|nullgetAvatarMedia()
Return media object for the User's avatar.
public
getAvatarMedia() : Medium|null
Use ->getAvatarImage() method instead.
Return values
Medium|nullgetAvatarUrl()
Return the User's avatar URL
public
getAvatarUrl() : string
Return values
stringgetDefaults()
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
Return values
array<string|int, mixed>getMedia()
Gets the associated media collection.
public
getMedia() : MediaCollectionInterface|Media
Return values
MediaCollectionInterface|MediagetMediaFolder()
Get filesystem path to the associated media.
public
getMediaFolder() : string
Return values
stringgetMediaOrder()
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
booljoin()
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
Return values
$thisjoinDefaults()
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
$thisjsonSerialize()
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
UserInterfacemerge()
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
$thisoffsetExists()
public
offsetExists(string $offset) : bool
Parameters
- $offset : string
Attributes
- #[ReturnTypeWillChange]
Return values
booloffsetGet()
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
stringremove()
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
$thissetKeepEmptyValues()
public
setKeepEmptyValues(bool $value) : $this
Parameters
- $value : bool
Return values
$thissetMissingValuesAsNull()
public
setMissingValuesAsNull(bool $value) : $this
Parameters
- $value : bool
Return values
$thisundef()
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
$thisvalidate()
Validate by blueprints.
public
validate() : $this
Tags
Return values
$thisvalue()
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
Return values
mixed —Value.
filterUsername()
protected
filterUsername(string $username) : string
Parameters
- $username : string
Return values
stringgenerateMultiavatar()
protected
generateMultiavatar(string $hash) : string
Parameters
- $hash : string
Return values
stringgetAvatarFile()
protected
getAvatarFile() : string|null
Return values
string|nullgetCollection()
protected
static getCollection() : UserCollectionInterface