ServiceProvider

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

package Klein

 Methods

Constructor

__construct(\Klein\Request $request, \Klein\Response $response) 
access public

Parameters

$request

\Klein\Request

Object containing all HTTP request data and behaviors

$response

\Klein\Response

Object containing all HTTP response data and behaviors

Magic "__get" method

__get(string $key) : string

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

access public

Parameters

$key

string

The name of the shared data

Returns

string

Magic "__isset" method

__isset(string $key) : boolean

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

access public

Parameters

$key

string

The name of the shared data

Returns

boolean

Magic "__set" method

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

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

access public

Parameters

$key

string

The name of the shared data

$value

mixed

The value of the shared data

Magic "__unset" method

__unset(string $key) : void

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

access public

Parameters

$key

string

The name of the shared data

Add a custom validator for our validation method

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

Parameters

$method

string

The name of the validator method

$callback

callable

The callback to perform on validation

Redirects the request back to the referrer

back() : \Klein\ServiceProvider
access public

Returns

Bind object instances to this service

bind(\Klein\Request $request, \Klein\Response $response) : \Klein\ServiceProvider
access public

Parameters

$request

\Klein\Request

Object containing all HTTP request data and behaviors

$response

\Klein\Response

Object containing all HTTP response data and behaviors

Returns

Escapes a string

escape(string $str) : void
Static
static
access public

Parameters

$str

string

The string to escape

Stores a flash message of $type

flash(string $msg, string $type, array $params) : void
access public

Parameters

$msg

string

The message to flash

$type

string

The flash message type

$params

array

Optional params to be parsed by markdown

Returns and clears all flashes of optional $type

flashes(string $type) : array
access public

Parameters

$type

string

The name of the flash message type

Returns

array

Get (or set) the view's layout

layout(string $layout) : string | \Klein\ServiceProvider

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.

access public

Parameters

$layout

string

The layout of the view

Returns

Render a text string as markdown

markdown(string $str, array $args) : string
Static

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)

static
access public

Parameters

$str

string

The text string to parse

$args

array

Optional arguments to be parsed by markdown

Returns

string

Renders a view without a layout

partial(string $view, array $data) : void
access public

Parameters

$view

string

The view to render

$data

array

The data to render in the view

Redirects the request to the current URL

refresh() : \Klein\ServiceProvider
access public

Returns

Renders a view + optional layout

render(string $view, array $data) : void
access public

Parameters

$view

string

The view to render

$data

array

The data to render in the view

Returns the shared data collection object

sharedData() : \Klein\DataCollection\DataCollection
access public

Returns

Get the current session's ID

startSession() : string | false

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

access public

Returns

stringfalse

Start a validator chain for the specified string

validate(string $string, string $err) : \Klein\Validator
access public

Parameters

$string

string

The string to validate

$err

string

The custom exception message to throw

Returns

Start a validator chain for the specified parameter

validateParam(string $param, string $err) : \Klein\Validator
access public

Parameters

$param

string

The name of the parameter to validate

$err

string

The custom exception message to throw

Returns

Renders the current view

yieldView() : void
access public

 Properties

 

$layout : string
access protected
 

$request : \Klein\Request
access protected
 

$response : \Klein\Response
access protected
 

$session_id : string
access protected
 

$shared_data : \Klein\DataCollection\DataCollection
access protected
 

$view : string
access protected