Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nabeghe/hooker
A simple hook system library (actions and filters) for php based on Symfony EventDispatcher
https://github.com/nabeghe/hooker
event eventdispatcher events hook hooks php symfony
Last synced: about 1 month ago
JSON representation
A simple hook system library (actions and filters) for php based on Symfony EventDispatcher
- Host: GitHub
- URL: https://github.com/nabeghe/hooker
- Owner: nabeghe
- License: mit
- Created: 2024-09-19T18:03:28.000Z (about 2 months ago)
- Default Branch: master
- Last Pushed: 2024-09-19T18:06:22.000Z (about 2 months ago)
- Last Synced: 2024-09-29T13:36:14.087Z (about 2 months ago)
- Topics: event, eventdispatcher, events, hook, hooks, php, symfony
- Language: PHP
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Hooker for PHP
> A simple hook system library (actions and filters) based on Symfony EventDispatcher.
## 🫡 Usage
### 🚀 Installation
You can install the package via composer:
```bash
composer require nabeghe/hooker
```### Examples
Check the examples folder in the repositiry.
#### Action
```php
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:
```php
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
```