Skip to content
Permalink
Browse files

Applied dispatchEvent() method.

  • Loading branch information...
robertpustulka committed Sep 10, 2014
1 parent 5f6bb95 commit f57db2173f6051ae37bb888a649a7d68df1007e0
@@ -468,11 +468,11 @@ protected function _loadComponents() {
* @return void|\Cake\Network\Response
*/
public function startupProcess() {
$event = $this->eventManager()->dispatch(new Event('Controller.initialize', $this));
$event = $this->dispatchEvent('Controller.initialize');
if ($event->result instanceof Response) {
return $event->result;
}
$event = $this->eventManager()->dispatch(new Event('Controller.startup', $this));
$event = $this->dispatchEvent('Controller.startup');
if ($event->result instanceof Response) {
return $event->result;
}
@@ -488,7 +488,7 @@ public function startupProcess() {
* @return void|\Cake\Network\Response
*/
public function shutdownProcess() {
$event = $this->eventManager()->dispatch(new Event('Controller.shutdown', $this));
$event = $this->dispatchEvent('Controller.shutdown');
if ($event->result instanceof Response) {
return $event->result;
}
@@ -512,8 +512,7 @@ public function redirect($url, $status = null) {
$response->statusCode($status);
}
$event = new Event('Controller.beforeRedirect', $this, [$url, $response]);
$event = $this->eventManager()->dispatch($event);
$event = $this->dispatchEvent('Controller.beforeRedirect', [$url, $response]);
if ($event->result instanceof Response) {
return $event->result;
}
@@ -559,8 +558,7 @@ public function setAction($action) {
* @link http://book.cakephp.org/2.0/en/controllers.html#Controller::render
*/
public function render($view = null, $layout = null) {
$event = new Event('Controller.beforeRender', $this);
$event = $this->eventManager()->dispatch($event);
$event = $this->dispatchEvent('Controller.beforeRender');
if ($event->result instanceof Response) {
$this->autoRender = false;
return $event->result;
@@ -206,8 +206,7 @@ public function all() {
}
$table = $this->repository();
$event = new Event('Model.beforeFind', $table, [$this, $this->_options, !$this->eagerLoaded()]);
$table->eventManager()->dispatch($event);
$table->dispatchEvent('Model.beforeFind', [$this, $this->_options, !$this->eagerLoaded()]);
if (isset($this->_results)) {
return $this->_results;
@@ -585,8 +585,7 @@ public function deleteAll($conditions) {
protected function _dispatchBeforeFind($query) {
$table = $this->target();
$options = $query->getOptions();
$event = new Event('Model.beforeFind', $table, [$query, $options, false]);
$table->eventManager()->dispatch($event);
$table->dispatchEvent('Model.beforeFind', [$query, $options, false]);
}
/**
@@ -138,8 +138,7 @@ protected function _processValidation($entity, $options) {
$type = is_string($options['validate']) ? $options['validate'] : 'default';
$validator = $this->_table->validator($type);
$pass = compact('entity', 'options', 'validator');
$event = new Event('Model.beforeValidate', $this->_table, $pass);
$this->_table->eventManager()->dispatch($event);
$event = $this->_table->dispatchEvent('Model.beforeValidate', $pass);
if ($event->isStopped()) {
return (bool)$event->result;
@@ -151,8 +150,7 @@ protected function _processValidation($entity, $options) {
$success = $entity->validate($validator);
$event = new Event('Model.afterValidate', $this->_table, $pass);
$this->_table->eventManager()->dispatch($event);
$event = $this->_table->dispatchEvent('Model.afterValidate', $pass);
if ($event->isStopped()) {
$success = (bool)$event->result;
@@ -1180,8 +1180,7 @@ protected function _processSave($entity, $options) {
}
$options['associated'] = $this->_associations->normalizeKeys($associated);
$event = new Event('Model.beforeSave', $this, compact('entity', 'options'));
$this->eventManager()->dispatch($event);
$event = $this->dispatchEvent('Model.beforeSave', compact('entity', 'options'));
if ($event->isStopped()) {
return $event->result;
@@ -1217,8 +1216,7 @@ protected function _processSave($entity, $options) {
);
if ($success || !$options['atomic']) {
$entity->clean();
$event = new Event('Model.afterSave', $this, compact('entity', 'options'));
$this->eventManager()->dispatch($event);
$this->dispatchEvent('Model.afterSave', compact('entity', 'options'));
$entity->isNew(false);
$entity->source($this->alias());
$success = true;
@@ -1402,12 +1400,10 @@ public function delete(EntityInterface $entity, $options = []) {
* @return bool success
*/
protected function _processDelete($entity, $options) {
$eventManager = $this->eventManager();
$event = new Event('Model.beforeDelete', $this, [
$event = $this->dispatchEvent('Model.beforeDelete', [
'entity' => $entity,
'options' => $options
]);
$eventManager->dispatch($event);
if ($event->isStopped()) {
return $event->result;
}
@@ -1434,11 +1430,10 @@ protected function _processDelete($entity, $options) {
return $success;
}
$event = new Event('Model.afterDelete', $this, [
$this->dispatchEvent('Model.afterDelete', [
'entity' => $entity,
'options' => $options
]);
$eventManager->dispatch($event);
return $success;
}
@@ -58,8 +58,7 @@ class Dispatcher {
* @throws \Cake\Routing\Exception\MissingControllerException When the controller is missing.
*/
public function dispatch(Request $request, Response $response) {
$beforeEvent = new Event('Dispatcher.beforeDispatch', $this, compact('request', 'response'));
$this->eventManager()->dispatch($beforeEvent);
$beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));
$request = $beforeEvent->data['request'];
if ($beforeEvent->result instanceof Response) {
@@ -89,8 +88,7 @@ public function dispatch(Request $request, Response $response) {
return $response->body();
}
$afterEvent = new Event('Dispatcher.afterDispatch', $this, compact('request', 'response'));
$this->eventManager()->dispatch($afterEvent);
$afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));
$afterEvent->data['response']->send();
}
@@ -416,9 +416,9 @@ public function render($view = null, $layout = null) {
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
$this->_currentType = static::TYPE_VIEW;
$this->eventManager()->dispatch(new Event('View.beforeRender', $this, array($viewFileName)));
$this->dispatchEvent('View.beforeRender', [$viewFileName]);
$this->Blocks->set('content', $this->_render($viewFileName));
$this->eventManager()->dispatch(new Event('View.afterRender', $this, array($viewFileName)));
$this->dispatchEvent('View.afterRender', [$viewFileName]);
}
if ($layout === null) {
@@ -451,7 +451,7 @@ public function renderLayout($content, $layout = null) {
} else {
$this->Blocks->set('content', $content);
}
$this->eventManager()->dispatch(new Event('View.beforeLayout', $this, array($layoutFileName)));
$this->dispatchEvent('View.beforeLayout', [$layoutFileName]);
$title = $this->Blocks->get('title');
if ($title === '') {
@@ -462,7 +462,7 @@ public function renderLayout($content, $layout = null) {
$this->_currentType = static::TYPE_LAYOUT;
$this->Blocks->set('content', $this->_render($layoutFileName));
$this->eventManager()->dispatch(new Event('View.afterLayout', $this, array($layoutFileName)));
$this->dispatchEvent('View.afterLayout', [$layoutFileName]);
return $this->Blocks->get('content');
}
@@ -696,14 +696,11 @@ protected function _render($viewFile, $data = array()) {
$this->_current = $viewFile;
$initialBlocks = count($this->Blocks->unclosed());
$eventManager = $this->eventManager();
$beforeEvent = new Event('View.beforeRenderFile', $this, array($viewFile));
$this->dispatchEvent('View.beforeRenderFile', [$viewFile]);
$eventManager->dispatch($beforeEvent);
$content = $this->_evaluate($viewFile, $data);
$afterEvent = new Event('View.afterRenderFile', $this, array($viewFile, $content));
$eventManager->dispatch($afterEvent);
$afterEvent = $this->dispatchEvent('View.afterRenderFile', [$viewFile, $content]);
if (isset($afterEvent->result)) {
$content = $afterEvent->result;
}
@@ -1007,13 +1004,13 @@ protected function _renderElement($file, $data, $options) {
$this->_currentType = static::TYPE_ELEMENT;
if ($options['callbacks']) {
$this->eventManager()->dispatch(new Event('View.beforeRender', $this, array($file)));
$this->dispatchEvent('View.beforeRender', [$file]);
}
$element = $this->_render($file, array_merge($this->viewVars, $data));
if ($options['callbacks']) {
$this->eventManager()->dispatch(new Event('View.afterRender', $this, array($file, $element)));
$this->dispatchEvent('View.afterRender', [$file, $element]);
}
$this->_currentType = $restore;

0 comments on commit f57db21

Please sign in to comment.
You can’t perform that action at this time.