Skip to content
/ Events Public

Events; are useful constructs that allow you to hook from one point to another within the software.

License

Notifications You must be signed in to change notification settings

InitPHP/Events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Requirements

Installation

composer require initphp/events

Usage

Call the trigger() method where the events will be added. Send event with on() method.

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

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

License

Copyright © 2022 MIT License

About

Events; are useful constructs that allow you to hook from one point to another within the software.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages