Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manifestwebdesign/php-hooks
Hook / Event helper library for PHP
https://github.com/manifestwebdesign/php-hooks
Last synced: 15 days ago
JSON representation
Hook / Event helper library for PHP
- Host: GitHub
- URL: https://github.com/manifestwebdesign/php-hooks
- Owner: ManifestWebDesign
- Created: 2013-02-28T19:37:13.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-02-28T20:01:04.000Z (almost 12 years ago)
- Last Synced: 2024-03-26T02:16:44.504Z (10 months ago)
- Language: PHP
- Size: 105 KB
- Stars: 8
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PHP-Hooks
=========
Standalone Hook / Event helper library for PHPBasic Usage:
------------
```php
Hook::add('my_hook', function($message){
echo $message;
});
Hook::call('my_hook', 'Hello world'); // echo 'Hello world'
```Removing a Single Callback from a Hook:
---------------------------------------
Hook internally creates unique ids for callbacks, so they can be removed
```php
$callback = function($message){
echo $message;
};
Hook::add('my_hook', $callback);
Hook::call('my_hook', 'Hello world'); // echo 'Hello world'
Hook::remove('my_hook', $callback);
Hook::call('my_hook', 'Hello world'); // does nothing
```Removing all Callbacks for a Hook:
----------------------------------
```php
Hook::add('my_hook', function($message){
echo $message;
});
Hook::remove('my_hook');
Hook::call('my_hook', 'Hello world'); // does nothing
```Priority and Return False
----------------------------------
```php
Hook::add('my_hook', function($message){
echo $message;
}, 100); // priority of 100
Hook::add('my_hook', function(){
return false;
}, 99);
Hook::call('my_hook', 'Hello world'); // does nothing, because the callback that returned false was executed first
```Get Array of Registered Callbacks for a Hook
--------------------------------------------
```php
Hook::add('my_hook', function($message){
echo $message;
}, 100); // priority of 100
Hook::add('my_hook', function(){
return false;
}, 99);
Hook::get('my_hook'); // returns numeric array with both callbacks, in the order that they would execute
```