PHP Classes

File: demos/actions_classes.php

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

Contents

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

require
'autoload.php';

use
Redbox\Hooks\Actions;

class
Action
{


   
/**
     */
   
public function firstFunc()
    {
        echo
"Called first\n";
    }

   
/**
     */
   
public function secondFunc()
    {
        echo
"Called second\n";
    }

   
/**
     * Register and call the actions.
     *
     * @return string
     */
   
public function execute()
    {
       
Actions::addAction('say_hello', [$this, 'firstFunc'], 0);
       
Actions::addAction('say_hello', [$this, 'secondFunc'], 1);
        return
Actions::doAction('say_hello');
    }
}

$instance = new Action;
/**
 * Result should be:
 *
 * Called first
 * Called second
 *
 */
$instance->execute();

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