phramework doc
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Namespaces

  • Phramework
    • Authentication
    • Database
      • Operations
    • Exceptions
    • Extensions
    • Models
    • URIStrategy
    • Validate
    • Viewers

Classes

  • ClassBased
  • URITemplate

Interfaces

  • IURIStrategy

Class URITemplate

IURIStrategy implementation using URI templates

This strategy uses URI templates to validate the requested URI, if the URI matches a template then the assigned method will be executed.

This class is the preferable strategy if jsonapi is to be used.

It requires apache configuration via .htaccess

RewriteEngine On

#Required for URITemplate strategy
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
Phramework\URIStrategy\URITemplate implements Phramework\URIStrategy\IURIStrategy
Namespace: Phramework\URIStrategy
License: Apache-2.0
Author: Xenofon Spafaridis nohponex@gmail.com
Since: 1.0.0
Located at URIStrategy/URITemplate.php

Methods summary

public
# __construct( array[] $templates )

Create a URI Template strategy

Create a URI Template strategy

Parameters

$templates
List of URI template and meta - information objects

Todo

specify templates format
public
# addTemplates( array[] $templates )

Include additional templates

Include additional templates

Parameters

$templates
List of URI template and meta - information objects

Todo

specify templates format
public false|array
# test( string $URITemplate, string $URI )

Test an URI template validates the provided URI

Test an URI template validates the provided URI

Parameters

$URITemplate
URI Template
$URI
Provided URI

Returns

false|array

If the validation of the template is not successful then false will be returned, else a array with a key-value array in position 0 will be returned containing the extracter parameters from the URI template.

Todo

provide options to specify parameters data type (alphanumeric or int)
provide options to define optional parameters
public static string[2]
# URI( )

Get current URI and GET parameters from the requested URI

Get current URI and GET parameters from the requested URI

Returns

string[2]
Returns an array with current URI and GET parameters
public string[2]
# invoke( object & $requestParameters, string $requestMethod, array $requestHeaders, object|false $requestUser )

Invoke URIStrategy

Invoke URIStrategy

Parameters

$requestParameters
Request parameters
$requestMethod
HTTP request method
$requestHeaders
Request headers
$requestUser

Use object if successful authenticated otherwise false

Returns

string[2]
This method should return [$class, $method] on success

Throws

Phramework\Exceptions\NotFoundException
Phramework\Exceptions\UnauthorizedException

Todo

Use named parameters in future if available by PHP

Implementation of

Phramework\URIStrategy\IURIStrategy::invoke()
phramework doc API documentation generated by ApiGen