ManagesTransformers
Contains methods to register + apply API route binding transformers.
Tags
Table of Contents
Properties
- $_transformers : array<string|int, mixed>
Methods
- getAllTransformers() : array<string|int, mixed>
- Get all registered transformers.
- registerTransformer() : void
- Register a transformer for API route binding.
- transform() : mixed
- Convert a value through a transformer based on its type. If no transformer is found, the value is returned as-is.
Properties
$_transformers
private
static array<string|int, mixed>
$_transformers
= []
Mapping of key names to closures to transform a variable into an object (ie, a user ID to a User object)
Methods
getAllTransformers()
Get all registered transformers.
public
static getAllTransformers() : array<string|int, mixed>
Return values
array<string|int, mixed> —All transformers.
registerTransformer()
Register a transformer for API route binding.
public
static registerTransformer(string $type, string $module, callable(Nameless2API, string): mixed $transformer) : void
Parameters
- $type : string
-
The name of the transformer. This is used to identify the transformer when binding.
- $module : string
-
The name of the module that registered the transformer.
- $transformer : callable(Nameless2API, string): mixed
-
Function which converts the value in the URL to the desired type.
transform()
Convert a value through a transformer based on its type. If no transformer is found, the value is returned as-is.
public
static transform(Nameless2API $api, string $type, string $value) : mixed
Parameters
- $api : Nameless2API
-
Instance of API to provide the transformer.
- $type : string
-
The type to use.
- $value : string
-
The value to convert.
Return values
mixed —The converted value.