SKURepository
extends AbstractRepository
in package
Contains all SKUs for a given application.
Because of how our SKU and subscription systems work, you will see two SKUs for your subscription offering.
For integration and testing entitlements for Subscriptions, you should use the SKU with type: 5.
Tags
Table of Contents
Properties
- $cache : CacheWrapper
- $discrim : string
- The collection discriminator.
- $cache : CacheWrapper
- $class : string
- Class type allowed into the collection.
- $discrim : string
- The collection discriminator.
- $endpoints : mixed
- {@inheritDoc}
- $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
- __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.
- all() : bool
- Checks if all items match the callback.
- any() : bool
- Checks if any item matches the callback.
- clear() : void
- Clears the repository.
- collect() : ExCollectionInterface
- Converts the items into a new collection.
- count() : int
- Counts the amount of objects in the collection.
- create() : Part
- Builds a new, empty part.
- delete() : PromiseInterface<string|int, Part>
- Attempts to delete a part on the Discord servers.
- diff() : ExCollectionInterface
- Gets the difference between the items.
- fetch() : PromiseInterface<string|int, Part>
- Gets a part from the repository or Discord servers.
- fill() : self
- Fills an array of items into the collection.
- filter() : ExCollectionInterface
- 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.
- find_key() : mixed
- Finds the key of the first item that matches the callback.
- first() : Part|null
- Returns the first cached part.
- for() : ExCollectionInterface
- Creates a collection for a class.
- fresh() : PromiseInterface<string|int, Part>
- Returns a part with fresh values.
- freshen() : PromiseInterface<string|int, static>
- Freshens the repository cache.
- from() : ExCollectionInterface
- 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.
- intersect() : ExCollectionInterface
- Gets the intersection of the items.
- isset() : bool
- If the collection has an offset.
- jsonSerialize() : array<string|int, mixed>
- {@inheritDoc}
- keys() : array<string|int, int>|array<string|int, string>
- Get the keys of the items.
- last() : Part|null
- Returns the last cached part.
- map() : ExCollectionInterface
- Runs a callback over the collection and creates a new Collection.
- merge() : self
- 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() : self
- Pushes items to the collection.
- pushItem() : self
- Pushes a single item to the repository.
- reduce() : ExCollectionInterface
- Reduces the collection to a single value using a callback function.
- save() : PromiseInterface<string|int, Part>
- Attempts to save a part to the Discord servers.
- search() : string|int|false
- Searches for a given value within the collection and returns the corresponding key if successful.
- serialize() : string
- Returns the string representation of the collection.
- set() : mixed
- Sets a part in the repository.
- shift() : mixed
- Shifts an item from the collection.
- slice() : ExCollectionInterface
- Slices the collection.
- sort() : ExCollectionInterface
- Sort through each item with a callback.
- splice() : self
- Splices the collection, removing a portion of the items and replacing them with the given replacement.
- toArray() : array<string|int, mixed>
- Converts the weak caches to array.
- unique() : ExCollectionInterface
- Returns unique items.
- unserialize() : void
- Unserializes the collection.
- values() : array<string|int, mixed>
- Get the values of the items.
- walk() : ExCollectionInterface
- Applies the given callback function to each item in the collection.
- cacheFreshen() : PromiseInterface<string|int, static>
Properties
$cache read-only
public
CacheWrapper
$cache
The react/cache wrapper.
$discrim
The collection discriminator.
public
string
$discrim
The discriminator.
$cache
protected
CacheWrapper
$cache
$class
Class type allowed into the collection.
protected
string
$class
= \Discord\Parts\Monetization\SKU::class
$discrim
The collection discriminator.
protected
string
$discrim
= 'id'
Discriminator.
$endpoints
{@inheritDoc}
protected
mixed
$endpoints
= ['all' => \Discord\Http\Endpoint::APPLICATION_SKUS]
$factory
The parts factory.
protected
Factory
$factory
Parts factory.
$http
The HTTP client.
protected
Http
$http
Client.
$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
Return values
mixed —The result of the called method.
__construct()
public
__construct(Discord $discord[, array<string|int, mixed> $vars = [] ]) : mixed
Parameters
- $discord : Discord
- $vars : array<string|int, 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
__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(ExCollectionInterface|array<string|int, mixed> $data) : void
Parameters
- $data : ExCollectionInterface|array<string|int, mixed>
all()
Checks if all items match the callback.
public
all(callable $callback) : bool
Parameters
- $callback : callable
Return values
boolany()
Checks if any item matches the callback.
public
any(callable $callback) : bool
Parameters
- $callback : callable
Return values
boolclear()
Clears the repository.
public
clear() : void
Use async $repository->cache->clear()
collect()
Converts the items into a new collection.
public
collect() : ExCollectionInterface
Return values
ExCollectionInterfacecount()
Counts the amount of objects in the collection.
public
count() : int
Return values
intcreate()
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
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 ]) : PromiseInterface<string|int, Part>
Parameters
- $part : Part|string
-
The part to delete.
- $reason : string|null = null
-
Reason for Audit Log (if supported).
Tags
Return values
PromiseInterface<string|int, Part>diff()
Gets the difference between the items.
public
diff(mixed $items[, callable|null $callback = null ]) : ExCollectionInterface
If a callback is provided and is callable, it uses array_udiff_assoc
to compute the difference.
Otherwise, it uses array_diff
.
Parameters
- $items : mixed
- $callback : callable|null = null
Return values
ExCollectionInterfacefetch()
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
Return values
PromiseInterface<string|int, Part>fill()
Fills an array of items into the collection.
public
fill(ExCollectionInterface|array<string|int, mixed> $items) : self
Parameters
- $items : ExCollectionInterface|array<string|int, mixed>
Return values
selffilter()
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
Return values
ExCollectionInterfacefind()
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.
find_key()
Finds the key of the first item that matches the callback.
public
find_key(callable $callback) : mixed
Parameters
- $callback : callable
first()
Returns the first cached part.
public
first() : Part|null
Return values
Part|nullfor()
Creates a collection for a class.
public
static for(string $class[, string|null $discrim = 'id' ]) : ExCollectionInterface
Parameters
- $class : string
- $discrim : string|null = 'id'
Return values
ExCollectionInterfacefresh()
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
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
Return values
PromiseInterface<string|int, static>from()
Creates a collection from an array.
public
static from([array<string|int, mixed> $items = [] ][, string|null $discrim = 'id' ][, string|null $class = null ]) : ExCollectionInterface
Parameters
- $items : array<string|int, mixed> = []
- $discrim : string|null = 'id'
- $class : string|null = null
Return values
ExCollectionInterfaceget()
Gets a part from the repository.
public
get(string $discrim, mixed $key) : Part|null
Parameters
- $discrim : string
- $key : mixed
Return values
Part|nullgetIterator()
Returns an iterator for the cache.
public
& getIterator() : Traversable
Return values
Traversablehas()
Checks if the array has an object.
public
has(string|int ...$keys) : bool
Use async $repository->cache->has()
Parameters
- $keys : string|int
Return values
boolintersect()
Gets the intersection of the items.
public
intersect(mixed $items[, callable|null $callback = null ]) : ExCollectionInterface
If a callback is provided and is callable, it uses array_uintersect_assoc
to compute the intersection.
Otherwise, it uses array_intersect
.
Parameters
- $items : mixed
- $callback : callable|null = null
Return values
ExCollectionInterfaceisset()
If the collection has an offset.
public
isset(mixed $offset) : bool
Parameters
- $offset : mixed
Return values
booljsonSerialize()
{@inheritDoc}
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>last()
Returns the last cached part.
public
last() : Part|null
Return values
Part|nullmap()
Runs a callback over the collection and creates a new Collection.
public
map(callable $callback) : ExCollectionInterface
Parameters
- $callback : callable
Return values
ExCollectionInterfacemerge()
Merges another collection into this collection.
public
merge(mixed $collection) : self
Parameters
- $collection : mixed
Return values
selfoffsetExists()
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
booloffsetGet()
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|nulloffsetSet()
Sets a part into the repository.
public
offsetSet(string|int $offset, Part|null $value) : void
Use async $repository->cache->set()
Parameters
- $offset : string|int
- $value : Part|null
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|mixedpush()
Pushes items to the collection.
public
push(mixed ...$items) : self
Parameters
- $items : mixed
Return values
selfpushItem()
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
selfreduce()
Reduces the collection to a single value using a callback function.
public
reduce(callable $callback[, mixed|null $initial = null ]) : ExCollectionInterface
Parameters
- $callback : callable
- $initial : mixed|null = null
Return values
ExCollectionInterfacesave()
Attempts to save a part to the Discord servers.
public
save(Part $part[, string|null $reason = null ]) : PromiseInterface<string|int, Part>
Parameters
- $part : Part
-
The part to save.
- $reason : string|null = null
-
Reason for Audit Log (if supported).
Tags
Return values
PromiseInterface<string|int, Part>search()
Searches for a given value within the collection and returns the corresponding key if successful.
public
search(mixed $needle[, bool $strict = false ]) : string|int|false
Parameters
- $needle : mixed
- $strict : bool = false
-
[optional]
Return values
string|int|falseserialize()
Returns the string representation of the collection.
public
serialize([int $flags = 0 ][, int|null $depth = 512 ]) : string
Parameters
- $flags : int = 0
- $depth : int|null = 512
Return values
stringset()
Sets a part in the repository.
public
set(string|int $offset, Part $value) : mixed
Parameters
- $offset : string|int
- $value : Part
shift()
Shifts an item from the collection.
public
shift() : mixed
slice()
Slices the collection.
public
slice(int $offset[, int|null $length = null ][, bool $preserve_keys = false ]) : ExCollectionInterface
Parameters
- $offset : int
- $length : int|null = null
- $preserve_keys : bool = false
Return values
ExCollectionInterfacesort()
Sort through each item with a callback.
public
sort(callable|int|null $callback) : ExCollectionInterface
Parameters
- $callback : callable|int|null
Return values
ExCollectionInterfacesplice()
Splices the collection, removing a portion of the items and replacing them with the given replacement.
public
splice(int $offset, int|null $length[, mixed $replacement = [] ]) : self
Parameters
- $offset : int
- $length : int|null
- $replacement : mixed = []
Return values
selftoArray()
Converts the weak caches to array.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>unique()
Returns unique items.
public
unique([int $flags = SORT_STRING ]) : ExCollectionInterface
Parameters
- $flags : int = SORT_STRING
Return values
ExCollectionInterfaceunserialize()
Unserializes the collection.
public
unserialize(string $serialized) : void
Parameters
- $serialized : string
values()
Get the values of the items.
public
values() : array<string|int, mixed>
Return values
array<string|int, mixed>walk()
Applies the given callback function to each item in the collection.
public
walk(callable $callback, mixed $arg) : ExCollectionInterface
Parameters
- $callback : callable
- $arg : mixed
Return values
ExCollectionInterfacecacheFreshen()
protected
cacheFreshen(object $response) : PromiseInterface<string|int, static>
Parameters
- $response : object