Documentation

Endpoints
in package
uses MatchesRoutes, ManagesTransformers

Endpoint management class.

Tags
author

Aberdeener

version
2.0.0-pr13
license

MIT

Table of Contents

Properties

$_endpoints  : array<string|int, EndpointBase>
$_transformers  : array<string|int, mixed>

Methods

getAll()  : array<string|int, EndpointBase>
Get all registered Endpoints.
getAllTransformers()  : array<string|int, mixed>
Get all registered transformers.
handle()  : void
Find an endpoint which matches this request and `execute()` it.
loadEndpoints()  : void
Recursively scan, preload and register EndpointBase classes in a folder.
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.
isVariable()  : bool
matchRoute()  : array<string|int, mixed>|false
Determine if an Endpoint matches a route.
stripVariable()  : string

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.

handle()

Find an endpoint which matches this request and `execute()` it.

public handle(string $route, string $method, Nameless2API $api) : void
Parameters
$route : string

Route to find endpoint for.

$method : string

HTTP method to find endpoint for.

$api : Nameless2API

Instance of api instance to provide the endpoint.

loadEndpoints()

Recursively scan, preload and register EndpointBase classes in a folder.

public loadEndpoints(string $path) : void
Parameters
$path : string

Path to scan from.

Tags
see
EndpointBase

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.

isVariable()

private isVariable(string $type) : bool
Parameters
$type : string
Return values
bool

matchRoute()

Determine if an Endpoint matches a route.

private matchRoute(EndpointBase $endpoint, string $route) : array<string|int, mixed>|false

If it does, return an array of variables to pass to the endpoint.

Parameters
$endpoint : EndpointBase

Endpoint to attempt to match.

$route : string

Route to match.

Return values
array<string|int, mixed>|false

Array of variables to pass to the endpoint, or false if the route does not match.

stripVariable()

private stripVariable(string $type) : string
Parameters
$type : string
Return values
string

        
On this page

Search results