From 82ddd2e5629cb96f32a1b80203d45bf7d4826c0e Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Mon, 10 Apr 2017 12:15:10 +0300 Subject: [PATCH] HookManager: add possibility to define custom hook methods --- application/Espo/Core/HookManager.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/application/Espo/Core/HookManager.php b/application/Espo/Core/HookManager.php index b431f0f8f1..6f50cc91f7 100644 --- a/application/Espo/Core/HookManager.php +++ b/application/Espo/Core/HookManager.php @@ -42,17 +42,14 @@ class HookManager protected $cacheFile = 'data/cache/application/hooks.php'; /** - * List of defined hooks + * List of ignored hook methods * * @var array */ - protected $hookList = array( - 'beforeSave', - 'afterSave', - 'beforeRemove', - 'afterRemove', - 'afterRelate', - 'afterUnrelate' + protected $ignoredMethods = array( + '__construct', + 'getDependencyList', + 'inject', ); protected $paths = array( @@ -170,9 +167,12 @@ class HookManager $hookFilePath = Util::concatPath($hookScopeDirPath, $hookFile); $className = Util::getClassName($hookFilePath); - foreach($this->hookList as $hookName) { + $classMethods = get_class_methods($className); + $hookMethods = array_diff($classMethods, $this->ignoredMethods); + + foreach($hookMethods as $hookName) { $entityHookData = isset($hookData[$scopeName][$hookName]) ? $hookData[$scopeName][$hookName] : array(); - if (method_exists($className, $hookName) && !$this->isHookExists($className, $entityHookData)) { + if (!$this->isHookExists($className, $entityHookData)) { $hookData[$normalizedScopeName][$hookName][$className::$order][] = $className; } }