DiscordPHP Documentation

AbstractRepositoryInterface extends CollectionInterface

Contract for a DiscordPHP repository: a keyed, cached {@see CollectionInterface} of {@see Part}s for one Discord API resource, plus the async CRUD methods (`freshen()`, `fetch()`, `create()`, `save()`, `delete()`) that talk to the Discord REST API and keep the cache in sync. {@see AbstractRepository} is the concrete base every repository extends.

Tags
see
AbstractRepository

The abstract implementation

PartInterface

The items held by a repository

since
10.1.4

Table of Contents

Methods

__construct()  : mixed
__get()  : mixed
Reads an otherwise-protected repository property (`discrim`, `cache`, …).
cacheGet()  : PromiseInterface
Resolves with the cached item at `$offset`, loading it from the cache backend if needed.
cachePull()  : PromiseInterface
Removes and resolves with the cached item at `$key` (or `$default`).
clear()  : void
collect()  : ExCollectionInterface
Returns the repository's items as a new collection.
create()  : Part
Builds a new, un-saved Part of this repository's class from `$attributes`.
delete()  : PromiseInterface
Deletes `$part` (a Part or its id) on Discord and removes it from the repository.
fetch()  : PromiseInterface
Fetches the Part with id `$id`, resolving from cache unless `$fresh` is true.
filter()  : ExCollectionInterface
find()  : mixed
first()  : mixed
fresh()  : PromiseInterface
Re-fetches `$part` from the Discord API and refills it in place.
freshen()  : PromiseInterface
Freshens the repository from the Discord API and resolves with itself.
get()  : mixed
getIterator()  : Traversable
has()  : bool
jsonSerialize()  : array<string|int, mixed>
keys()  : array<string|int, mixed>
last()  : mixed
offsetExists()  : bool
offsetGet()  : mixed
offsetSet()  : void
offsetUnset()  : void
pull()  : mixed
pushItem()  : self
save()  : PromiseInterface
set()  : mixed
toArray()  : array<string|int, mixed>
values()  : array<string|int, mixed>

Methods

__construct()

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

Variables bound into the repository's endpoint URIs.

__get()

Reads an otherwise-protected repository property (`discrim`, `cache`, …).

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

cacheGet()

Resolves with the cached item at `$offset`, loading it from the cache backend if needed.

public cacheGet(mixed $offset) : PromiseInterface
Parameters
$offset : mixed
Return values
PromiseInterface

cachePull()

Removes and resolves with the cached item at `$key` (or `$default`).

public cachePull(mixed $key[, mixed $default = null ]) : PromiseInterface
Parameters
$key : mixed
$default : mixed = null
Return values
PromiseInterface

collect()

Returns the repository's items as a new collection.

public collect() : ExCollectionInterface
Return values
ExCollectionInterface

create()

Builds a new, un-saved Part of this repository's class from `$attributes`.

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

Whether the Part should be marked as already existing on Discord.

Return values
Part

delete()

Deletes `$part` (a Part or its id) on Discord and removes it from the repository.

public delete(Part|string $part[, string|null $reason = null ]) : PromiseInterface
Parameters
$part : Part|string
$reason : string|null = null

Audit-log reason.

Return values
PromiseInterface

fetch()

Fetches the Part with id `$id`, resolving from cache unless `$fresh` is true.

public fetch(string $id[, bool $fresh = false ]) : PromiseInterface
Parameters
$id : string
$fresh : bool = false
Return values
PromiseInterface

filter()

public filter(callable $callback) : ExCollectionInterface
Parameters
$callback : callable
Tags
inheritDoc
Return values
ExCollectionInterface

fresh()

Re-fetches `$part` from the Discord API and refills it in place.

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

Query string parameters for the fetch.

Return values
PromiseInterface

freshen()

Freshens the repository from the Discord API and resolves with itself.

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

Query string parameters for the list endpoint.

Return values
PromiseInterface

jsonSerialize()

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

offsetExists()

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed
Tags
inheritDoc
Return values
bool

offsetGet()

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

offsetSet()

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
$value : mixed
Tags
inheritDoc

pull()

public pull(mixed $key[, mixed $default = null ]) : mixed
Parameters
$key : mixed
$default : mixed = null
Tags
inheritDoc

save()

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

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

Parameters
$part : Part
$reason : string|null = null
Return values
PromiseInterface

toArray()

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

Use jsonSerialize

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

Search results