Skip to content
/ hooker Public

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

License

Notifications You must be signed in to change notification settings

nabeghe/hooker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hooker for PHP

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

Check the examples folder in the repositiry.

Action

require 'vendor/autoload.php';

use Nabeghe\Hooker\Hooker;
use Nabeghe\Hooker\Action;

$hooker = new Hooker();

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

$hooker->listen('your_custom_action_name', function (Action $action) {
    echo $action['protocol'].$action['url'].PHP_EOL;
}, 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\Filter;

$hooker = new Hooker();

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

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages