PHP Class Phlyty\App

Afficher le fichier Open project: phly/phlyty Class Usage Examples

Protected Properties

Свойство 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

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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
Résultat Route

event() public méthode

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

events() public méthode

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

flash() public méthode

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
Résultat App | array

get() public méthode

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
Résultat Route

getFlashMessenger() public méthode

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

getLog() public méthode

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

halt() public méthode

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
Résultat void

map() public méthode

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
Résultat Route

options() public méthode

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
Résultat Route

params() public méthode

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

pass() public méthode

Pass execution on to next matching route
public pass ( )

patch() public méthode

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
Résultat Route

post() public méthode

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
Résultat Route

prepareRoutes() protected méthode

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

put() public méthode

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
Résultat Route

redirect() public méthode

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
Résultat void

registerNamedRoute() protected méthode

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

registerRouteListener() protected méthode

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

registerRouteMethods() protected méthode

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

render() public méthode

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
Résultat App

request() public méthode

Retrieve the request environment
public request ( ) : Zend\Http\PhpEnvironment\Request
Résultat Zend\Http\PhpEnvironment\Request

response() public méthode

Retrieve the response environment
public response ( ) : Zend\Http\PhpEnvironment\Response
Résultat Zend\Http\PhpEnvironment\Response

route() protected méthode

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
Résultat mixed The last handler return value

run() public méthode

Run the application
public run ( )

setEventManager() public méthode

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

setFlashMessenger() public méthode

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

setLog() public méthode

Set logger
public setLog ( Zend\Log\Logger $log ) : App
$log Zend\Log\Logger
Résultat App

setRequest() public méthode

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

setResponse() public méthode

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

setView() public méthode

Set view object
public setView ( Phlyty\View\ViewInterface $view ) : App
$view Phlyty\View\ViewInterface
Résultat App

setViewModelPrototype() public méthode

Set view model prototype object
public setViewModelPrototype ( object $model ) : App
$model object
Résultat App

stop() public méthode

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

trigger() public méthode

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

urlFor() public méthode

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
Résultat string

view() public méthode

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

viewModel() public méthode

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
Résultat object

Property Details

$events protected_oe property

Event manager instance
protected EventManagerInterface,Zend\EventManager $events
Résultat Zend\EventManager\EventManagerInterface

$flashMessenger protected_oe property

Flash messenger instance
protected FlashMessenger,Zend\Mvc\Controller\Plugin $flashMessenger
Résultat Zend\Mvc\Controller\Plugin\FlashMessenger

$log protected_oe property

By default, has no writers attached
protected Logger,Zend\Log $log
Résultat Zend\Log\Logger

$namedRoutes protected_oe property

Named routes - used to generate URLs
protected array $namedRoutes
Résultat array

$params protected_oe property

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

$request protected_oe property

Request environment
protected Request,Zend\Http\PhpEnvironment $request
Résultat Zend\Http\PhpEnvironment\Request

$response protected_oe property

Response environment
protected Response,Zend\Http\PhpEnvironment $response
Résultat Zend\Http\PhpEnvironment\Response

$routeIndex protected_oe property

Index of route that matched
protected null|int $routeIndex
Résultat null | integer

$routeListenerRegistered protected_oe property

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

$routes protected_oe property

Routes
protected Route[],phlyty $routes
Résultat Route[]

$routesByMethod protected_oe property

Array of method => Route[] pairs
protected array $routesByMethod
Résultat array

$view protected_oe property

View
protected ViewInterface,Phlyty\View $view
Résultat Phlyty\View\ViewInterface

$viewModelPrototype protected_oe property

Prototype object for view models
protected object $viewModelPrototype
Résultat object