DiscordPHP Documentation

ApplicationIdentityRepository extends AbstractRepository
in package

The links between Discord users and their accounts in external systems, recorded for an application, and the game stats profiles published for them.

Identities are keyed by the external account rather than by an id, so there is no generic fetch: look them up by user or by external id instead.

Tags
see
ApplicationIdentity
Application
since
10.59.0
link
https://docs.discord.com/developers/resources/application-identity-profile

Table of Contents

Properties

$cache  : CacheWrapper
$class  : string
Class type allowed into the collection.
$discord  : mixed
$discrim  : string
The collection discriminator.
$endpoints  : array<string|int, mixed>
Endpoints for interacting with the Discord servers.
$factory  : Factory
The parts factory.
$http  : Http
The HTTP client.
$items  : array<string|int, mixed>
The items contained in the collection.
$vars  : array<string|int, mixed>
Variables that are related to the repository.

Methods

__call()  : mixed
This method checks if a method with the name "__Collection__{$name}" exists within the class. If it does, it calls that method with the provided arguments.
__construct()  : mixed
AbstractRepository constructor.
__debugInfo()  : array<string|int, mixed>
__get()  : mixed
Exposes the read-only \`discrim\` and \`cache\` properties.
clear()  : void
Clears the repository.
create()  : Part
Builds a new, empty part.
delete()  : PromiseInterface<string|int, ApplicationIdentity>
Deletes an identity.
fetch()  : PromiseInterface<string|int, Part>
Gets a part from the repository or Discord servers.
filter()  : ExCollectionInterface
Runs a filter callback over the repository and returns a new collection based on the response of the callback.
find()  : ApplicationIdentity|null
findByExternalId()  : PromiseInterface<string|int, ExCollectionInterface<string|int, ApplicationIdentity>|array<string|int, ApplicationIdentity>>
Returns the identities recorded for the Discord user currently linked to an external account.
first()  : ApplicationIdentity|null
forUser()  : PromiseInterface<string|int, ExCollectionInterface<string|int, ApplicationIdentity>|array<string|int, ApplicationIdentity>>
Returns the external identities a user has linked to the application.
fresh()  : PromiseInterface<string|int, Part>
Returns a part with fresh values.
freshen()  : PromiseInterface<string|int, static>
Freshens the repository cache.
get()  : ApplicationIdentity|null
getIterator()  : Traversable
Returns an iterator for the cache.
getProfile()  : PromiseInterface<string|int, ApplicationIdentityProfile>
Returns the game stats profile the application published for one of a user's identities.
has()  : bool
Checks if the array has an object.
jsonSerialize()  : array<string|int, mixed>
keys()  : array<string|int, int>|array<string|int, string>
Get the keys of the items.
last()  : ApplicationIdentity|null
offsetExists()  : bool
If the repository has an offset.
offsetGet()  : Part|null
Gets a part from the repository.
offsetSet()  : void
Sets a part into the repository.
offsetUnset()  : void
Unsets an index from the repository.
pull()  : Part|mixed
Pulls a part from the repository.
pushItem()  : self
Pushes a single item to the repository.
save()  : PromiseInterface<string|int, Part>
Attempts to save a part to the Discord servers.
set()  : mixed
Sets a part in the repository.
toArray()  : array<string|int, mixed>
Converts the weak caches to array.
updateProfile()  : PromiseInterface
Publishes the game stats profile for one of a user's identities.
values()  : array<string|int, mixed>
Get the values of the items.
cacheFreshen()  : PromiseInterface<string|int, static>
collectIdentities()  : ExCollectionInterface<string|int, ApplicationIdentity>|array<string|int, ApplicationIdentity>
Turns a wrapped list of identities into a collection.
userId()  : string
The id of a user given as a part or already as an id.

Properties

$class

Class type allowed into the collection.

protected string $class = \Discord\Parts\OAuth\ApplicationIdentity::class
Tags
inheritDoc

$endpoints

Endpoints for interacting with the Discord servers.

protected array<string|int, mixed> $endpoints = []

Endpoints.

Tags
inheritDoc

$items

The items contained in the collection.

protected array<string|int, mixed> $items = []

$vars

Variables that are related to the repository.

protected array<string|int, mixed> $vars = []

Variables.

Methods

__call()

This method checks if a method with the name "__Collection__{$name}" exists within the class. If it does, it calls that method with the provided arguments.

public __call(string $name, array<string|int, mixed> $arguments) : mixed

If the method does not exist, it throws a BadMethodCallException.

Previously, this class utilized parent::method to call methods from the parent class. This was changed to use the __Collection__method naming convention to avoid conflicts

Parameters
$name : string

The name of the method being called.

$arguments : array<string|int, mixed>

The arguments passed to the method.

Tags
throws
BadMethodCallException

If the method does not exist.

Return values
mixed —

The result of the called method.

__construct()

AbstractRepository constructor.

public __construct(Discord $discord[, array<string|int, mixed> $vars = [] ]) : mixed
Parameters
$discord : Discord
$vars : array<string|int, mixed> = []

An array of variables used for the endpoint.

__debugInfo()

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

__get()

Exposes the read-only \`discrim\` and \`cache\` properties.

public __get(string $key) : mixed
Parameters
$key : string

create()

Builds a new, empty part.

public create([array<string|int, mixed>|object $attributes = [] ][, bool $created = false ]) : Part
Parameters
$attributes : array<string|int, mixed>|object = []

The attributes for the new part.

$created : bool = false
Tags
throws
Exception
Return values
Part —

The new part.

delete()

Deletes an identity.

public delete(ApplicationIdentity $part[, string|null $reason = null ]) : PromiseInterface<string|int, ApplicationIdentity>
Parameters
$part : ApplicationIdentity

The identity to delete.

$reason : string|null = null

Unused; identities have no audit log.

Tags
link
https://docs.discord.com/developers/resources/application-identity-profile#delete-application-identity
Return values
PromiseInterface<string|int, ApplicationIdentity>

fetch()

Gets a part from the repository or Discord servers.

public fetch(string $id[, bool $fresh = false ]) : PromiseInterface<string|int, Part>
Parameters
$id : string

The ID to search for.

$fresh : bool = false

Whether we should skip checking the cache.

Tags
throws
Exception
Return values
PromiseInterface<string|int, Part>

filter()

Runs a filter callback over the repository and returns a new collection based on the response of the callback.

public filter(callable $callback) : ExCollectionInterface
Parameters
$callback : callable
Tags
todo

This method will be typed to return an ExCollectionInterface in v11

Return values
ExCollectionInterface

findByExternalId()

Returns the identities recorded for the Discord user currently linked to an external account.

public findByExternalId(string $provider_type, string $provider_issued_user_id[, string|null $provider_id = null ]) : PromiseInterface<string|int, ExCollectionInterface<string|int, ApplicationIdentity>|array<string|int, ApplicationIdentity>>
Parameters
$provider_type : string

The external account provider type.

$provider_issued_user_id : string

The user's ID in the external system.

$provider_id : string|null = null

Provider-specific identifier, when one is needed to tell identities apart.

Tags
link
https://docs.discord.com/developers/resources/application-identity-profile#get-application-identities-by-external-id
Return values
PromiseInterface<string|int, ExCollectionInterface<string|int, ApplicationIdentity>|array<string|int, ApplicationIdentity>> —

Empty when no identity matches.

forUser()

Returns the external identities a user has linked to the application.

public forUser(User|string $user) : PromiseInterface<string|int, ExCollectionInterface<string|int, ApplicationIdentity>|array<string|int, ApplicationIdentity>>

The user must have authorized the application with the application_identities.write scope.

Parameters
$user : User|string

The user or user id.

Tags
link
https://docs.discord.com/developers/resources/application-identity-profile#get-application-identities-by-user-id
Return values
PromiseInterface<string|int, ExCollectionInterface<string|int, ApplicationIdentity>|array<string|int, ApplicationIdentity>>

fresh()

Returns a part with fresh values.

public fresh(Part $part[, array<string|int, mixed> $queryparams = [] ]) : PromiseInterface<string|int, Part>
Parameters
$part : Part

The part to get fresh values.

$queryparams : array<string|int, mixed> = []

Query string params to add to the request (no validation)

Tags
throws
Exception
Return values
PromiseInterface<string|int, Part>

freshen()

Freshens the repository cache.

public freshen([array<string|int, mixed> $queryparams = [] ]) : PromiseInterface<string|int, static>
Parameters
$queryparams : array<string|int, mixed> = []

Query string params to add to the request (no validation)

Tags
throws
Exception
Return values
PromiseInterface<string|int, static>

getIterator()

Returns an iterator for the cache.

public & getIterator() : Traversable
Return values
Traversable

getProfile()

Returns the game stats profile the application published for one of a user's identities.

public getProfile(User|string $user, string $provider_issued_user_id) : PromiseInterface<string|int, ApplicationIdentityProfile>

The user must have authorized the application with the application_identities.write scope.

Parameters
$user : User|string

The user or user id.

$provider_issued_user_id : string

The user's ID in the external system.

Tags
link
https://docs.discord.com/developers/resources/application-identity-profile#get-application-identity-profile
Return values
PromiseInterface<string|int, ApplicationIdentityProfile>

has()

Checks if the array has an object.

public has(string|int ...$keys) : bool

Use async $repository->cache->has()

Parameters
$keys : string|int
Return values
bool

jsonSerialize()

public jsonSerialize([bool $assoc = true ]) : array<string|int, mixed>
Parameters
$assoc : bool = true
Tags
inheritDoc
Return values
array<string|int, mixed>

keys()

Get the keys of the items.

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

offsetExists()

If the repository has an offset.

public offsetExists(string|int $offset) : bool

Use async $repository->cache->has() This method is deprecated for userland code but can still be used internally within the library.

Parameters
$offset : string|int
Return values
bool

offsetGet()

Gets a part from the repository.

public offsetGet(string|int $offset) : Part|null

Use async $repository->cacheGet() or sync $repository->get() This method is deprecated for userland code but can still be used internally within the library.

Parameters
$offset : string|int
Return values
Part|null

offsetSet()

Sets a part into the repository.

public offsetSet(string|int $offset, ?Part $value) : void

Use async $repository->cache->set()

Parameters
$offset : string|int
$value : ?Part

offsetUnset()

Unsets an index from the repository.

public offsetUnset(string|int $offset) : void

Use async $repository->cache->delete()

Parameters
$offset : string|int

pull()

Pulls a part from the repository.

public pull(string|int $key[, mixed $default = null ]) : Part|mixed

Use async $repository->cachePull()

Parameters
$key : string|int
$default : mixed = null
Return values
Part|mixed

pushItem()

Pushes a single item to the repository.

public pushItem(Part $item) : self

Use async $repository->cache->set() This method is deprecated for userland code but can still be used internally within the library.

Parameters
$item : Part
Return values
self

save()

Attempts to save a part to the Discord servers.

public save(Part $part[, string|null $reason = null ]) : PromiseInterface<string|int, Part>

Use Part->save($reason) to ensure permissions are checked.

Parameters
$part : Part

The part to save.

$reason : string|null = null

Reason for Audit Log (if supported).

Tags
throws
Exception
Return values
PromiseInterface<string|int, Part>

toArray()

Converts the weak caches to array.

public toArray([bool $assoc = true ]) : array<string|int, mixed>

Use jsonSerialize

Parameters
$assoc : bool = true
Return values
array<string|int, mixed>

updateProfile()

Publishes the game stats profile for one of a user's identities.

public updateProfile(User|string $user, string $provider_issued_user_id, ?array<string|int, mixed> $data) : PromiseInterface

The data field is replaced in full on every update: anything left out of it is removed.

Parameters
$user : User|string

The user or user id.

$provider_issued_user_id : string

The user's ID in the external system.

$data : ?array<string|int, mixed>

['data'] The profile data: primary pre-configured stats and dynamic custom fields.

Tags
link
https://docs.discord.com/developers/resources/application-identity-profile#update-application-identity-profile
Return values
PromiseInterface

values()

Get the values of the items.

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

cacheFreshen()

protected cacheFreshen(object $response) : PromiseInterface<string|int, static>
Parameters
$response : object
Return values
PromiseInterface<string|int, static>

collectIdentities()

Turns a wrapped list of identities into a collection.

protected collectIdentities(object|array<string|int, mixed> $response) : ExCollectionInterface<string|int, ApplicationIdentity>|array<string|int, ApplicationIdentity>

Unkeyed: two providers can issue the same user id, and a keyed collection would drop one of them.

Parameters
$response : object|array<string|int, mixed>

The response, with its identities under identities.

Return values
ExCollectionInterface<string|int, ApplicationIdentity>|array<string|int, ApplicationIdentity>
On this page

Search results