PHP code example of g4 / events

1. Go to this page and download the library: Download g4/events library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

g4 / events example snippets


// Register event as an anonymous function
\G4\Events\PubSub::on('event_name', function($arg1, $arg2) { echo $arg1; echo $arg2; });

// Register event as a class method
\G4\Events\PubSub::on('event_name', [new \G4\Events\Test(), 'test']);

// Unregister all subscribers
\G4\Events\PubSub::clear();

// Unregister all subscribers based on event name
\G4\Events\PubSub::off('event_name');

// Unregister one single subscriber
\G4\Events\PubSub::off('event_name', [new \G4\Events\Test(), 'test']);

// Get all events and subscribers
\G4\Events\PubSub::getEvents();

// Check if event is registered
\G4\Events\PubSub::has('event_name');

// Check if subscriber is registered
\G4\Events\PubSub::has('event_name', [new \G4\Events\Test(), 'test']);

// Trigger event with arguments
\G4\Events\PubSub::trigger('event_name', [12345, 987]);

// Trigger event without arguments
\G4\Events\PubSub::trigger('event_name');