PHP Classes

File: demos/actions_chaining.php

Recommend this page to a friend!
  Classes of Johnny Mast  >  PHP Filters and Actions  >  demos/actions_chaining.php  >  Download  
File: demos/actions_chaining.php
Role: Example script
Content type: text/plain
Description: Auxiliary script
Class: PHP Filters and Actions
Listen to events and execute registered actions
Author: By
Last change:
Date: 5 years ago
Size: 544 bytes
 

Contents

Class file image Download
<?php
namespace Sandbox\Demos;

require
'autoload.php';

use
Redbox\Hooks\Actions;

Actions::addAction('say_hi', function ($name = '') {
    echo
"Hi: " . $name . "\n";
    return
$name;
});

Actions::addAction('say_bye', function ($name = '') {
    echo
"Bye: " . $name . "\n";
    return
$name;
});

/**
 * Result should be:
 *
 * Hi: GitHub
 * Bye: GitHub
 *
 */
Actions::doAction(['say_hi', 'say_bye'], 'GitHub');

/**
 * This is not required in your code. I have to add this to reset my unit tests.
 */
Actions::removeAllActions('say_hi');