Zend Framework  3.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Application Class Reference

Main application class for invoking applications. More...

Public Member Functions

 __construct (ServiceManager $serviceManager, EventManagerInterface $events=null, RequestInterface $request=null, ResponseInterface $response=null)
 Constructor.
 
 getConfig ()
 Retrieve the application configuration.
 
 bootstrap (array $listeners=[])
 Bootstrap the application.
 
 getServiceManager ()
 Retrieve the service manager.
 
 getRequest ()
 Get the request object.
 
 getResponse ()
 Get the response object.
 
 getMvcEvent ()
 Get the MVC event instance.
 
 setEventManager (EventManagerInterface $eventManager)
 Set the event manager instance.
 
 getEventManager ()
 Retrieve the event manager.
 
 run ()
 Run the application.
 

Static Public Member Functions

static init ($configuration=[])
 Static method for quick and easy initialization of the Application.
 

Public Attributes

const ERROR_CONTROLLER_CANNOT_DISPATCH = 'error-controller-cannot-dispatch'
 
const ERROR_CONTROLLER_NOT_FOUND = 'error-controller-not-found'
 
const ERROR_CONTROLLER_INVALID = 'error-controller-invalid'
 
const ERROR_EXCEPTION = 'error-exception'
 
const ERROR_ROUTER_NO_MATCH = 'error-router-no-match'
 
const ERROR_MIDDLEWARE_CANNOT_DISPATCH = 'error-middleware-cannot-dispatch'
 

Protected Member Functions

 completeRequest (MvcEvent $event)
 Complete the request.
 

Protected Attributes

 $defaultListeners
 
 $event
 
 $events
 
 $request
 
 $response
 
 $serviceManager = null
 

Detailed Description

Main application class for invoking applications.

Expects the user will provide a configured ServiceManager, configured with the following services:

The most common workflow is: $services = new Zend($servicesConfig); $app = new Application($appConfig, $services); $app->bootstrap(); $response = $app->run(); $response->send();

bootstrap() opts in to the default route, dispatch, and view listeners, sets up the MvcEvent, and triggers the bootstrap event. This can be omitted if you wish to setup your own listeners and/or workflow; alternately, you can simply extend the class to override such behavior.

Constructor & Destructor Documentation

__construct ( ServiceManager  $serviceManager,
EventManagerInterface  $events = null,
RequestInterface  $request = null,
ResponseInterface  $response = null 
)

Constructor.

Parameters
ServiceManager$serviceManager
null | EventManagerInterface$events
null | RequestInterface$request
null | ResponseInterface$response

Member Function Documentation

bootstrap ( array  $listeners = [])

Bootstrap the application.

Defines and binds the MvcEvent, and passes it the request, response, and router. Attaches the ViewManager as a listener. Triggers the bootstrap event.

Parameters
array$listenersList of listeners to attach.
Returns
Application
completeRequest ( MvcEvent  $event)
protected

Complete the request.

Triggers "render" and "finish" events, and returns response from event object.

Parameters
MvcEvent$event
Returns
Application
getConfig ( )

Retrieve the application configuration.

Returns
array|object
getEventManager ( )

Retrieve the event manager.

Lazy-loads an EventManager instance if none registered.

Returns
EventManagerInterface

Implements EventsCapableInterface.

getMvcEvent ( )

Get the MVC event instance.

Returns
MvcEvent
getRequest ( )

Get the request object.

Returns

Implements ApplicationInterface.

getResponse ( )

Get the response object.

Returns
ResponseInterface

Implements ApplicationInterface.

getServiceManager ( )

Retrieve the service manager.

Returns
ServiceManager

Implements ApplicationInterface.

static init (   $configuration = [])
static

Static method for quick and easy initialization of the Application.

If you use this init() method, you cannot specify a service with the name of 'ApplicationConfig' in your service manager config. This name is reserved to hold the array from application.config.php.

The following services can only be overridden from application.config.php:

All other services are configured after module loading, thus can be overridden by modules.

Parameters
array$configuration
Returns
Application
run ( )

Run the application.

route(MvcEvent) Routes the request, and sets the RouteMatch object in the event. dispatch(MvcEvent) Dispatches a request, using the discovered RouteMatch and provided request. dispatch.error(MvcEvent) On errors (controller not found, action not supported, etc.), populates the event with information about the error type, discovered controller, and controller class (if known). Typically, a handler should return a populated Response object that can be returned immediately.

Returns
self

Implements ApplicationInterface.

setEventManager ( EventManagerInterface  $eventManager)

Set the event manager instance.

Parameters
EventManagerInterface$eventManager
Returns
Application

Implements EventManagerAwareInterface.

Member Data Documentation

$defaultListeners
protected
Initial value:
= [
'RouteListener',
'MiddlewareListener',
'DispatchListener',
'HttpMethodListener',
'ViewManager',
'SendResponseListener',
]
$event
protected
$events
protected
$request
protected
$response
protected
$serviceManager = null
protected
const ERROR_CONTROLLER_CANNOT_DISPATCH = 'error-controller-cannot-dispatch'
const ERROR_CONTROLLER_INVALID = 'error-controller-invalid'
const ERROR_CONTROLLER_NOT_FOUND = 'error-controller-not-found'
const ERROR_EXCEPTION = 'error-exception'
const ERROR_MIDDLEWARE_CANNOT_DISPATCH = 'error-middleware-cannot-dispatch'
const ERROR_ROUTER_NO_MATCH = 'error-router-no-match'