forked from PrestaShop/PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PrestaShop#37125 from matthieu-rolland/filter-modu…
…le-hook Make getHookModuleExecList customizable from modules
- Loading branch information
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
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; | ||
|
||
public function __construct(iterable $hookModuleFilters) | ||
{ | ||
$this->hookModuleFilters = $hookModuleFilters; | ||
} | ||
|
||
public function filterHookModuleExecList(array $modules, string $hookName): array | ||
{ | ||
foreach ($this->hookModuleFilters as $hookModuleFilter) { | ||
$modules = $hookModuleFilter->filterHookModuleExecList($modules, $hookName); | ||
} | ||
|
||
return $modules; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
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; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/PrestaShopBundle/Resources/config/services/core/common.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |