PHP code example of proteins / event

1. Go to this page and download the library: Download proteins/event 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/ */

    

proteins / event example snippets


use Proteins\Event;

use Proteins\Events;

class MyClass {
    use Events;
}

Event::on('my.event',function(){
   echo 'Hello, Friend!';
});

Event::on('my.event',function(){
   echo 'First!';
});

Event::on('my.event',function(){
   echo 'Second!';
});

Event::trigger('my.event');

Event::on('my.event',function(){
   return 'Hello!';
});

Event::on('my.event',function(){
   return time();
});

$results = Event::trigger('my.event');

array(2) {
 [0]  =>  string(6) "Hello!"
 [1]  =>  int(1389115191)
}

Event::on('eat',function($who,$what,$where){
   echo "$who ate a $what, in the $where.";
});

Event::trigger('eat','Simon','Burrito','Kitchen');

// Result : Simon ate a Burrito, in the Kitchen

class Game {
  use Events;
  public static function loadLevel($name){
    ...
    self::trigger("level.loaded", $name);
  }
}

Game::on("level.start",function($level_name){
  echo "Starting {$level_name}, BRING'EM'ON!!!\n";
});

Game::on("level.loaded",function($level_name){
  echo "Reticulating splines for {$level_name}...\n";
  Game::trigger("level.start", $level_name);
});

Game::on("level.start",function($level_name){
  echo "Replenish ammonitions...\n";
});

Game::loadLevel("E1M1");