PHP Class Scalr\Api\Rest\Application

Since: 5.4.0 (09.02.2015)
Author: Vitaliy Demidov ([email protected])
Show file Open project: scalr/scalr Class Usage Examples

Public Properties

Property Type Description
$startTime float API Application start time

Protected Properties

Property Type Description
$pathPreprocessor callable Preprocess request method and path

Public Methods

Method Description
__construct ( array $settings = [] ) Constructor
__get ( $name )
__isset ( $name )
addRoute ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route Adds a route to routing table
call ( ) Application wide handler
delete ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route Adds delete route
error ( Callable | Exception $e = null ) Error handler
get ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route Adds get route
getContainer ( ) : Container Gets API Container
getDefaultSettings ( )
getRouteUrl ( string $route, array $params = [] ) : string Gets url for the specified route
group ( ) Route Groups
halt ( number $status, string $message = '' ) Stops application immediately
handleApiVersion ( Scalr\Api\Rest\Routing\Route $route ) ApiVersion middleware handler
handleErrors ( integer $errno, string $errstr, string $errfile, integer $errline ) : boolean Error handler
notFound ( ) Not found handler
options ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route Adds options route
patch ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route Adds patch route
post ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route Adds post route
put ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route Adds put route
redirect ( string $url, number $status = 302 ) Redirects to the specified url
redirectTo ( string $route, array $params = [], number $status = 302 ) Redirects to the specified named route
run ( ) Runs application
stop ( ) Stops application

Protected Methods

Method Description
callErrorHandler ( Exception $e = null ) : string Calls error handler
defaultError ( ErrorException $e = null ) : string Gets default error content
getDefaultTemplate ( string $title, string $body ) : string Parses default template and returns its content

Method Details

__construct() public method

Constructor
public __construct ( array $settings = [] )
$settings array optional Application settings

__get() public method

public __get ( $name )

__isset() public method

public __isset ( $name )

addRoute() public method

Adds a route to routing table
public addRoute ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route
$path string The path pattern of the route
$options array | callable The options
$requirements array optional The requirements
return Scalr\Api\Rest\Routing\Route Returns route instance

call() public method

Application wide handler
public call ( )

callErrorHandler() protected method

Calls error handler
protected callErrorHandler ( Exception $e = null ) : string
$e Exception optional An exception
return string

defaultError() protected method

Gets default error content
protected defaultError ( ErrorException $e = null ) : string
$e ErrorException optional An Exception
return string

delete() public method

Adds delete route
public delete ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route
$path string The path pattern of the route
$options array | callable The options
$requirements array optional The requirements
return Scalr\Api\Rest\Routing\Route Returns route instance

error() public method

It registers error handler or invokes registered error handler with an exception
public error ( Callable | Exception $e = null )
$e Callable | Exception optional Either the callable handler or exception

get() public method

Adds get route
public get ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route
$path string The path pattern of the route
$options array | callable The options
$requirements array optional The requirements
return Scalr\Api\Rest\Routing\Route Returns route instance

getContainer() public method

Gets API Container
public getContainer ( ) : Container
return Scalr\DependencyInjection\Container Returns DI Container instance

getDefaultSettings() public static method

public static getDefaultSettings ( )

getDefaultTemplate() protected method

Parses default template and returns its content
protected getDefaultTemplate ( string $title, string $body ) : string
$title string A title
$body string A body
return string Returns parsed template

getRouteUrl() public method

Gets url for the specified route
public getRouteUrl ( string $route, array $params = [] ) : string
$route string The name of the route
$params array optional The parameters
return string Returns the URL for the specified Route

group() public method

Route Groups
public group ( )

halt() public method

Stops application immediately
public halt ( number $status, string $message = '' )
$status number HTTP response status code
$message string optional The response message

handleApiVersion() public method

It extracts :apiversion group parameter from the route and sets application setting
public handleApiVersion ( Scalr\Api\Rest\Routing\Route $route )
$route Scalr\Api\Rest\Routing\Route A route

handleErrors() public static method

Error handler
public static handleErrors ( integer $errno, string $errstr, string $errfile, integer $errline ) : boolean
$errno integer
$errstr string
$errfile string
$errline integer
return boolean

notFound() public method

Not found handler
public notFound ( )

options() public method

Adds options route
public options ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route
$path string The path pattern of the route
$options array | callable The options
$requirements array optional The requirements
return Scalr\Api\Rest\Routing\Route Returns route instance

patch() public method

Adds patch route
public patch ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route
$path string The path pattern of the route
$options array | callable The options
$requirements array optional The requirements
return Scalr\Api\Rest\Routing\Route Returns route instance

post() public method

Adds post route
public post ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route
$path string The path pattern of the route
$options array | callable The options
$requirements array optional The requirements
return Scalr\Api\Rest\Routing\Route Returns route instance

put() public method

Adds put route
public put ( string $path, array | callable $options, array $requirements = [] ) : Scalr\Api\Rest\Routing\Route
$path string The path pattern of the route
$options array | callable The options
$requirements array optional The requirements
return Scalr\Api\Rest\Routing\Route Returns route instance

redirect() public method

Redirects to the specified url
public redirect ( string $url, number $status = 302 )
$url string The URL
$status number optional The HTTP response status code

redirectTo() public method

Redirects to the specified named route
public redirectTo ( string $route, array $params = [], number $status = 302 )
$route string The name of the Route
$params array optional The list of the parameters
$status number optional The HTTP response status code.

run() public method

Runs application
public run ( )

stop() public method

Stops application
public stop ( )

Property Details

$pathPreprocessor protected property

Preprocess request method and path
protected callable $pathPreprocessor
return callable

$startTime public property

API Application start time
public float $startTime
return float