3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
12 use Zend\EventManager\Event
;
13 use Zend\Stdlib\RequestInterface
as Request
;
14 use Zend\Stdlib\ResponseInterface
as Response
;
15 use Zend\View\Model\ModelInterface
as Model
;
16 use Zend\View\Model\ViewModel
;
18 class MvcEvent
extends Event
21 * Mvc events triggered by eventmanager
23 const EVENT_BOOTSTRAP
= 'bootstrap';
24 const EVENT_DISPATCH
= 'dispatch';
25 const EVENT_DISPATCH_ERROR
= 'dispatch.error';
26 const EVENT_FINISH
= 'finish';
27 const EVENT_RENDER
= 'render';
28 const EVENT_RENDER_ERROR
= 'render.error';
29 const EVENT_ROUTE
= 'route';
32 protected $application;
50 * @var Router\RouteStackInterface
55 * @var Router\RouteMatch
57 protected $routeMatch;
65 * Set application instance
67 * @param ApplicationInterface $application
70 public function setApplication(ApplicationInterface
$application)
72 $this->setParam('application', $application);
73 $this->application
= $application;
78 * Get application instance
80 * @return ApplicationInterface
82 public function getApplication()
84 return $this->application
;
90 * @return Router\RouteStackInterface
92 public function getRouter()
100 * @param Router\RouteStackInterface $router
103 public function setRouter(Router\RouteStackInterface
$router)
105 $this->setParam('router', $router);
106 $this->router
= $router;
113 * @return Router\RouteMatch
115 public function getRouteMatch()
117 return $this->routeMatch
;
123 * @param Router\RouteMatch $matches
126 public function setRouteMatch(Router\RouteMatch
$matches)
128 $this->setParam('route-match', $matches);
129 $this->routeMatch
= $matches;
138 public function getRequest()
140 return $this->request
;
146 * @param Request $request
149 public function setRequest(Request
$request)
151 $this->setParam('request', $request);
152 $this->request
= $request;
161 public function getResponse()
163 return $this->response
;
169 * @param Response $response
172 public function setResponse(Response
$response)
174 $this->setParam('response', $response);
175 $this->response
= $response;
182 * @param Model $viewModel
185 public function setViewModel(Model
$viewModel)
187 $this->viewModel
= $viewModel;
196 public function getViewModel()
198 if (null === $this->viewModel
) {
199 $this->setViewModel(new ViewModel());
201 return $this->viewModel
;
209 public function getResult()
211 return $this->result
;
217 * @param mixed $result
220 public function setResult($result)
222 $this->setParam('__RESULT__', $result);
223 $this->result
= $result;
228 * Does the event represent an error response?
232 public function isError()
234 return (bool) $this->getParam('error', false);
238 * Set the error message (indicating error in handling request)
240 * @param string $message
243 public function setError($message)
245 $this->setParam('error', $message);
250 * Retrieve the error message, if any
254 public function getError()
256 return $this->getParam('error', '');
260 * Get the currently registered controller name
264 public function getController()
266 return $this->getParam('controller');
270 * Set controller name
272 * @param string $name
275 public function setController($name)
277 $this->setParam('controller', $name);
282 * Get controller class
286 public function getControllerClass()
288 return $this->getParam('controller-class');
292 * Set controller class
294 * @param string $class
297 public function setControllerClass($class)
299 $this->setParam('controller-class', $class);