\app\framework\Component\Route\KleinServiceProvider

ServiceProvider

Service provider class for handling logic extending between a request's data and a response's behavior

Summary

Methods
Properties
Constants
__construct()
bind()
sharedData()
startSession()
flash()
flashes()
markdown()
escape()
refresh()
back()
layout()
yieldView()
render()
partial()
addValidator()
validate()
validateParam()
__isset()
__get()
__set()
__unset()
No public properties found
No constants found
No protected methods found
$request
$response
$session_id
$layout
$view
$shared_data
N/A
No private methods found
No private properties found
N/A

Properties

$request

$request : 

The Request instance containing HTTP request data and behaviors

Type

$response

$response : 

The Response instance containing HTTP response data and behaviors

Type

$session_id

$session_id : 

The id of the current PHP session

Type

$layout

$layout : 

The view layout

Type

$view

$view : 

The view to render

Type

$shared_data

$shared_data : 

Shared data collection

Type

Methods

bind()

bind(\app\framework\Component\Route\Klein\Request  $request = null, \app\framework\Component\Route\Klein\AbstractResponse  $response = null) : \app\framework\Component\Route\Klein\ServiceProvider

Bind object instances to this service

Parameters

\app\framework\Component\Route\Klein\Request $request

Object containing all HTTP request data and behaviors

\app\framework\Component\Route\Klein\AbstractResponse $response

Object containing all HTTP response data and behaviors

Returns

\app\framework\Component\Route\Klein\ServiceProvider

startSession()

startSession() : string|false

Get the current session's ID

This will start a session if the current session id is null

Returns

string|false

flash()

flash(string  $msg, string  $type = 'info', array  $params = null) : void

Stores a flash message of $type

Parameters

string $msg

The message to flash

string $type

The flash message type

array $params

Optional params to be parsed by markdown

flashes()

flashes(string  $type = null) : array

Returns and clears all flashes of optional $type

Parameters

string $type

The name of the flash message type

Returns

array

markdown()

markdown(string  $str, array  $args = null) : string

Render a text string as markdown

Supports basic markdown syntax

Also, this method takes in EITHER an array of optional arguments (as the second parameter) ... OR this method will simply take a variable number of arguments (after the initial str arg)

Parameters

string $str

The text string to parse

array $args

Optional arguments to be parsed by markdown

Returns

string

escape()

escape(string  $str, integer  $flags = ENT_QUOTES) : string

Escapes a string for UTF-8 HTML displaying

This is a quick macro for escaping strings designed to be shown in a UTF-8 HTML environment. Its options are otherwise limited by design

Parameters

string $str

The string to escape

integer $flags

A bitmask of htmlentities() compatible flags

Returns

string

layout()

layout(string  $layout = null) : string|\app\framework\Component\Route\Klein\ServiceProvider

Get (or set) the view's layout

Simply calling this method without any arguments returns the current layout. Calling with an argument, however, sets the layout to what was provided by the argument.

Parameters

string $layout

The layout of the view

Returns

string|\app\framework\Component\Route\Klein\ServiceProvider

yieldView()

yieldView() : void

Renders the current view

render()

render(string  $view, array  $data = array()) : void

Renders a view + optional layout

Parameters

string $view

The view to render

array $data

The data to render in the view

partial()

partial(string  $view, array  $data = array()) : void

Renders a view without a layout

Parameters

string $view

The view to render

array $data

The data to render in the view

addValidator()

addValidator(string  $method, callable  $callback) : void

Add a custom validator for our validation method

Parameters

string $method

The name of the validator method

callable $callback

The callback to perform on validation

validate()

validate(string  $string, string  $err = null) : \app\framework\Component\Route\Klein\Validator

Start a validator chain for the specified string

Parameters

string $string

The string to validate

string $err

The custom exception message to throw

Returns

\app\framework\Component\Route\Klein\Validator

validateParam()

validateParam(string  $param, string  $err = null) : \app\framework\Component\Route\Klein\Validator

Start a validator chain for the specified parameter

Parameters

string $param

The name of the parameter to validate

string $err

The custom exception message to throw

Returns

\app\framework\Component\Route\Klein\Validator

__isset()

__isset(string  $key) : boolean

Magic "__isset" method

Allows the ability to arbitrarily check the existence of shared data from this instance while treating it as an instance property

Parameters

string $key

The name of the shared data

Returns

boolean

__get()

__get(string  $key) : string

Magic "__get" method

Allows the ability to arbitrarily request shared data from this instance while treating it as an instance property

Parameters

string $key

The name of the shared data

Returns

string

__set()

__set(string  $key, mixed  $value) : void

Magic "__set" method

Allows the ability to arbitrarily set shared data from this instance while treating it as an instance property

Parameters

string $key

The name of the shared data

mixed $value

The value of the shared data

__unset()

__unset(string  $key) : void

Magic "__unset" method

Allows the ability to arbitrarily remove shared data from this instance while treating it as an instance property

Parameters

string $key

The name of the shared data