https://github.com/fabiomontefuscolo/php-mediator
A simple hooks system
https://github.com/fabiomontefuscolo/php-mediator
actions filters hooks mediator php
Last synced: 5 months ago
JSON representation
A simple hooks system
- Host: GitHub
- URL: https://github.com/fabiomontefuscolo/php-mediator
- Owner: fabiomontefuscolo
- License: lgpl-2.1
- Archived: true
- Created: 2018-05-15T19:20:14.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-16T02:37:03.000Z (about 8 years ago)
- Last Synced: 2025-11-27T15:30:47.925Z (7 months ago)
- Topics: actions, filters, hooks, mediator, php
- Language: PHP
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-mediator [](https://travis-ci.org/fabiomontefuscolo/php-mediator)
It is just another Hook system. It is useful to integrate very distinct components of software without making them too coupled to each other.
## Installing
```shell
composer require montefuscolo/php-mediator
```
## Using it
### Actions
```php
add_action('my-channel', function() {
echo 'Hello World' . PHP_EOL;
});
$mediator->add_action('my-channel', function() {
echo 'Foo Bar' . PHP_EOL;
});
// ....
$mediator->run_actions('my-channel');
```
### Filters
```php
add_filter('my-channel', function($n) {
return $n * 2;
});
$mediator->add_filter('my-channel', function($n) {
return $n * 3;
});
$mediator->add_filter('my-channel', function($n) {
return $n - 6;
});
// ....
echo $mediator->run_filters('my-channel', 1);
// >>> 0
```