https://github.com/initphp/events
Events; are useful constructs that allow you to hook from one point to another within the software.
https://github.com/initphp/events
php php-event php-hook php-hooks
Last synced: 5 months ago
JSON representation
Events; are useful constructs that allow you to hook from one point to another within the software.
- Host: GitHub
- URL: https://github.com/initphp/events
- Owner: InitPHP
- License: mit
- Created: 2022-03-15T09:37:37.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-09T08:55:01.000Z (over 3 years ago)
- Last Synced: 2025-10-05T23:45:01.648Z (6 months ago)
- Topics: php, php-event, php-hook, php-hooks
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Events
It allows you to run functions from outside in different places within your software. It allows you to set up a similar structure known as a hook in the Wordpress ecosystem.
[](https://packagist.org/packages/initphp/events) [](https://packagist.org/packages/initphp/events) [](https://packagist.org/packages/initphp/events) [](https://packagist.org/packages/initphp/events) [](https://packagist.org/packages/initphp/events)
## Requirements
- PHP 5.6 or higher
- [InitPHP EventEmitter Library](https://github.com/InitPHP/EventEmitter)
## Installation
```
composer require initphp/events
```
## Usage
Call the `trigger()` method where the events will be added. Send event with `on()` method.
```php
require_once "vendor/autoload.php";
use \InitPHP\Events\Events;
Events::on('helloTrigger', function(){
echo 'Hello World' . PHP_EOL;
}, 100);
Events::on('helloTrigger', function(){
echo 'Hi, World' . PHP_EOL;
}, 99);
Events::trigger('helloTrigger');
```
**Output :**
```
Hi World
Hello World
```
### Use of Arguments
```php
require_once "vendor/autoload.php";
use \InitPHP\Events\Events;
Events::on('helloTrigger', function($name, $myName){
echo 'Hello ' . $name . '. I am ' . $myName . '.' . PHP_EOL;
}, 100);
Events::on('helloTrigger', function($name, $myName){
echo 'Hi ' . $name . '. I am ' . $myName . '.' . PHP_EOL;
}, 99);
Events::trigger('helloTrigger', 'World', 'John');
```
**Output :**
```
Hi World. I am John.
Hello World. I am John.
```
## Credits
- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) <>
## License
Copyright © 2022 [MIT License](./LICENSE)