DiscordPHP Documentation

AbstractRepository extends Collection
in package

Repositories provide a way to store and update parts on the Discord server.

Tags
since
4.0.0
author

Aaron Scherer aequasi@gmail.com

author

David Cole david.cole1340@gmail.com

Table of Contents

$cache  : CacheWrapper
$discrim  : string
The collection discriminator.
$cache  : CacheWrapper
$class  : string
Class type allowed into the collection.
$discrim  : string
The 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.
__construct()  : mixed
AbstractRepository constructor.
__debugInfo()  : array<string|int, mixed>
Returns an item that will be displayed for debugging.
__get()  : mixed
__serialize()  : array<string|int, mixed>
Returns the string representation of the collection.
__unserialize()  : void
Unserializes the collection.
clear()  : void
Clears the repository.
count()  : int
Counts the amount of objects in the collection.
create()  : Part
Builds a new, empty part.
delete()  : ExtendedPromiseInterface<string|int, Part>
Attempts to delete a part on the Discord servers.
fetch()  : ExtendedPromiseInterface<string|int, Part>
Gets a part from the repository or Discord servers.
fill()  : Collection
Fills an array of items into the collection.
filter()  : Collection
Runs a filter callback over the repository and returns a new collection based on the response of the callback.
find()  : Part|null
Runs a filter callback over the repository and returns the first part where the callback returns `true` when given the part.
first()  : Part|null
Returns the first cached part.
for()  : static
Creates a collection for a class.
fresh()  : ExtendedPromiseInterface<string|int, Part>
Returns a part with fresh values.
freshen()  : ExtendedPromiseInterface<string|int, static>
Freshens the repository cache.
from()  : static
Creates a collection from an array.
get()  : Part|null
Gets a part from the repository.
getIterator()  : Traversable
Returns an iterator for the cache.
has()  : bool
Checks if the array has an object.
isset()  : bool
If the collection has an offset.
jsonSerialize()  : array<string|int, mixed>
Serializes the object to a value that can be serialized natively by json_encode().
keys()  : array<string|int, int>|array<string|int, string>
Get the keys of the items.
last()  : Part|null
Returns the last cached part.
map()  : Collection
Runs a callback over the collection and creates a new collection.
merge()  : Collection
Merges another collection into this collection.
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.
push()  : Collection
Pushes items to the collection.
pushItem()  : $this
Pushes a single item to the repository.
save()  : ExtendedPromiseInterface<string|int, Part>
Attempts to save a part to the Discord servers.
serialize()  : string
Returns the string representation of the collection.
set()  : mixed
Sets a part in the repository.
toArray()  : array<string|int, mixed>
Converts the weak caches to array.
unserialize()  : void
Unserializes the collection.
cacheFreshen()  : ExtendedPromiseInterface<string|int, static>

Properties

$discrim read-only

The collection discriminator.

public string $discrim

The discriminator.

$class

Class type allowed into the collection.

protected string $class

$endpoints

Endpoints for interacting with the Discord servers.

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

Endpoints.

$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

__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.

Return values
mixed

__debugInfo()

Returns an item that will be displayed for debugging.

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

__get()

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

__serialize()

Returns the string representation of the collection.

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

__unserialize()

Unserializes the collection.

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

clear()

Clears the repository.

public clear() : void
Tags
deprecated
10.0.0

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

Return values
void

count()

Counts the amount of objects in the collection.

public count() : int
Return values
int

create()

Builds a new, empty part.

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

The attributes for the new part.

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

The new part.

delete()

Attempts to delete a part on the Discord servers.

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

The part to delete.

$reason : string|null = null

Reason for Audit Log (if supported).

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

fetch()

Gets a part from the repository or Discord servers.

public fetch(string $id[, bool $fresh = false ]) : ExtendedPromiseInterface<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
ExtendedPromiseInterface<string|int, Part>

fill()

Fills an array of items into the collection.

public fill(array<string|int, mixed> $items) : Collection
Parameters
$items : array<string|int, mixed>
Return values
Collection

filter()

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

public filter(callable $callback) : Collection
Parameters
$callback : callable
Return values
Collection

find()

Runs a filter callback over the repository and returns the first part where the callback returns `true` when given the part.

public find(callable $callback) : Part|null
Parameters
$callback : callable
Return values
Part|null

null if no items returns true when called in the callback.

for()

Creates a collection for a class.

public static for(string $class[, string $discrim = 'id' ]) : static
Parameters
$class : string
$discrim : string = 'id'
Return values
static

fresh()

Returns a part with fresh values.

public fresh(Part $part[, array<string|int, mixed> $queryparams = [] ]) : ExtendedPromiseInterface<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
ExtendedPromiseInterface<string|int, Part>

freshen()

Freshens the repository cache.

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

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

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

from()

Creates a collection from an array.

public static from([array<string|int, mixed> $items = [] ][, string $discrim = 'id' ][, string $class = null ]) : static
Parameters
$items : array<string|int, mixed> = []
$discrim : string = 'id'
$class : string = null
Return values
static

get()

Gets a part from the repository.

public get(string $discrim, mixed $key) : Part|null
Parameters
$discrim : string
$key : mixed
Return values
Part|null

getIterator()

Returns an iterator for the cache.

public & getIterator() : Traversable
Return values
Traversable

has()

Checks if the array has an object.

public has(array<string|int, mixed> ...$keys) : bool
Parameters
$keys : array<string|int, mixed>
Tags
deprecated
10.0.0

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

Return values
bool

isset()

If the collection has an offset.

public isset(mixed $offset) : bool
Parameters
$offset : mixed
Return values
bool

jsonSerialize()

Serializes the object to a value that can be serialized natively by json_encode().

public jsonSerialize() : array<string|int, mixed>
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>

map()

Runs a callback over the collection and creates a new collection.

public map(callable $callback) : Collection
Parameters
$callback : callable
Return values
Collection

offsetExists()

If the repository has an offset.

public offsetExists(string|int $offset) : bool
Parameters
$offset : string|int
Tags
deprecated
10.0.0

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

Return values
bool

offsetGet()

Gets a part from the repository.

public offsetGet(string|int $offset) : Part|null
Parameters
$offset : string|int
Tags
deprecated
10.0.0

Use async $repository->cacheGet() or sync $repository->get()

Return values
Part|null

offsetSet()

Sets a part into the repository.

public offsetSet(string|int $offset, Part|null $value) : void
Parameters
$offset : string|int
$value : Part|null
Tags
deprecated
10.0.0

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

Return values
void

offsetUnset()

Unsets an index from the repository.

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed
Tags
deprecated
10.0.0

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

Return values
void

pull()

Pulls a part from the repository.

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

Use async $repository->cachePull()

Return values
Part|mixed

pushItem()

Pushes a single item to the repository.

public pushItem(Part $item) : $this
Parameters
$item : Part
Tags
deprecated
10.0.0

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

Return values
$this

save()

Attempts to save a part to the Discord servers.

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

The part to save.

$reason : string|null = null

Reason for Audit Log (if supported).

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

serialize()

Returns the string representation of the collection.

public serialize() : string
Return values
string

set()

Sets a part in the repository.

public set(string|int $offset, Part $value) : mixed
Parameters
$offset : string|int
$value : Part
Return values
mixed

toArray()

Converts the weak caches to array.

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

unserialize()

Unserializes the collection.

public unserialize(string $serialized) : void
Parameters
$serialized : string
Return values
void

cacheFreshen()

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

Search results