\PhpApiPhpApi

This classe resolves URL routing by using annotations on methods.

It specifies a pattern that, when matched, triggers that operation.

Summary

Methods
Properties
Constants
start()
No public properties found
API_ANNOTATION_PATH
METHOD_ANNOTATION_PATH
__construct()
No protected properties found
N/A
generateRoutes()
addRoute()
getAllClasses()
validatePattern()
getRoute()
evaluateURL()
getUniquePatterns()
processRequestPattern()
searchRequestPattern()
explodePattern()
$sourceDir
$request
$requestMethod
$routes
$patterns
N/A

Constants

API_ANNOTATION_PATH

API_ANNOTATION_PATH

The file path where the @Api annotation is setup

METHOD_ANNOTATION_PATH

METHOD_ANNOTATION_PATH

The file path where the @Method annotation is setup

Properties

$sourceDir

$sourceDir : string

The directory this class will iterate looking for @Api annotation

Type

string

$request

$request : string

The request string captured from URL

Type

string

$requestMethod

$requestMethod : string

The request method (GET, PUT, DELETE.

..)

Type

string

$routes

$routes : array<mixed,\PhpApi\Route>

Holds all @Api routes.

It stores the pattern that triggers the route, class and function that will be executed, moreover the specific HTTP method used for that function

Type

array<mixed,\PhpApi\Route>

$patterns

$patterns : array

Stores only the patterns that triggers routes (to improve search speed)

Type

array

Methods

start()

start(string  $sourceDir) 

Start the PhpApi library and evaluates the actual URL

Parameters

string $sourceDir

The directory this class will iterate looking for @Api annotation

__construct()

__construct(string  $sourceDir) 

Initilizes the object loading routes and patterns. Do not instantiate this directly. Instead, use the

Parameters

string $sourceDir

The directory this class will iterate looking for @Api annotation

generateRoutes()

generateRoutes() 

Generates routes that triggers specific class methods

addRoute()

addRoute(\ReflectionMethod  $method, \PhpApi\Annotations\Api  $api, \PhpApi\Annotations\HttpMethod  $httpMethod = null) 

Adds the route and pattern for a given $method using a specific HTTP request method if available

Parameters

\ReflectionMethod $method

The class method that will be triggered

\PhpApi\Annotations\Api $api

The $method @Api annotation

\PhpApi\Annotations\HttpMethod $httpMethod

The $method @HttpMethod Annotation

getAllClasses()

getAllClasses() : array<mixed,\Saxulum\AnnotationManager\Helper\ClassInfo>

Returns all classes within the source directory

Returns

array<mixed,\Saxulum\AnnotationManager\Helper\ClassInfo>

validatePattern()

validatePattern(string  $pattern) : boolean

Validates @Api pattern string

Parameters

string $pattern

The pattern

Returns

boolean —

If the pattern is valid

getRoute()

getRoute(string  $pattern) : \PhpApi\Route

Returns the route for a given pattern

Parameters

string $pattern

The pattern

Returns

\PhpApi\Route

The route

evaluateURL()

evaluateURL() 

Evaluates URL looking for a route/pattern that matches the request

getUniquePatterns()

getUniquePatterns() : array

Returns all patterns used in @Api. This method returns just one ocurrence of the pattern even if it is used in multiple locations (with distinctive HTTP request methods)

Returns

array

processRequestPattern()

processRequestPattern(string  $pattern) 

Executes the class method for the given pattern

Parameters

string $pattern

searchRequestPattern()

searchRequestPattern() : string

Search for patterns that looks like the original request

Returns

string —

The pattern

explodePattern()

explodePattern(string  $pattern) : array

Explodes a pattern or route into a array using a slash as delimiter

Parameters

string $pattern

The pattern or route

Returns

array —

The exploded string