PHP Class Phlyty\App

显示文件 Open project: phly/phlyty Class Usage Examples

Protected Properties

Property Type Description
$events Zend\EventManager\EventManagerInterface Event manager instance
$flashMessenger Zend\Mvc\Controller\Plugin\FlashMessenger Flash messenger instance
$log Zend\Log\Logger By default, has no writers attached
$namedRoutes array Named routes - used to generate URLs
$params null | Zend\Mvc\Router\RouteMatch Parameters returned as the result of a route match
$request Zend\Http\PhpEnvironment\Request Request environment
$response Zend\Http\PhpEnvironment\Response Response environment
$routeIndex null | integer Index of route that matched
$routeListenerRegistered boolean Whether or not we've already registered the route listener
$routes Route[] Routes
$routesByMethod array Array of method => Route[] pairs
$view Phlyty\View\ViewInterface View
$viewModelPrototype object Prototype object for view models

Public Methods

Method Description
delete ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route Add a route for a DELETE request
event ( ) : AppEvent Create and return an application event instance
events ( ) : Zend\EventManager\EventManagerInterface Retrieve event manager instance
flash ( string $name, null | string $message = null ) : App | array Create a flash message or retrieve the flash messages for a specific namespace
get ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route Add a route for a GET request
getFlashMessenger ( ) : Zend\Mvc\Controller\Plugin\FlashMessenger Get flash messenger instance
getLog ( ) : Zend\Log\Logger Retrieve logger
halt ( integer $status, string $message = '' ) : void Halt execution
map ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route Map a route to a callback
options ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route Add a route for a OPTIONS request
params ( ) : Zend\Mvc\Router\RouteMatch Return the route match parameters
pass ( ) Pass execution on to next matching route
patch ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route Add a route for a PATCH request
post ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route Add a route for a POST request
put ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route Add a route for a PUT request
redirect ( string | Zend\Uri\UriInterface $uri, integer $status = 302 ) : void Redirect
render ( string $template, array | object $viewModel = [] ) : App Render a template
request ( ) : Zend\Http\PhpEnvironment\Request Retrieve the request environment
response ( ) : Zend\Http\PhpEnvironment\Response Retrieve the response environment
run ( ) Run the application
setEventManager ( Zend\EventManager\EventManagerInterface $events ) : App Set the event manager instance
setFlashMessenger ( Zend\Mvc\Controller\Plugin\FlashMessenger $flashMessenger ) : App Set flash messenger instance
setLog ( Zend\Log\Logger $log ) : App Set logger
setRequest ( Zend\Http\PhpEnvironment\Request $request ) : App Set the request object instance
setResponse ( Zend\Http\PhpEnvironment\Response $response ) : App Set the response object instance
setView ( Phlyty\View\ViewInterface $view ) : App Set view object
setViewModelPrototype ( object $model ) : App Set view model prototype object
stop ( ) : void Stop execution
trigger ( string $name, array $params = [] ) : Zend\EventManager\ResponseCollection Trigger a named event
urlFor ( string $route = null, array $params = [], array $options = [] ) : string Generates a URL based on a named route
view ( ) : Phlyty\View\ViewInterface Retrieve view instance
viewModel ( ) : object Retrieve a view model instance

Protected Methods

Method Description
prepareRoutes ( ) Prepare routes
registerNamedRoute ( Route $route ) Register a named route
registerRouteListener ( ) Register the route listener with the route event
registerRouteMethods ( Route $route, integer $index ) Determine what methods a route responds to
route ( Zend\Http\PhpEnvironment\Request $request, string $method ) : mixed Route the request

Method Details

delete() public method

Add a route for a DELETE request
public delete ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route
$route string | Zend\Mvc\Router\RouteInterface
$controller callable
return Route

event() public method

Sets the target to the App object instance, and, if a route has been matched, adds it to the instance.
public event ( ) : AppEvent
return AppEvent

events() public method

If not present, lazy-loads and registers one.
public events ( ) : Zend\EventManager\EventManagerInterface
return Zend\EventManager\EventManagerInterface

flash() public method

Create a flash message or retrieve the flash messages for a specific namespace
public flash ( string $name, null | string $message = null ) : App | array
$name string
$message null | string
return App | array

get() public method

Add a route for a GET request
public get ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route
$route string | Zend\Mvc\Router\RouteInterface
$controller callable
return Route

getFlashMessenger() public method

Lazy instantiates one if none provided
public getFlashMessenger ( ) : Zend\Mvc\Controller\Plugin\FlashMessenger
return Zend\Mvc\Controller\Plugin\FlashMessenger

getLog() public method

Lazy instantiates one if none present.
public getLog ( ) : Zend\Log\Logger
return Zend\Log\Logger

halt() public method

Halts execution, and sets the response status code to $status, as well as sets the response body to the provided message (if any). Any previous content in the response body will be overwritten.
public halt ( integer $status, string $message = '' ) : void
$status integer HTTP response status
$message string HTTP response body
return void

map() public method

Map a route to a callback
public map ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route
$route string | Zend\Mvc\Router\RouteInterface
$controller callable
return Route

options() public method

Add a route for a OPTIONS request
public options ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route
$route string | Zend\Mvc\Router\RouteInterface
$controller callable
return Route

params() public method

If none has been set yet, lazy instantiates an empty Router\RouteMatch container.
public params ( ) : Zend\Mvc\Router\RouteMatch
return Zend\Mvc\Router\RouteMatch

pass() public method

Pass execution on to next matching route
public pass ( )

patch() public method

Add a route for a PATCH request
public patch ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route
$route string | Zend\Mvc\Router\RouteInterface
$controller callable
return Route

post() public method

