nabeghe/hooker

A simple hook system library (actions and filters) based on Symfony EventDispatcher.

v0.3.2 2025-06-08 22:22 UTC

This package is auto-updated.

Last update: 2025-06-08 22:24:03 UTC


README

A simple hook system library (actions and filters) based on Symfony EventDispatcher.

🫡 Usage

🚀 Installation

You can install the package via composer:

composer require nabeghe/hooker

Examples

Action

require 'vendor/autoload.php';

use Nabeghe\Hooker\Hooker;
use Nabeghe\Hooker\Hook;

$hooker = new Hooker();

$hooker->setDefaultArgToHooks('protocol', 'https://');

$hooker->listen('your_custom_action_name', function (Hook $action) {
    echo $action['protocol'].$action['url'].PHP_EOL;
}, 2); // priority = 2

$hooker->action('your_custom_action_name', ['url' => 'https://github.com/nabeghe/hooker']);

Filter:

require 'vendor/autoload.php';

use Nabeghe\Hooker\Hooker;
use Nabeghe\Hooker\Hook;

$hooker = new Hooker();

$hooker->listen('your_custom_filter_name', function (Hook $filter) {
    if ($filter->getValue() === null) {
        $filter->setValue(8 + $filter['default']);
    }
});

$value = $hooker->filter('your_custom_filter_name', null, ['default' => 5]);
echo $value; // 13

📖 License

Copyright (c) Hadi Akbarzadeh

Licensed under the MIT license, see LICENSE.md for details.