Main application class for invoking applications

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

  • EventManager
  • ModuleManager
  • Request
  • Response
  • RouteListener
  • Router
  • DispatchListener
  • ViewManager

The most common workflow is:

$services = new Zend\ServiceManager\ServiceManager($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.

category Zend
package Zend_Mvc

 Methods

Constructor

__construct(mixed $configuration, \Zend\ServiceManager\ServiceManager $serviceManager) 

Parameters

$configuration

mixed

Bootstrap the application

bootstrap() : \Zend\Mvc\Application

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

Returns

Retrieve the application configuration

getConfig() : array | object

Returns

arrayobject

Retrieve the event manager

getEventManager() : \Zend\EventManager\EventManagerInterface

Lazy-loads an EventManager instance if none registered.

Returns

Get the MVC event instance

getMvcEvent() : \Zend\Mvc\MvcEvent

Get the request object

getRequest() : \Zend\Stdlib\RequestInterface

Get the response object

getResponse() : \Zend\Stdlib\ResponseInterface

Retrieve the service manager

getServiceManager() : \Zend\ServiceManager\ServiceManager

Static method for quick and easy initialization of the Application.

init(array $configuration) : \Zend\Mvc\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:

  • ModuleManager
  • SharedEventManager
  • EventManager & Zend\EventManager\EventManagerInterface

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

Parameters

$configuration

array

Returns

Run the application

run() : \Zend\Stdlib\ResponseInterface

triggers route(MvcEvent) Routes the request, and sets the RouteMatch object in the event.
triggers dispatch(MvcEvent) Dispatches a request, using the discovered RouteMatch and provided request.
triggers 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

Set the event manager instance

setEventManager(\Zend\EventManager\EventManagerInterface $eventManager) : \Zend\Mvc\Application

Complete the request

completeRequest(\Zend\Mvc\MvcEvent $event) : \Zend\Stdlib\ResponseInterface

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

Parameters

Returns

 Properties

 

$configuration

$configuration : array

 

MVC event token

$event : \Zend\Mvc\MvcEvent

   

$request

$request : \Zend\Stdlib\RequestInterface

 

$response

$response : \Zend\Stdlib\ResponseInterface

 

$serviceManager

$serviceManager : \Zend\ServiceManager\ServiceManager

 Constants

 

ERROR_CONTROLLER_CANNOT_DISPATCH

ERROR_CONTROLLER_CANNOT_DISPATCH 

 

ERROR_CONTROLLER_INVALID

ERROR_CONTROLLER_INVALID 

 

ERROR_CONTROLLER_NOT_FOUND

ERROR_CONTROLLER_NOT_FOUND 

 

ERROR_EXCEPTION

ERROR_EXCEPTION 

 

ERROR_ROUTER_NO_MATCH

ERROR_ROUTER_NO_MATCH