Skip to content

Commit

Permalink
fix service availability issue
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-rolland committed Nov 13, 2024
1 parent 4295f87 commit b806043
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion classes/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ private static function getHookModuleFilter()
}

try {
$hookModuleFilter = $serviceContainer->get('prestashop.hook.module.filter');
$hookModuleFilter = $serviceContainer->get(HookModuleFilter::class);
} catch (Exception $e) {
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions config/services/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ services:
public: false
tags: ['container.env_var_processor']

prestashop.hook.module.filter:
class: PrestaShop\PrestaShop\Core\Hook\HookModuleFilter
PrestaShop\PrestaShop\Core\Hook\HookModuleFilter:
arguments:
- !tagged core.hook_module_exec_filter
12 changes: 12 additions & 0 deletions src/Core/Hook/HookModuleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@

namespace PrestaShop\PrestaShop\Core\Hook;

/**
* This service is responsible for filtering the list of modules for a given hook that is returned by
* the getHookModuleExecList method from Hook.php. It is called at the very end of getHookModuleExecList.
*
* How to use it to filter a list of modules for a hook:
*
* In your module, create a service which implements the HookModuleFilterInterface and give it
* the tag named core.hook_module_exec_filter. Then in your service, you can filter the list of modules
* in the filterHookModuleExecList method, according to your own logic.
*
* Your service will automatically be sent in this class's constructor, and be used to filter the list of modules.
*/
class HookModuleFilter implements HookModuleFilterInterface
{
private $hookModuleFilters;
Expand Down
4 changes: 4 additions & 0 deletions src/Core/Hook/HookModuleFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

namespace PrestaShop\PrestaShop\Core\Hook;

/**
* This interface must be implemented by all services that will be used by the HookModuleFilter service.
* See HookModuleFilter.php for more explanations.
*/
interface HookModuleFilterInterface
{
public function filterHookModuleExecList(array $modules, string $hookName): array;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
imports:
- { resource: ./circuit_breaker.yml }

services:
PrestaShop\PrestaShop\Core\Hook\HookModuleFilter:
arguments:
- !tagged core.hook_module_exec_filter

0 comments on commit b806043

Please sign in to comment.