PHP Class flight\Engine

It is responsible for loading an HTTP request, running the assigned services, and generating an HTTP response.
Datei anzeigen Open project: mikecao/flight Class Usage Examples

Protected Properties

Property Type Description
$dispatcher object Event dispatcher.
$loader object Class loader.
$vars array Stored variables.

Public Methods

Method Description
__call ( string $name, array $params ) : mixed Handles calls to class methods.
__construct ( ) Constructor.
_error ( object $e ) Sends an HTTP 500 response for any errors.
_etag ( string $id, string $type = 'strong' ) Handles ETag HTTP caching.
_halt ( integer $code = 200, string $message = '' ) Stops processing and returns a given response.
_json ( mixed $data, integer $code = 200, boolean $encode = true, string $charset = 'utf-8', integer $option ) Sends a JSON response.
_jsonp ( mixed $data, string $param = 'jsonp', integer $code = 200, boolean $encode = true, string $charset = 'utf-8', integer $option ) Sends a JSONP response.
_lastModified ( integer $time ) Handles last modified HTTP caching.
_notFound ( ) Sends an HTTP 404 response when a URL is not found.
_redirect ( string $url, integer $code = 303 ) Redirects the current request to another URL.
_render ( string $file, array $data = null, string $key = null ) Renders a template.
_route ( string $pattern, callback $callback, boolean $pass_route = false ) Routes a URL to a callback function.
_start ( ) Starts the framework.
_stop ( integer $code = 200 ) Stops the framework and outputs the current response.
after ( string $name, callback $callback ) Adds a post-filter to a method.
before ( string $name, callback $callback ) Adds a pre-filter to a method.
clear ( string $key = null ) Unsets a variable. If no key is passed in, clear all variables.
get ( string $key = null ) : mixed Gets a variable.
handleError ( integer $errno, integer $errstr, integer $errfile, integer $errline ) Custom error handler. Converts errors into exceptions.
handleErrors ( boolean $enabled ) Enables/disables custom error handling.
handleException ( object $e ) Custom exception handler. Logs exceptions.
has ( string $key ) : boolean Checks if a variable has been set.
init ( ) Initializes the framework.
map ( string $name, callback $callback ) Maps a callback to a framework method.
path ( string $dir ) Adds a path for class autoloading.
register ( string $name, string $class, array $params = [], callback $callback = null ) Registers a class to a framework method.
set ( mixed $key, string $value = null ) Sets a variable.

Method Details

__call() public method

Handles calls to class methods.
public __call ( string $name, array $params ) : mixed
$name string Method name
$params array Method parameters
return mixed Callback results

__construct() public method

Constructor.
public __construct ( )

_error() public method

Sends an HTTP 500 response for any errors.
public _error ( object $e )
$e object Thrown exception

_etag() public method

Handles ETag HTTP caching.
public _etag ( string $id, string $type = 'strong' )
$id string ETag identifier
$type string ETag type

_halt() public method

Stops processing and returns a given response.
public _halt ( integer $code = 200, string $message = '' )
$code integer HTTP status code
$message string Response message

_json() public method

Sends a JSON response.
public _json ( mixed $data, integer $code = 200, boolean $encode = true, string $charset = 'utf-8', integer $option )
$data mixed JSON data
$code integer HTTP status code
$encode boolean Whether to perform JSON encoding
$charset string Charset
$option integer Bitmask Json constant such as JSON_HEX_QUOT

_jsonp() public method

Sends a JSONP response.
public _jsonp ( mixed $data, string $param = 'jsonp', integer $code = 200, boolean $encode = true, string $charset = 'utf-8', integer $option )
$data mixed JSON data
$param string Query parameter that specifies the callback name.
$code integer HTTP status code
$encode boolean Whether to perform JSON encoding
$charset string Charset
$option integer Bitmask Json constant such as JSON_HEX_QUOT

_lastModified() public method

Handles last modified HTTP caching.
public _lastModified ( integer $time )
$time integer Unix timestamp

_notFound() public method

Sends an HTTP 404 response when a URL is not found.
public _notFound ( )

_redirect() public method

Redirects the current request to another URL.
public _redirect ( string $url, integer $code = 303 )
$url string URL
$code integer HTTP status code

_render() public method

Renders a template.
public _render ( string $file, array $data = null, string $key = null )
$file string Template file
$data array Template data
$key string View variable name

_route() public method

Routes a URL to a callback function.
public _route ( string $pattern, callback $callback, boolean $pass_route = false )
$pattern string URL pattern to match
$callback callback Callback function
$pass_route boolean Pass the matching route object to the callback

_start() public method

Starts the framework.
public _start ( )

_stop() public method

Stops the framework and outputs the current response.
public _stop ( integer $code = 200 )
$code integer HTTP status code

after() public method

Adds a post-filter to a method.
public after ( string $name, callback $callback )
$name string Method name
$callback callback Callback function

before() public method

Adds a pre-filter to a method.
public before ( string $name, callback $callback )
$name string Method name
$callback callback Callback function

clear() public method

Unsets a variable. If no key is passed in, clear all variables.
public clear ( string $key = null )
$key string Key

get() public method

Gets a variable.
public get ( string $key = null ) : mixed
$key string Key
return mixed

handleError() public method

Custom error handler. Converts errors into exceptions.
public handleError ( integer $errno, integer $errstr, integer $errfile, integer $errline )
$errno integer Error number
$errstr integer Error string
$errfile integer Error file name
$errline integer Error file line number

handleErrors() public method

Enables/disables custom error handling.
public handleErrors ( boolean $enabled )
$enabled boolean True or false

handleException() public method

Custom exception handler. Logs exceptions.
public handleException ( object $e )
$e object Thrown exception

has() public method

Checks if a variable has been set.
public has ( string $key ) : boolean
$key string Key
return boolean Variable status

init() public method

Initializes the framework.
public init ( )

map() public method

Maps a callback to a framework method.
public map ( string $name, callback $callback )
$name string Method name
$callback callback Callback function

path() public method

Adds a path for class autoloading.
public path ( string $dir )
$dir string Directory path

register() public method

Registers a class to a framework method.
public register ( string $name, string $class, array $params = [], callback $callback = null )
$name string Method name
$class string Class name
$params array Class initialization parameters
$callback callback Function to call after object instantiation

set() public method

Sets a variable.
public set ( mixed $key, string $value = null )
$key mixed Key
$value string Value

Property Details

$dispatcher protected_oe property

Event dispatcher.
protected object $dispatcher
return object

$loader protected_oe property

Class loader.
protected object $loader
return object

$vars protected_oe property

Stored variables.
protected array $vars
return array