PHPackages                             dartmoon/prestashop-hooks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dartmoon/prestashop-hooks

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dartmoon/prestashop-hooks
=========================

PrestaShop Hooks made OOP

v0.3.0(2y ago)02831MITPHP

Since Aug 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/dartmoon-io/prestashop-hooks)[ Packagist](https://packagist.org/packages/dartmoon/prestashop-hooks)[ RSS](/packages/dartmoon-prestashop-hooks/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (1)

Prestashop Hooks
================

[](#prestashop-hooks)

PrestaShop hooks done right! Instead of polluting the main file of your module with all the hook definitions, with this package you can define them into their own class.

Installation
------------

[](#installation)

1. Install the package

```
composer require dartmoon/prestashop-hooks
```

2. Add to the main class of your module the trait `HasHookDispatcher` and the `hooks` property

```
use Dartmoon\Hooks\Traits\HasHookDispatcher;

class YourModule
{
    use HasHookDispatcher;

    /**
     * Hook classes
     */
    protected $hooks = [
        //
    ];

    // ...
}
```

3. Fix the class constructor by initializing the hook dispatcher

```
public function __construct()
{
    //...

    // Let's init the hook dispatcher
    $this->initHookDispatcher();
}
```

4. Fix the `install` method to install the hooks

```
public function install()
{
    if (
        parent::install()
        && $this->registerHook($this->getHookDispatcher()->getAvailableHooks())
    ) {
        //...

        return true;
    }

    return false;
}
```

Usage
-----

[](#usage)

### Create the hook group class

[](#create-the-hook-group-class)

Let's create the class. For the sake of the example suppose we are creating them inside the `src/Hooks` folder of your module.

File `src/Hooks/FrontAssetsHooks.php`

```
