PHP Class Zaphpa_Middleware, zaphpa

Show file Open project: zaphpa/zaphpa

Public Properties

Property Type Description
$context
$routes
$scope

Public Methods

Method Description
preprocess ( &$router ) Preprocess. This is where you'd add new routes *
prerender ( &$buffer ) This is your chance to override output. It can be called multiple times for each ->flush() invocation! *
preroute ( &$req, &$res ) Preroute. This is where you would aler request, or implement things like: security etc. *
restrict ( string $hook, $methods, $route ) : Zaphpa_Middlware Restrict a middleware hook to certain paths and HTTP methods.
shouldRun ( string $hook ) : boolean Determine whether the current route has any route restrictions for this middleware.

Method Details

preprocess() public method

Preprocess. This is where you'd add new routes *
public preprocess ( &$router )

prerender() public method

This is your chance to override output. It can be called multiple times for each ->flush() invocation! *
public prerender ( &$buffer )

preroute() public method

Preroute. This is where you would aler request, or implement things like: security etc. *
public preroute ( &$req, &$res )

restrict() public method

No actual restriction takes place in this method. We simply place the $methods array into $this->scope, keyed by its $hook.
public restrict ( string $hook, $methods, $route ) : Zaphpa_Middlware
$hook string A middleware hook, expecting either 'preroute' or 'prerender'. @param array $rules An associative array of paths and their allowed methods: - path: A URL route string, the same as are used in $router->addRoute(). - methods: An array of HTTP methods that are allowed, or an '*' to match all methods. @return Zaphpa_Middlware The current middleware object, to allow for chaining a la jQuery.
return Zaphpa_Middlware

shouldRun() public method

If the middleware has restrictions for a given $hook, we check for the current route. If the current route is in the list of allowed paths, we check that the request method is also allowed. Otherwise, the current route needn't run the $hook.
public shouldRun ( string $hook ) : boolean
$hook string A middleware hook, expecting either 'preroute' or 'prerender'. @return bool Whether the current route should run $hook.
return boolean

Property Details

$context public static property

public static $context

$routes public static property

public static $routes

$scope public property

public $scope