PHP Class Ham

ファイルを表示 Open project: radiosilence/ham Class Usage Examples

Public Properties

Property Type Description
$cache
$config
$layout
$logger
$name
$parent
$prefix
$routes
$template_paths

Public Methods

Method Description
__construct ( string $name = 'default', mixed $cache = False, boolean $log = False ) Create a Ham application.
__invoke ( mixed | boolean $app = False ) : mixed | string Invoke method allows the application to be mounted as a closure.
_abort ( integer $code, string $message = '', Ham $app = null ) : string static version of abort to allow for calling of abort by class
abort ( integer $code, string $message = '' ) : string application specific Cancel method
config_from_env ( $var ) Allows configuration file to be specified by environment variable, to make deployment easy.
config_from_file ( $filename ) Configure an application object from a file.
create_cache ( $prefix, $dummy = False, $redisFirst = False ) Cache factory, be it XCache or APC.
create_logger ( $log_file ) Logger factory; just FileLogger for now.
json ( $obj, $code = 200 )
onError ( $closure_callback, $logMessage = NULL ) Exists only as a function to fill as a setter for A developer to add custom 404 pages If a log message is set, it will append the error functio to the developer-defined one.
partial ( $view, $data = null )
render ( $view, $data = null, $layout = null ) Returns the contents of a template, populated with the data given to it.
route ( $uri, $callback, array $request_methods = ['GET'] ) : boolean Add routes
run ( ) Calls route and outputs it to STDOUT

Protected Methods

Method Description
_compile_route ( $uri, $wildcard ) Takes a route in simple syntax and makes it into a regular expression.
_escape_route_uri ( $uri )
_find_route ( $path )
_get_compiled_routes ( )
_get_template_path ( $name )
_route ( $request_uri ) Makes sure the routes are compiled then scans through them and calls whichever one is approprate.
page_not_found ( ) Called upon when 404 is deduced to be the only outcome

Method Details

__construct() public method

Create a Ham application.
public __construct ( string $name = 'default', mixed $cache = False, boolean $log = False )
$name string a canonical name for this app. Must not be shared between apps or cache collisions will happen. Unless you want that.
$cache mixed
$log boolean

__invoke() public method

Invoke method allows the application to be mounted as a closure.
public __invoke ( mixed | boolean $app = False ) : mixed | string
$app mixed | boolean parent application that can be referenced by $app->parent
return mixed | string

_abort() public static method

static version of abort to allow for calling of abort by class
public static _abort ( integer $code, string $message = '', Ham $app = null ) : string
$code integer
$message string
$app Ham
return string

_compile_route() protected method

Takes a route in simple syntax and makes it into a regular expression.
protected _compile_route ( $uri, $wildcard )

_escape_route_uri() protected method

protected _escape_route_uri ( $uri )

_find_route() protected method

protected _find_route ( $path )

_get_compiled_routes() protected method

protected _get_compiled_routes ( )

_get_template_path() protected method

protected _get_template_path ( $name )

_route() protected method

Makes sure the routes are compiled then scans through them and calls whichever one is approprate.
protected _route ( $request_uri )

abort() public method

application specific Cancel method
public abort ( integer $code, string $message = '' ) : string
$code integer
$message string
return string

config_from_env() public method

Allows configuration file to be specified by environment variable, to make deployment easy.
public config_from_env ( $var )

config_from_file() public method

Configure an application object from a file.
public config_from_file ( $filename )

create_cache() public static method

Cache factory, be it XCache or APC.
public static create_cache ( $prefix, $dummy = False, $redisFirst = False )

create_logger() public static method

Logger factory; just FileLogger for now.
public static create_logger ( $log_file )

json() public method

public json ( $obj, $code = 200 )

onError() public method

Exists only as a function to fill as a setter for A developer to add custom 404 pages If a log message is set, it will append the error functio to the developer-defined one.
public onError ( $closure_callback, $logMessage = NULL )

page_not_found() protected method

Called upon when 404 is deduced to be the only outcome
protected page_not_found ( )

partial() public method

public partial ( $view, $data = null )

render() public method

Returns the contents of a template, populated with the data given to it.
public render ( $view, $data = null, $layout = null )

route() public method

Add routes
public route ( $uri, $callback, array $request_methods = ['GET'] ) : boolean
$uri
$callback
$request_methods array
return boolean

run() public method

Calls route and outputs it to STDOUT
public run ( )

Property Details

$cache public_oe property

public $cache

$config public_oe property

public $config

$layout public_oe property

public $layout

$logger public_oe property

public $logger

$name public_oe property

public $name

$parent public_oe property

public $parent

$prefix public_oe property

public $prefix

$routes public_oe property

public $routes

$template_paths public_oe property

public $template_paths