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.

package Default

 Methods

Constructor

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

Parameters

$configuration

mixed

$serviceManager

\Zend\ServiceManager\ServiceManager

Bootstrap the application

bootstrap(array $listeners = array()) : \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.

Parameters

$listeners

array

List of listeners to attach.

Returns

\Zend\Mvc\Application

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

\Zend\EventManager\EventManagerInterface

Get the MVC event instance

getMvcEvent() : \Zend\Mvc\MvcEvent

Returns

\Zend\Mvc\MvcEvent

Get the request object

getRequest() : \Zend\Stdlib\RequestInterface
inherited_from \Zend\Mvc\ApplicationInterface::getRequest()

Returns

\Zend\Stdlib\RequestInterface

Get the response object

getResponse() : \Zend\Stdlib\ResponseInterface
inherited_from \Zend\Mvc\ApplicationInterface::getResponse()

Returns

\Zend\Stdlib\ResponseInterface

Retrieve the service manager

getServiceManager() : \Zend\ServiceManager\ServiceManager
inherited_from \Zend\Mvc\ApplicationInterface::getServiceManager()

Returns

\Zend\ServiceManager\ServiceManager

Static method for quick and easy initialization of the Application.

init(array $configuration = array()) : \Zend\Mvc\Application
Static

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

\Zend\Mvc\Application

Run the application

run() : \Zend\Mvc\Application
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.
inherited_from \Zend\Mvc\ApplicationInterface::run()
fluent This method is part of a fluent interface and will return the same instance

Returns

\Zend\Mvc\Application

send()

send() 
deprecated

Set the event manager instance

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

Parameters

$eventManager

\Zend\EventManager\EventManagerInterface

Returns

\Zend\Mvc\Application

Complete the request

completeRequest(\Zend\Mvc\MvcEvent $event) : \Zend\Mvc\Application

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

Parameters

$event

\Zend\Mvc\MvcEvent

Returns

\Zend\Mvc\Application

 Properties

 

$configuration

$configuration : array

Default

null
 

Default application event listeners

$defaultListeners : array

Default

array('RouteListener', 'DispatchListener', 'HttpMethodListener', 'ViewManager', 'SendResponseListener')
 

MVC event token

$event : \Zend\Mvc\MvcEvent

Default

 

$events

$events : \Zend\EventManager\EventManagerInterface

Default

 

$request

$request : \Zend\Stdlib\RequestInterface

Default

 

$response

$response : \Zend\Stdlib\ResponseInterface

Default

 

$serviceManager

$serviceManager : \Zend\ServiceManager\ServiceManager

Default

null

 Constants

 

ERROR_CONTROLLER_CANNOT_DISPATCH

ERROR_CONTROLLER_CANNOT_DISPATCH = 'error-controller-cannot-dispatch' 
 

ERROR_CONTROLLER_INVALID

ERROR_CONTROLLER_INVALID = 'error-controller-invalid' 
 

ERROR_CONTROLLER_NOT_FOUND

ERROR_CONTROLLER_NOT_FOUND = 'error-controller-not-found' 
 

ERROR_EXCEPTION

ERROR_EXCEPTION = 'error-exception' 
 

ERROR_ROUTER_NO_MATCH

ERROR_ROUTER_NO_MATCH = 'error-router-no-match'