Permalink
Browse files

Used constants instead of string literals for mvc events

  • Loading branch information...
1 parent 647f23a commit 644af5958357fe85de0238d98d941a28c2141518 unknown committed Mar 22, 2012
@@ -104,8 +104,8 @@ public function setRouter(Router\RouteStack $router)
/**
* Set the MVC event instance
- *
- * @param MvcEvent $event
+ *
+ * @param MvcEvent $event
* @return Application
*/
public function setMvcEvent(MvcEvent $event)
@@ -165,7 +165,7 @@ public function getRouter()
/**
* Get the MVC event instance
- *
+ *
* @return MvcEvent
*/
public function getMvcEvent()
@@ -229,13 +229,13 @@ public function run()
}
return false;
};
-
+
// Trigger route event
- $result = $events->trigger('route', $event, $shortCircuit);
+ $result = $events->trigger(MvcEvent::EVENT_ROUTE, $event, $shortCircuit);
if ($result->stopped()) {
$response = $result->last();
if ($response instanceof Response) {
- $events->trigger('finish', $event);
+ $events->trigger(MvcEvent::EVENT_FINISH, $event);
return $response;
}
if ($event->getError()) {
@@ -248,12 +248,12 @@ public function run()
}
// Trigger dispatch event
- $result = $events->trigger('dispatch', $event, $shortCircuit);
+ $result = $events->trigger(MvcEvent::EVENT_DISPATCH, $event, $shortCircuit);
// Complete response
$response = $result->last();
if ($response instanceof Response) {
- $events->trigger('finish', $event);
+ $events->trigger(MvcEvent::EVENT_FINISH, $event);
return $response;
}
@@ -268,15 +268,15 @@ public function run()
*
* Triggers "render" and "finish" events, and returns response from
* event object.
- *
- * @param MvcEvent $event
+ *
+ * @param MvcEvent $event
* @return Response
*/
protected function completeRequest(MvcEvent $event)
{
$events = $this->events();
- $events->trigger('render', $event);
- $events->trigger('finish', $event);
+ $events->trigger(MvcEvent::EVENT_RENDER, $event);
+ $events->trigger(MvcEvent::EVENT_FINISH, $event);
return $event->getResponse();
}
@@ -296,7 +296,7 @@ public function route(MvcEvent $e)
if (!$routeMatch instanceof Router\RouteMatch) {
$e->setError(static::ERROR_CONTROLLER_NOT_FOUND);
- $results = $this->events()->trigger('dispatch.error', $e);
+ $results = $this->events()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $e);
if (count($results)) {
$return = $results->last();
} else {
@@ -336,7 +336,7 @@ public function dispatch(MvcEvent $e)
->setController($controllerName)
->setParam('exception', $exception);
- $results = $events->trigger('dispatch.error', $error);
+ $results = $events->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $error);
if (count($results)) {
$return = $results->last();
} else {
@@ -355,7 +355,7 @@ public function dispatch(MvcEvent $e)
->setController($controllerName)
->setControllerClass(get_class($controller));
- $results = $events->trigger('dispatch.error', $error);
+ $results = $events->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $error);
if (count($results)) {
$return = $results->last();
} else {
@@ -379,7 +379,7 @@ public function dispatch(MvcEvent $e)
->setController($controllerName)
->setControllerClass(get_class($controller))
->setParam('exception', $ex);
- $results = $events->trigger('dispatch.error', $error);
+ $results = $events->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $error);
if (count($results)) {
$return = $results->last();
} else {
@@ -407,7 +407,7 @@ public function dispatch(MvcEvent $e)
protected function attachDefaultListeners()
{
$events = $this->events();
- $events->attach('route', array($this, 'route'));
- $events->attach('dispatch', array($this, 'dispatch'));
+ $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'route'));
+ $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'dispatch'));
}
}
@@ -24,18 +24,18 @@ class Bootstrap implements Bootstrapper
/**
* Constructor
*
- * @param Config $config
+ * @param Config $config
* @return void
*/
public function __construct(Config $config)
{
- $this->config = $config;
+ $this->config = $config;
}
/**
* Set the event manager to use with this object
- *
- * @param Events $events
+ *
+ * @param Events $events
* @return void
*/
public function setEventManager(Events $events)
@@ -49,7 +49,7 @@ public function setEventManager(Events $events)
* If none is initialized, an EventManager instance will be created with
* the contexts of this class, the current class name (if extending this
* class), and "bootstrap".
- *
+ *
* @return Events
*/
public function events()
@@ -69,12 +69,12 @@ public function events()
*
* - Initializes the locator, and injects it in the application
* - Initializes the router, and injects it in the application
- * - Triggers the "bootstrap" event, passing in the application and modules
+ * - Triggers the "bootstrap" event, passing in the application and modules
* as parameters. This allows module classes to perform arbitrary
- * initialization tasks after bootstrapping but before running the
+ * initialization tasks after bootstrapping but before running the
* application.
- *
- * @param Application $application
+ *
+ * @param Application $application
* @return void
*/
public function bootstrap(AppContext $application)
@@ -88,8 +88,8 @@ public function bootstrap(AppContext $application)
/**
* Sets up the locator based on the configuration provided
- *
- * @param AppContext $application
+ *
+ * @param AppContext $application
* @return void
*/
protected function setupLocator(AppContext $application)
@@ -228,8 +228,8 @@ protected function setupLocator(AppContext $application)
/**
* Sets up the router based on the configuration provided
- *
- * @param Application $application
+ *
+ * @param Application $application
* @return void
*/
protected function setupRouter(AppContext $application)
@@ -241,11 +241,11 @@ protected function setupRouter(AppContext $application)
/**
* Sets up the view integration
*
- * Pulls the View object and PhpRenderer strategy from the locator, and
- * attaches the former to the latter. Then attaches the
+ * Pulls the View object and PhpRenderer strategy from the locator, and
+ * attaches the former to the latter. Then attaches the
* DefaultRenderingStrategy to the application event manager.
- *
- * @param Application $application
+ *
+ * @param Application $application
* @return void
*/
protected function setupView($application)
@@ -270,11 +270,11 @@ protected function setupView($application)
$createViewModelListener = $locator->get('Zend\Mvc\View\CreateViewModelListener');
$injectTemplateListener = $locator->get('Zend\Mvc\View\InjectTemplateListener');
$injectViewModelListener = $locator->get('Zend\Mvc\View\InjectViewModelListener');
- $staticEvents->attach('Zend\Stdlib\Dispatchable', 'dispatch', array($createViewModelListener, 'createViewModelFromArray'), -80);
- $staticEvents->attach('Zend\Stdlib\Dispatchable', 'dispatch', array($createViewModelListener, 'createViewModelFromNull'), -80);
- $staticEvents->attach('Zend\Stdlib\Dispatchable', 'dispatch', array($injectTemplateListener, 'injectTemplate'), -90);
- $events->attach('dispatch.error', array($injectViewModelListener, 'injectViewModel'), -100);
- $staticEvents->attach('Zend\Stdlib\Dispatchable', 'dispatch', array($injectViewModelListener, 'injectViewModel'), -100);
+ $staticEvents->attach('Zend\Stdlib\Dispatchable', MvcEvent::EVENT_DISPATCH, array($createViewModelListener, 'createViewModelFromArray'), -80);
+ $staticEvents->attach('Zend\Stdlib\Dispatchable', MvcEvent::EVENT_DISPATCH, array($createViewModelListener, 'createViewModelFromNull'), -80);
+ $staticEvents->attach('Zend\Stdlib\Dispatchable', MvcEvent::EVENT_DISPATCH, array($injectTemplateListener, 'injectTemplate'), -90);
+ $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($injectViewModelListener, 'injectViewModel'), -100);
+ $staticEvents->attach('Zend\Stdlib\Dispatchable', MvcEvent::EVENT_DISPATCH, array($injectViewModelListener, 'injectViewModel'), -100);
// Inject MVC Event with view model
$mvcEvent = $application->getMvcEvent();
@@ -292,8 +292,8 @@ protected function setupView($application)
*
* Triggers with the keys "application" and "config", the latter pointing
* to the Module Manager attached to the bootstrap.
- *
- * @param AppContext $application
+ *
+ * @param AppContext $application
* @return void
*/
protected function setupEvents(AppContext $application)
@@ -302,6 +302,6 @@ protected function setupEvents(AppContext $application)
'application' => $application,
'config' => $this->config,
);
- $this->events()->trigger('bootstrap', $this, $params);
+ $this->events()->trigger(MvcEvent::EVENT_BOOTSTRAP, $this, $params);
}
}
@@ -84,7 +84,7 @@ public function dispatch(Request $request, Response $response = null)
->setResponse($response)
->setTarget($this);
- $result = $this->events()->trigger('dispatch', $e, function($test) {
+ $result = $this->events()->trigger(MvcEvent::EVENT_DISPATCH, $e, function($test) {
return ($test instanceof Response);
});
@@ -282,9 +282,9 @@ public function plugin($name, array $options = null)
*
* If the plugin is a functor, call it, passing the parameters provided.
* Otherwise, return the plugin instance.
- *
- * @param string $method
- * @param array $params
+ *
+ * @param string $method
+ * @param array $params
* @return mixed
*/
public function __call($method, array $params)
@@ -304,7 +304,7 @@ public function __call($method, array $params)
protected function attachDefaultListeners()
{
$events = $this->events();
- $events->attach('dispatch', array($this, 'execute'));
+ $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'execute'));
}
/**
@@ -108,7 +108,7 @@ public function dispatch(Request $request, Response $response = null)
->setResponse($response)
->setTarget($this);
- $result = $this->events()->trigger('dispatch', $e, function($test) {
+ $result = $this->events()->trigger(MvcEvent::EVENT_DISPATCH, $e, function($test) {
return ($test instanceof Response);
});
if ($result->stopped()) {
@@ -346,9 +346,9 @@ public function plugin($name, array $options = null)
*
* If the plugin is a functor, call it, passing the parameters provided.
* Otherwise, return the plugin instance.
- *
- * @param string $method
- * @param array $params
+ *
+ * @param string $method
+ * @param array $params
* @return mixed
*/
public function __call($method, $params)
@@ -368,7 +368,7 @@ public function __call($method, $params)
protected function attachDefaultListeners()
{
$events = $this->events();
- $events->attach('dispatch', array($this, 'execute'));
+ $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'execute'));
}
/**
@@ -9,6 +9,19 @@
class MvcEvent extends Event
{
+ /**#@+
+ * Mvc events triggered by eventmanager
+ */
+ const EVENT_BOOTSTRAP = 'bootstrap';
+ const EVENT_DISPATCH = 'dispatch';
+ const EVENT_DISPATCH_ERROR = 'dispatch.error';
+ const EVENT_FINISH = 'finish';
+ const EVENT_RENDER = 'render';
+ const EVENT_RENDERER = 'renderer';
+ const EVENT_RESPONSE = 'response';
+ const EVENT_ROUTE = 'route';
+ /**#@-*/
+
protected $request;
protected $response;
protected $result;
@@ -75,7 +88,7 @@ public function setViewModel(ViewModel $viewModel)
$this->viewModel = $viewModel;
return $this;
}
-
+
/**
* Get value for viewModel
*
@@ -31,27 +31,27 @@ class CreateViewModelListener implements ListenerAggregate
{
/**
* Listeners we've registered
- *
+ *
* @var array
*/
protected $listeners = array();
/**
* Attach listeners
- *
- * @param Events $events
+ *
+ * @param Events $events
* @return void
*/
public function attach(Events $events)
{
- $this->listeners[] = $events->attach('dispatch', array($this, 'createViewModelFromArray'), -80);
- $this->listeners[] = $events->attach('dispatch', array($this, 'createViewModelFromNull'), -80);
+ $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'createViewModelFromArray'), -80);
+ $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'createViewModelFromNull'), -80);
}
/**
* Detach listeners
- *
- * @param Events $events
+ *
+ * @param Events $events
* @return void
*/
public function detach(Events $events)
@@ -66,7 +66,7 @@ public function detach(Events $events)
/**
* Inspect the result, and cast it to a ViewModel if an assoc array is detected
*
- * @param MvcEvent $e
+ * @param MvcEvent $e
* @return void
*/
public function createViewModelFromArray(MvcEvent $e)
Oops, something went wrong.

0 comments on commit 644af59

Please sign in to comment.