Alpha Framework 3.1.0 API Documentation

FrontController

The front controller designed to optionally handle all requests.

Tags
since
1.0
author

John Collins dev@alphaframework.org

license

http://www.opensource.org/licenses/bsd-license.php The BSD License

copyright

Copyright (c) 2018, John Collins (founder of Alpha Framework). All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.
* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the
  following disclaimer in the documentation and/or other
  materials provided with the distribution.
* Neither the name of the Alpha Framework nor the names
  of its contributors may be used to endorse or promote
  products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Table of Contents

$currentRoute  : string
The route for the current request.
$defaultParamValues  : array<string|int, mixed>
An optional 2D hash array of default request parameter values to use when those params are left off the request.
$encryptedQuery  : bool
Boolean to flag if the GET query string is encrypted or not.
$filters  : array<string|int, mixed>
An array of HTTP filters applied to each request to the front controller. Each member must implement FilterInterface!
$logger  : Logger
Trace logger.
$pageController  : string
The name of the page controller we want to invoke.
$queryString  : string
The GET query string.
$routes  : array<string|int, mixed>
An associative array of URIs to callable methods to service matching requests.
__construct()  : mixed
The constructor method.
addRoute()  : FrontController
Add a new route to map a URI to the callback that will service its requests, normally by invoking a controller class.
decodeQueryParams()  : string
Static method to return the decoded GET paramters from an encrytpted tk value.
encodeQuery()  : string
Static method for encoding a query string.
generateSecureURL()  : string
Static method for generating an absolute, secure URL for a page controller.
getDecodeQueryParams()  : array<string|int, mixed>
Static method to return the decoded GET paramters from an encrytpted tk value as an array of key/value pairs.
getFilters()  : array<string|int, mixed>
Returns the array of filters currently attached to this FrontController.
getPageController()  : string
Getter for the page controller.
getRouteCallback()  : callable
Get the defined callback in the routes array for the URI provided.
process()  : Response
Processes the supplied request by invoking the callable defined matching the request's URI.
registerFilter()  : mixed
Add the supplied filter object to the list of filters ran on each request to the front controller.
setEncrypt()  : mixed
Sets the encryption flag.
value()  : FrontController
Method to allow the setting of default request param values to be used when they are left off the request URI.

Properties

$currentRoute

The route for the current request.

private string $currentRoute
Tags
since
2.0

$defaultParamValues

An optional 2D hash array of default request parameter values to use when those params are left off the request.

private array<string|int, mixed> $defaultParamValues
Tags
since
2.0

$encryptedQuery

Boolean to flag if the GET query string is encrypted or not.

private bool $encryptedQuery = false
Tags
since
1.0

$filters

An array of HTTP filters applied to each request to the front controller. Each member must implement FilterInterface!

private array<string|int, mixed> $filters = array()
Tags
since
1.0

$pageController

The name of the page controller we want to invoke.

private string $pageController
Tags
since
1.0

$queryString

The GET query string.

private string $queryString
Tags
since
1.0

$routes

An associative array of URIs to callable methods to service matching requests.

private array<string|int, mixed> $routes
Tags
since
2.0

Methods

__construct()

The constructor method.

public __construct() : mixed
Tags
throws
BadRequestException
since
1.0
Return values
mixed

addRoute()

Add a new route to map a URI to the callback that will service its requests, normally by invoking a controller class.

public addRoute(string $URI, callable $callback) : FrontController
Parameters
$URI : string

The URL to match, can include params within curly } braces.

$callback : callable

The method to service the matched requests (should return a Response!).

Tags
throws
IllegalArguementException
since
2.0
Return values
FrontController

decodeQueryParams()

Static method to return the decoded GET paramters from an encrytpted tk value.

public static decodeQueryParams(mixed $tk) : string
Parameters
$tk : mixed
Tags
since
1.0
Return values
string

encodeQuery()

Static method for encoding a query string.

public static encodeQuery(string $queryString) : string
Parameters
$queryString : string
Tags
since
1.0
Return values
string

generateSecureURL()

Static method for generating an absolute, secure URL for a page controller.

public static generateSecureURL(string $params) : string
Parameters
$params : string
Tags
since
1.0
Return values
string

getDecodeQueryParams()

Static method to return the decoded GET paramters from an encrytpted tk value as an array of key/value pairs.

public static getDecodeQueryParams(mixed $tk) : array<string|int, mixed>
Parameters
$tk : mixed
Tags
since
1.0
Return values
array<string|int, mixed>

getFilters()

Returns the array of filters currently attached to this FrontController.

public getFilters() : array<string|int, mixed>
Tags
since
1.0
Return values
array<string|int, mixed>

getPageController()

Getter for the page controller.

public getPageController() : string
Tags
since
1.0
Return values
string

getRouteCallback()

Get the defined callback in the routes array for the URI provided.

public getRouteCallback(string $URI) : callable
Parameters
$URI : string

The URI to search for.

Tags
throws
IllegalArguementException
since
2.0
Return values
callable

setEncrypt()

Sets the encryption flag.

public setEncrypt(bool $encryptedQuery) : mixed
Parameters
$encryptedQuery : bool
Tags
since
1.0
Return values
mixed

value()

Method to allow the setting of default request param values to be used when they are left off the request URI.

public value(string $param, mixed $defaultValue) : FrontController
Parameters
$param : string

The param name (as defined on the route between } braces)

$defaultValue : mixed

The value to use

Tags
since
2.0
Return values
FrontController

Search results