PHP Classes

File: demos/filters_classes.php

Recommend this page to a friend!
  Classes of Johnny Mast  >  PHP Filters and Actions  >  demos/filters_classes.php  >  Download  
File: demos/filters_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: 829 bytes
 

Contents

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

use
Redbox\Hooks\Filters;

require
'autoload.php';


class
Worker
{

    public function
prependChars($text = '')
    {
        return
'@@' . $text;
    }

    public function
appendChars($text = '')
    {
        return
$text . '@@';
    }

    public function
execute()
    {

       
Filters::addFilter('manipulate_string', [$this, 'prependChars']);
       
Filters::addFilter('manipulate_string', [$this, 'appendChars']);

        return
Filters::applyFilter('manipulate_string', 'This is a text');
    }
}

$worker = new Worker;
$out = $worker->execute();

/**
 * The result should be:
 *
 * Result: @@This is a text@@
 */
echo "Result: " . $out . "\n";

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