EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Hook data provider
Yurii1544b54cfa5b
diff --git a/application/Espo/Binding.php b/application/Espo/Binding.phpindex f2107f4e12..d3d614f828 100644--- a/application/Espo/Binding.php+++ b/application/Espo/Binding.php@@ -143,6 +143,11 @@ class Binding implements BindingProcessor'recordServiceContainer');+ $binder->bindService(+ 'Espo\\Core\\Hook\\DataProvider',+ 'hookDataProvider'+ );+$binder->bindService('Espo\\Core\\HookManager','hookManager'diff --git a/application/Espo/Core/DataManager.php b/application/Espo/Core/DataManager.phpindex 98a00e531b..802cc02ed4 100644--- a/application/Espo/Core/DataManager.php+++ b/application/Espo/Core/DataManager.php@@ -30,6 +30,7 @@namespace Espo\Core;use Espo\Core\Exceptions\Error;+use Espo\Core\Hook\Control;use Espo\Core\ORM\EntityManagerProxy;use Espo\Core\Utils\Database\Helper as DatabaseHelper;use Espo\Core\Utils\Database\Schema\RebuildMode;@@ -61,7 +62,6 @@ class DataManagerprivate ConfigWriter $configWriter,private Metadata $metadata,private OrmMetadataData $ormMetadataData,- private HookManager $hookManager,private SchemaManagerProxy $schemaManager,private Log $log,private Module $module,@@ -69,7 +69,8 @@ class DataManagerprivate ConfigMissingDefaultParamsSaver $configMissingDefaultParamsSaver,private FileManager $fileManager,private DatabaseParamsFactory $databaseParamsFactory,- private InjectableFactory $injectableFactory+ private InjectableFactory $injectableFactory,+ private Control $hookControl,) {}/**@@ -237,12 +238,12 @@ class DataManagerprivate function disableHooks(): void{- $this->hookManager->disable();+ $this->hookControl->disable();}private function enableHooks(): void{- $this->hookManager->enable();+ $this->hookControl->enable();}/**diff --git a/application/Espo/Core/Hook/Control.php b/application/Espo/Core/Hook/Control.phpnew file mode 100644index 0000000000..aec35d74ac--- /dev/null+++ b/application/Espo/Core/Hook/Control.php@@ -0,0 +1,60 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\Hook;++use Espo\Core\Container;+use Espo\Core\HookManager;++/**+ * @internal+ *+ * Serves as a proxy for `HookManager`.+ */+class Control+{+ public function __construct(+ private Container $container,+ ) {}++ public function enable(): void+ {+ $this->getHookManager()->enable();+ }++ public function disable(): void+ {+ $this->getHookManager()->disable();+ }++ private function getHookManager(): HookManager+ {+ return $this->container->getByClass(HookManager::class);+ }+}diff --git a/application/Espo/Core/Hook/DataProvider.php b/application/Espo/Core/Hook/DataProvider.phpnew file mode 100644index 0000000000..2d655af91d--- /dev/null+++ b/application/Espo/Core/Hook/DataProvider.php@@ -0,0 +1,225 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\Hook;++use Espo\Core\Utils\Config\SystemConfig;+use Espo\Core\Utils\DataCache;+use Espo\Core\Utils\File\Manager as FileManager;+use Espo\Core\Utils\Metadata;+use Espo\Core\Utils\Module\PathProvider;+use Espo\Core\Utils\Util;+use LogicException;++/**+ * @internal+ * @since 10.1.0+ *+ * To be re-used between requests.+ */+class DataProvider+{+ private const int DEFAULT_ORDER = 9;++ /** @var ?array<string, array<string, mixed>> */+ private $data = null;++ private string $cacheKey = 'hooks';++ /** @var string[] */+ private $ignoredMethodList = [+ '__construct',+ 'getDependencyList',+ 'inject',+ ];++ public function __construct(+ private SystemConfig $systemConfig,+ private FileManager $fileManager,+ private PathProvider $pathProvider,+ private DataCache $dataCache,+ private Metadata $metadata,+ ) {}++ /**+ * @return array<string, array<string, mixed>>+ */+ public function get(): array+ {+ if (!$this->data) {+ $this->load();+ }++ return $this->data ?? throw new LogicException();+ }++ private function load(): void+ {+ if ($this->systemConfig->useCache() && $this->dataCache->has($this->cacheKey)) {+ /** @var array<string, array<string, mixed>> $cachedData */+ $cachedData = $this->dataCache->get($this->cacheKey);++ $this->data = $cachedData;++ return;+ }++ $data = $this->readHookData($this->pathProvider->getCustom() . 'Hooks');++ foreach ($this->metadata->getModuleList() as $moduleName) {+ $modulePath = $this->pathProvider->getModule($moduleName) . 'Hooks';++ $data = $this->readHookData($modulePath, $data);+ }++ $data = $this->readHookData($this->pathProvider->getCore() . 'Hooks', $data);++ $this->data = $this->sortHooks($data);++ if ($this->systemConfig->useCache()) {+ $this->dataCache->store($this->cacheKey, $this->data);+ }+ }++ /**+ * @param string $hookDir+ * @param array<string, array<string, mixed>> $hookData+ * @return array<string, array<string, mixed>>+ */+ private function readHookData(string $hookDir, array $hookData = []): array+ {+ if (!$this->fileManager->exists($hookDir)) {+ return $hookData;+ }++ /** @var array<string, string[]> $fileList */+ $fileList = $this->fileManager->getFileList($hookDir, 1, '\.php$', true);++ foreach ($fileList as $scopeName => $hookFiles) {+ $hookScopeDirPath = Util::concatPath($hookDir, $scopeName);+ $normalizedScopeName = Util::normalizeScopeName($scopeName);++ foreach ($hookFiles as $hookFile) {+ $hookFilePath = Util::concatPath($hookScopeDirPath, $hookFile);+ $className = Util::getClassName($hookFilePath);++ $classMethods = get_class_methods($className);++ $hookMethods = array_diff($classMethods, $this->ignoredMethodList);++ /** @var string[] $hookMethods */+ $hookMethods = array_filter($hookMethods, function ($item) {+ if (str_starts_with($item, 'set')) {+ return false;+ }++ return true;+ });++ foreach ($hookMethods as $hookType) {+ $entityHookData = $hookData[$normalizedScopeName][$hookType] ?? [];++ if ($this->hookExists($className, $entityHookData)) {+ continue;+ }++ if ($this->hookClassIsSuppressed($className)) {+ continue;+ }++ $hookData[$normalizedScopeName][$hookType][] = [+ 'className' => $className,+ 'order' => $className::$order ?? self::DEFAULT_ORDER,+ ];+ }+ }+ }++ return $hookData;+ }++ /**+ * Check if hook exists in the list.+ *+ * @param class-string $className+ * @param array<string, mixed> $hookData+ */+ private function hookExists(string $className, array $hookData): bool+ {+ $class = preg_replace('/^.*\\\(.*)$/', '$1', $className);++ foreach ($hookData as $item) {+ if (preg_match('/\\\\'.$class.'$/', $item['className'])) {+ return true;+ }+ }++ return false;+ }++ /**+ * Sort hooks by the order parameter.+ *+ * @param array<string, array<string, mixed>> $hooks+ * @return array<string, array<string, mixed>>+ */+ private function sortHooks(array $hooks): array+ {+ foreach ($hooks as &$scopeHooks) {+ foreach ($scopeHooks as &$hookList) {+ usort($hookList, [$this, 'cmpHooks']);+ }+ }++ return $hooks;+ }++ /**+ * @param class-string $className+ */+ private function hookClassIsSuppressed(string $className): bool+ {+ $suppressList = $this->metadata->get(['app', 'hook', 'suppressClassNameList']) ?? [];++ return in_array($className, $suppressList);+ }++ /**+ * @param array<string, mixed> $a+ * @param array<string, mixed> $b+ */+ private function cmpHooks($a, $b): int+ {+ if ($a['order'] == $b['order']) {+ return 0;+ }++ return ($a['order'] < $b['order']) ? -1 : 1;+ }+}diff --git a/application/Espo/Core/HookManager.php b/application/Espo/Core/HookManager.phpindex e152b6b109..a8a73adaff 100644--- a/application/Espo/Core/HookManager.php+++ b/application/Espo/Core/HookManager.php@@ -29,14 +29,9 @@namespace Espo\Core;+use Espo\Core\Hook\DataProvider;use Espo\Core\Hook\GeneralInvoker;-use Espo\Core\Utils\Config\SystemConfig;-use Espo\Core\Utils\DataCache;-use Espo\Core\Utils\File\Manager as FileManager;use Espo\Core\Utils\Log;-use Espo\Core\Utils\Metadata;-use Espo\Core\Utils\Module\PathProvider;-use Espo\Core\Utils\Util;/*** Runs hooks. E.g. beforeSave, afterSave. Hooks can be located in a folder@@ -51,32 +46,22 @@ use Espo\Core\Utils\Util;*/class HookManager{- private const int DEFAULT_ORDER = 9;-/** @var ?array<string, array<string, mixed>> */private $data = null;+private bool $isDisabled = false;+/** @var array<string, class-string[]> */private $hookListHash = [];+/** @var array<class-string, object> */private $hooks;- private string $cacheKey = 'hooks';- /** @var string[] */- private $ignoredMethodList = [- '__construct',- 'getDependencyList',- 'inject',- ];public function __construct(private InjectableFactory $injectableFactory,- private FileManager $fileManager,- private Metadata $metadata,- private DataCache $dataCache,private Log $log,- private PathProvider $pathProvider,private GeneralInvoker $generalInvoker,- private SystemConfig $systemConfig,+ private DataProvider $dataProvider,) {}/**@@ -98,13 +83,13 @@ class HookManagerreturn;}- if (!isset($this->data)) {+ if ($this->data === null) {$this->loadHooks();}$hookList = $this->getHookList($scope, $hookName);- if (empty($hookList)) {+ if ($hookList === []) {return;}@@ -143,32 +128,7 @@ class HookManagerprivate function loadHooks(): void{- if ($this->systemConfig->useCache() && $this->dataCache->has($this->cacheKey)) {- /** @var array<string, array<string, mixed>> $cachedData */- $cachedData = $this->dataCache->get($this->cacheKey);-- $this->data = $cachedData;-- return;- }-- $metadata = $this->metadata;-- $data = $this->readHookData($this->pathProvider->getCustom() . 'Hooks');-- foreach ($metadata->getModuleList() as $moduleName) {- $modulePath = $this->pathProvider->getModule($moduleName) . 'Hooks';-- $data = $this->readHookData($modulePath, $data);- }-- $data = $this->readHookData($this->pathProvider->getCore() . 'Hooks', $data);-- $this->data = $this->sortHooks($data);-- if ($this->systemConfig->useCache()) {- $this->dataCache->store($this->cacheKey, $this->data);- }+ $this->data = $this->dataProvider->get();}/**@@ -183,89 +143,6 @@ class HookManagerreturn $this->injectableFactory->create($className);}- /**- * @param string $hookDir- * @param array<string, array<string, mixed>> $hookData- * @return array<string, array<string, mixed>>- */- private function readHookData(string $hookDir, array $hookData = []): array- {- if (!$this->fileManager->exists($hookDir)) {- return $hookData;- }-- /** @var array<string, string[]> $fileList */- $fileList = $this->fileManager->getFileList($hookDir, 1, '\.php$', true);-- foreach ($fileList as $scopeName => $hookFiles) {- $hookScopeDirPath = Util::concatPath($hookDir, $scopeName);- $normalizedScopeName = Util::normalizeScopeName($scopeName);-- foreach ($hookFiles as $hookFile) {- $hookFilePath = Util::concatPath($hookScopeDirPath, $hookFile);- $className = Util::getClassName($hookFilePath);-- $classMethods = get_class_methods($className);-- $hookMethods = array_diff($classMethods, $this->ignoredMethodList);-- /** @var string[] $hookMethods */- $hookMethods = array_filter($hookMethods, function ($item) {- if (str_starts_with($item, 'set')) {- return false;- }-- return true;- });-- foreach ($hookMethods as $hookType) {- $entityHookData = $hookData[$normalizedScopeName][$hookType] ?? [];-- if ($this->hookExists($className, $entityHookData)) {- continue;- }-- if ($this->hookClassIsSuppressed($className)) {- continue;- }-- $hookData[$normalizedScopeName][$hookType][] = [- 'className' => $className,- 'order' => $className::$order ?? self::DEFAULT_ORDER,- ];- }- }- }-- return $hookData;- }-- /**- * @param class-string $className- */- private function hookClassIsSuppressed(string $className): bool- {- $suppressList = $this->metadata->get(['app', 'hook', 'suppressClassNameList']) ?? [];-- return in_array($className, $suppressList);- }-- /**- * Sort hooks by the order parameter.- *- * @param array<string, array<string, mixed>> $hooks- * @return array<string, array<string, mixed>>- */- private function sortHooks(array $hooks): array- {- foreach ($hooks as &$scopeHooks) {- foreach ($scopeHooks as &$hookList) {- usort($hookList, [$this, 'cmpHooks']);- }- }-- return $hooks;- }/*** Get sorted hook list.@@ -286,7 +163,7 @@ class HookManagerif (isset($this->data[$scope][$hookName])) {$hookList = array_merge($hookList, $this->data[$scope][$hookName]);- usort($hookList, array($this, 'cmpHooks'));+ usort($hookList, [$this, 'cmpHooks']);}$normalizedList = [];@@ -301,25 +178,6 @@ class HookManagerreturn $this->hookListHash[$key];}- /**- * Check if hook exists in the list.- *- * @param class-string $className- * @param array<string, mixed> $hookData- */- private function hookExists(string $className, array $hookData): bool- {- $class = preg_replace('/^.*\\\(.*)$/', '$1', $className);-- foreach ($hookData as $item) {- if (preg_match('/\\\\'.$class.'$/', $item['className'])) {- return true;- }- }-- return false;- }-/*** @param array<string, mixed> $a* @param array<string, mixed> $bdiff --git a/application/Espo/Core/Loaders/HookDataProvider.php b/application/Espo/Core/Loaders/HookDataProvider.phpnew file mode 100644index 0000000000..cd22bb23c5--- /dev/null+++ b/application/Espo/Core/Loaders/HookDataProvider.php@@ -0,0 +1,49 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\Loaders;++use Espo\Core\Container\Loader;+use Espo\Core\Hook\DataProvider;+use Espo\Core\InjectableFactory;++/**+ * @noinspection PhpUnused+ */+class HookDataProvider implements Loader+{+ public function __construct(+ private InjectableFactory $injectableFactory,+ ) {}++ public function load()+ {+ return $this->injectableFactory->create(DataProvider::class);+ }+}diff --git a/tests/unit/Espo/Core/HookManagerTest.php b/tests/unit/Espo/Core/Hook/DataProviderTest.phpsimilarity index 68%rename from tests/unit/Espo/Core/HookManagerTest.phprename to tests/unit/Espo/Core/Hook/DataProviderTest.phpindex 6a4db157d8..be5e19e9f1 100644--- a/tests/unit/Espo/Core/HookManagerTest.php+++ b/tests/unit/Espo/Core/Hook/DataProviderTest.php@@ -27,30 +27,25 @@* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.************************************************************************/-namespace tests\unit\Espo\Core;+namespace tests\unit\Espo\Core\Hook;+use Espo\Core\Hook\DataProvider;use PHPUnit\Framework\TestCase;use tests\unit\ReflectionHelper;--use Espo\Core\Hook\GeneralInvoker;-use Espo\Core\HookManager;-use Espo\Core\InjectableFactory;use Espo\Core\Utils\Config;use Espo\Core\Utils\DataCache;use Espo\Core\Utils\File\Manager as FileManager;-use Espo\Core\Utils\Log;use Espo\Core\Utils\Metadata;use Espo\Core\Utils\Module\PathProvider;-class HookManagerTest extends TestCase+class DataProviderTest extends TestCase{- private $filesPath = 'tests/unit/testData/Hooks';+ private string $filesPath = 'tests/unit/testData/Hooks';private ?Config\SystemConfig $systemConfig = null;-- private $pathProvider;- private $reflection;- private $metadata;+ private ?PathProvider $pathProvider = null;+ private ?ReflectionHelper $reflectionHelper = null;+ private ?Metadata $metadata = null;protected function setUp(): void{@@ -59,24 +54,19 @@ class HookManagerTest extends TestCase$this->systemConfig = $this->createMock(Config\SystemConfig::class);- $injectableFactory = $this->createMock(InjectableFactory::class);$dataCache = $this->createMock(DataCache::class);$fileManager = new FileManager();$this->pathProvider = $this->createMock(PathProvider::class);- $generalInvoker = $this->createMock(GeneralInvoker::class);-- $hookManager = new HookManager(- $injectableFactory,- $fileManager,- $this->metadata,- $dataCache,- $this->createMock(Log::class),- $this->pathProvider,- $generalInvoker,- $this->systemConfig,++ $dataProvider = new DataProvider(+ systemConfig: $this->systemConfig,+ fileManager: $fileManager,+ pathProvider: $this->pathProvider,+ dataCache: $dataCache,+ metadata: $this->metadata,);- $this->reflection = new ReflectionHelper($hookManager);+ $this->reflectionHelper = new ReflectionHelper($dataProvider);}private function initPathProvider(string $folder): void@@ -106,156 +96,150 @@ class HookManagerTest extends TestCasepublic function testHookExists(): void{- $data = array (- 'Espo\\Hooks\\Note\\Stream' => 8,- 'Espo\\Hooks\\Note\\Mentions' => 9,- 'Espo\\Hooks\\Note\\Notifications' => 14,- );-- $data = array (- array (+ $data = [+ ['className' => 'Espo\\Hooks\\Note\\Stream','order' => 8,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Note\\Mentions','order' => 9,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Note\\Notifications','order' => 14,- ),- );+ ],+ ];$this->assertTrue(- $this->reflection->invokeMethod('hookExists', array('Espo\\Hooks\\Note\\Mentions', $data))+ $this->reflectionHelper->invokeMethod('hookExists', ['Espo\\Hooks\\Note\\Mentions', $data]));$this->assertTrue(- $this->reflection->invokeMethod('hookExists', array('Espo\\Modules\\Crm\\Hooks\\Note\\Mentions', $data))+ $this->reflectionHelper->invokeMethod('hookExists', ['Espo\\Modules\\Crm\\Hooks\\Note\\Mentions', $data]));$this->assertTrue(- $this->reflection->invokeMethod('hookExists', array('Espo\\Modules\\Test\\Hooks\\Note\\Mentions', $data))+ $this->reflectionHelper->invokeMethod('hookExists', ['Espo\\Modules\\Test\\Hooks\\Note\\Mentions', $data]));$this->assertTrue(- $this->reflection->invokeMethod('hookExists', array('Espo\\Modules\\Test\\Hooks\\Common\\Stream', $data))+ $this->reflectionHelper->invokeMethod('hookExists', ['Espo\\Modules\\Test\\Hooks\\Common\\Stream', $data]));$this->assertFalse(- $this->reflection->invokeMethod('hookExists', array('Espo\\Hooks\\Note\\TestHook', $data))+ $this->reflectionHelper->invokeMethod('hookExists', ['Espo\\Hooks\\Note\\TestHook', $data]));}- public function testSortHooks()+ public function testSortHooks(): void{- $data = array (+ $data = ['Common' =>- array (+ ['afterSave' =>- array (- array (+ [+ ['className' => 'Espo\\Hooks\\Common\\AssignmentEmailNotification','order' => 9,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Common\\Notifications','order' => 10,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Common\\Stream','order' => 9,- ),- ),+ ],+ ],'beforeSave' =>- array (- array (+ [+ ['className' => 'Espo\\Hooks\\Common\\Formula','order' => 5,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Common\\NextNumber','order' => 10,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Common\\CurrencyConverted','order' => 1,- ),- ),- ),+ ],+ ],+ ],'Note' =>- array (+ ['beforeSave' =>- array (- array (+ [+ ['className' => 'Espo\\Hooks\\Note\\Mentions','order' => 9,- ),- ),+ ],+ ],'afterSave' =>- array (- array (+ [+ ['className' => 'Espo\\Hooks\\Note\\Notifications','order' => 14,- ),- ),- ),- );+ ],+ ],+ ],+ ];- $result = array (+ $result = ['Common' =>- array (+ ['afterSave' =>- array (- array (+ [+ ['className' => 'Espo\\Hooks\\Common\\AssignmentEmailNotification','order' => 9,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Common\\Stream','order' => 9,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Common\\Notifications','order' => 10,- ),- ),+ ],+ ],'beforeSave' =>- array (- array (+ [+ ['className' => 'Espo\\Hooks\\Common\\CurrencyConverted','order' => 1,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Common\\Formula','order' => 5,- ),- array (+ ],+ ['className' => 'Espo\\Hooks\\Common\\NextNumber','order' => 10,- ),- ),- ),+ ],+ ],+ ],'Note' =>- array (+ ['beforeSave' =>- array (- array (+ [+ ['className' => 'Espo\\Hooks\\Note\\Mentions','order' => 9,- ),- ),+ ],+ ],'afterSave' =>- array (- array (+ [+ ['className' => 'Espo\\Hooks\\Note\\Notifications','order' => 14,- ),- ),- ),- );+ ],+ ],+ ],+ ];- $this->assertEquals($result, $this->reflection->invokeMethod('sortHooks', array($data)) );+ $this->assertEquals($result, $this->reflectionHelper->invokeMethod('sortHooks', [$data]));}- public function testCase1CustomHook()+ public function testCase1CustomHook(): void{$this->initPathProvider('testCase1');@@ -272,7 +256,7 @@ class HookManagerTest extends TestCase'Test',]);- $this->reflection->invokeMethod('loadHooks');+ $this->reflectionHelper->invokeMethod('load');$result = ['Note' =>@@ -287,10 +271,10 @@ class HookManagerTest extends TestCase],];- $this->assertEquals($result, $this->reflection->getProperty('data'));+ $this->assertEquals($result, $this->reflectionHelper->getProperty('data'));}- public function testCase2ModuleHook1()+ public function testCase2ModuleHook1(): void{$this->initPathProvider('testCase2');@@ -307,7 +291,7 @@ class HookManagerTest extends TestCase'Test',]);- $this->reflection->invokeMethod('loadHooks');+ $this->reflectionHelper->invokeMethod('load');$result = ['Note' =>@@ -323,10 +307,10 @@ class HookManagerTest extends TestCase],];- $this->assertEquals($result, $this->reflection->getProperty('data'));+ $this->assertEquals($result, $this->reflectionHelper->getProperty('data'));}- public function testCase2ModuleHookReverseModuleOrder()+ public function testCase2ModuleHookReverseModuleOrder(): void{$this->initPathProvider('testCase2');@@ -343,7 +327,7 @@ class HookManagerTest extends TestCase'Crm',]);- $this->reflection->invokeMethod('loadHooks');+ $this->reflectionHelper->invokeMethod('load');$result = ['Note' =>@@ -359,7 +343,7 @@ class HookManagerTest extends TestCase],];- $this->assertEquals($result, $this->reflection->getProperty('data'));+ $this->assertEquals($result, $this->reflectionHelper->getProperty('data'));}public function testCase3CoreHook()@@ -376,21 +360,21 @@ class HookManagerTest extends TestCase->method('getModuleList')->willReturn([]);- $this->reflection->invokeMethod('loadHooks');+ $this->reflectionHelper->invokeMethod('load');- $result = array (+ $result = ['Note' =>- array (+ ['beforeSave' =>- array (- array (+ [+ ['className' => 'tests\\unit\\testData\\Hooks\\testCase3\\application\\Espo\\Hooks\\Note\\Mentions','order' => 9,- ),- ),- ),- );+ ],+ ],+ ],+ ];- $this->assertEquals($result, $this->reflection->getProperty('data'));+ $this->assertEquals($result, $this->reflectionHelper->getProperty('data'));}}