Prestashop: Exception should be thrown when instanciation a module is done if hooks are not right configured

Created on 26 Sep 2019  路  6Comments  路  Source: PrestaShop/PrestaShop

Is your feature request related to a problem? Please describe.

When we register hooks, no checks are done to control the existence of related functions expected by Hook class.

So we can expect a hook to be hooked (lol) while the function is not here (or wrongly named).

Describe the solution you'd like

Something like an exception with the following message:

"WrongHookRegistrationException: hook with the name %hookName% has been registered, but the following function %functionName% is not defined in the Module class %className%.

Describe alternatives you've considered

Be allowed to set the function name while registering the hook or be allowed to pass a callable.

$this->registerHook('foo', function ($hookParams) {
    /// whatever ...
});

Additional context
I'm sad I want to cry a river ;)

Improvement waiting for dev

Most helpful comment

@kpodemski To make it less violent, we could only allow this in DEBUG mode, or convert it to a notice error message ?

All 6 comments

Ping @PrestaShop/prestashop-core-developers

@mickaelandrieu This would require us to use Reflection on the Module to make sure the right function exists 馃 when registerHook(...) is used, right ?

@matks It can be done after this if / elseif: https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Hook.php#L896

The function isHookCallableOn a module is already available.

I'm pretty sure this would be a breaking change :)

@kpodemski To make it less violent, we could only allow this in DEBUG mode, or convert it to a notice error message ?

@matks notice should be ok 馃憤

Was this page helpful?
0 / 5 - 0 ratings