Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jersoncarin/hooks
A lightweight hooking system inspired by wordpress
https://github.com/jersoncarin/hooks
Last synced: about 23 hours ago
JSON representation
A lightweight hooking system inspired by wordpress
- Host: GitHub
- URL: https://github.com/jersoncarin/hooks
- Owner: jersoncarin
- License: mit
- Created: 2021-01-16T17:04:28.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-18T12:02:56.000Z (almost 4 years ago)
- Last Synced: 2024-04-21T11:00:38.266Z (7 months ago)
- Language: PHP
- Size: 23.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jers Hooks API for PHP
JersHooks is a hooking system which inspired by wordpress hooking api
- apply_filters
- add_filter
- remove_filter
- add_action
- do_action
- remove_action# Requirements
- PHP 8.0+
# Installation
```php
composer require jersoncarin/jershooks
```
# How to use
```php
$hooks = new \Jersnet\Framework\Hook\Hooks;// adding action to the hooks
// Note: it can be a closure, a function and a class method
// add_action(string $tag,mixed $object,int $priority,int $args_limit)
$hooks->add_action('action_name',function(){
// some code
});// Firing an action
// do_action(string $tag,...$args);
// you can pass as many as you can arguments
$hooks->do_action('action_name');// Removing an action
// remove_action(string $tag,callable $callable,int $priority = 10)
// Third argument is optional
$hooks->remove_action('action_name','some_function');// Has action(s)
// Returns boolean
$hooks->has_action('action_name','some_function');
$hooks->has_actions();// adding filter to the hooks
// Note: it can be a closure, a function and a class method
// add_filter(string $tag,mixed $object,int $priority,int $args_limit)
$hooks->add_filter('filter_name',function($arg){
// some code
});// Removing an filter
// remove_filter(string $tag,callable $callable,int $priority = 10)
// Third argument is optional
$hooks->remove_filter('filter_name','some_function');// Has filter(s)
// Returns boolean
$hooks->has_filter('action_name','some_function');
$hooks->has_filters();// Applying Filters
// Apply filters to a hook
// apply_filters(string $tag,mixed $value,mixed ...$args)
// Return mixed
$hooks->apply_filters('filter_name','some_filter','extra_filer');
```
# Author
- Jerson Carin
# License
- MIT License