From 08a13fcc927792b66045f9febdfe40d498b1b393 Mon Sep 17 00:00:00 2001 From: fSerny Date: Mon, 23 Jan 2012 10:06:15 +0000 Subject: [PATCH] // Hook refacto (AdminController) git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12595 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/AdminController.php | 39 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/classes/AdminController.php b/classes/AdminController.php index f36c4f78f..28df16741 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -486,34 +486,43 @@ class AdminControllerCore extends Controller if ($this->filter) $this->processFilter(); - if (!empty($this->action) && method_exists($this, 'process'.ucfirst(Tools::toCamelCase($this->action)))) + + // Methods tests + $case1 = false; + $case2 = false; + if (!empty($this->action)) + { + $case1 = method_exists($this, 'process'.ucfirst(Tools::toCamelCase($this->action))); + $case2 = method_exists($this, $this->action); + } + + + // Hook before action + if ($case1 || $case2) { /* Hook Before Action */ - Hook::exec('actionAdminBefore', array('controller' => $this)); + Hook::exec('actionAdmin'.ucfirst($this->action).'Before', array('controller' => $this)); Hook::exec('action'.get_class($this).ucfirst($this->action).'Before', array('controller' => $this)); + } + + // Call process + if ($case1) $return = $this->{'process'.Tools::toCamelCase($this->action)}($token); + else if ($case2) + $return = $this->{$this->action}($this->boxes); - /* Hook After Action */ - Hook::exec('actionAdminAfter', array('controller' => $this, 'return' => $return)); - Hook::exec('action'.get_class($this).ucfirst($this->action).'After', array('controller' => $this, 'return' => $return)); - return $return; - } - else if (method_exists($this, $this->action)) + // Hook after action + if (isset($return) && ($case1 || $case2)) { - /* Hook Before Action */ - Hook::exec('actionAdminBefore', array('controller' => $this)); - Hook::exec('action'.get_class($this).ucfirst($this->action).'Before', array('controller' => $this)); - - $return = call_user_func(array($this, $this->action), $this->boxes); - /* Hook After Action */ - Hook::exec('actionAdminAfter', array('controller' => $this, 'return' => $return)); + Hook::exec('actionAdmin'.ucfirst($this->action).'After', array('controller' => $this, 'return' => $return)); Hook::exec('action'.get_class($this).ucfirst($this->action).'After', array('controller' => $this, 'return' => $return)); return $return; } + } }