Add a route for a POST request
public post ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route
$route string | Zend\Mvc\Router\RouteInterface
$controller callable
return Route

prepareRoutes() protected method

Ensure no duplicate routes, determine what named routes are available, and determine which routes respond to which methods.
protected prepareRoutes ( )

put() public method

Add a route for a PUT request
public put ( string | Zend\Mvc\Router\RouteInterface $route, callable $controller ) : Route
$route string | Zend\Mvc\Router\RouteInterface
$controller callable
return Route

redirect() public method

Stop execution, and redirect to the provided location.
public redirect ( string | Zend\Uri\UriInterface $uri, integer $status = 302 ) : void
$uri string | Zend\Uri\UriInterface
$status integer
return void

registerNamedRoute() protected method

Register a named route
protected registerNamedRoute ( Route $route )
$route Route

registerRouteListener() protected method

Register the route listener with the route event
protected registerRouteListener ( )

registerRouteMethods() protected method

Determine what methods a route responds to
protected registerRouteMethods ( Route $route, integer $index )
$route Route
$index integer

render() public method

Renders a template, with any view model provided, and injects the content into the response object.
public render ( string $template, array | object $viewModel = [] ) : App
$template string
$viewModel array | object
return App

request() public method

Retrieve the request environment
public request ( ) : Zend\Http\PhpEnvironment\Request
return Zend\Http\PhpEnvironment\Request

response() public method

Retrieve the response environment
public response ( ) : Zend\Http\PhpEnvironment\Response
return Zend\Http\PhpEnvironment\Response

route() protected method

Attempts to match a route. If matched, sets $params and $routeIndex. Otherwise, throws an Exception\PageNotFoundException.
protected route ( Zend\Http\PhpEnvironment\Request $request, string $method ) : mixed
$request Zend\Http\PhpEnvironment\Request
$method string
return mixed The last handler return value

run() public method

Run the application
public run ( )

setEventManager() public method

Set the event manager instance
public setEventManager ( Zend\EventManager\EventManagerInterface $events ) : App
$events Zend\EventManager\EventManagerInterface
return App

setFlashMessenger() public method

Set flash messenger instance
public setFlashMessenger ( Zend\Mvc\Controller\Plugin\FlashMessenger $flashMessenger ) : App
$flashMessenger Zend\Mvc\Controller\Plugin\FlashMessenger
return App

setLog() public method

Set logger
public setLog ( Zend\Log\Logger $log ) : App
$log Zend\Log\Logger
return App

setRequest() public method

Set the request object instance
public setRequest ( Zend\Http\PhpEnvironment\Request $request ) : App
$request Zend\Http\PhpEnvironment\Request
return App

setResponse() public method

Set the response object instance
public setResponse ( Zend\Http\PhpEnvironment\Response $response ) : App
$response Zend\Http\PhpEnvironment\Response
return App

setView() public method

Set view object
public setView ( Phlyty\View\ViewInterface $view ) : App
$view Phlyty\View\ViewInterface
return App

setViewModelPrototype() public method

Set view model prototype object
public setViewModelPrototype ( object $model ) : App
$model object
return App

stop() public method

Stops execution immediately, returning the response as it currently stands.
public stop ( ) : void
return void

trigger() public method

Allows optionally passing more params if desired.
public trigger ( string $name, array $params = [] ) : Zend\EventManager\ResponseCollection
$name string
$params array
return Zend\EventManager\ResponseCollection

urlFor() public method

Generates a URL based on a named route
public urlFor ( string $route = null, array $params = [], array $options = [] ) : string
$route string Named Route instance
$params array Parameters to use in url generation, if any
$options array Router\RouteInterface-specific options to use in url generation, if any
return string

view() public method

If none present, lazy-loads View\MustacheView instance.
public view ( ) : Phlyty\View\ViewInterface
return Phlyty\View\ViewInterface

viewModel() public method

Always returns a new view model instance, cloned from the instance in $viewModelPrototype. If no prototype exists, creates one from View\MustacheViewModel.
public viewModel ( ) : object
return object

Property Details

$events protected_oe property

Event manager instance
protected EventManagerInterface,Zend\EventManager $events
return Zend\EventManager\EventManagerInterface

$flashMessenger protected_oe property

Flash messenger instance
protected FlashMessenger,Zend\Mvc\Controller\Plugin $flashMessenger
return Zend\Mvc\Controller\Plugin\FlashMessenger

$log protected_oe property

By default, has no writers attached
protected Logger,Zend\Log $log
return Zend\Log\Logger

$namedRoutes protected_oe property

Named routes - used to generate URLs
protected array $namedRoutes
return array

$params protected_oe property

Parameters returned as the result of a route match
protected null|RouteMatch,Zend\Mvc\Router $params
return null | Zend\Mvc\Router\RouteMatch

$request protected_oe property

Request environment
protected Request,Zend\Http\PhpEnvironment $request
return Zend\Http\PhpEnvironment\Request

$response protected_oe property

Response environment
protected Response,Zend\Http\PhpEnvironment $response
return Zend\Http\PhpEnvironment\Response

$routeIndex protected_oe property

Index of route that matched
protected null|int $routeIndex
return null | integer

$routeListenerRegistered protected_oe property

Whether or not we've already registered the route listener
protected bool $routeListenerRegistered
return boolean

$routes protected_oe property

Routes
protected Route[],phlyty $routes
return Route[]

$routesByMethod protected_oe property

Array of method => Route[] pairs
protected array $routesByMethod
return array

$view protected_oe property

View
protected ViewInterface,Phlyty\View $view
return Phlyty\View\ViewInterface

$viewModelPrototype protected_oe property

Prototype object for view models
protected object $viewModelPrototype
return object