PHP Classes

File: demos/filters_chaining.php

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

Contents

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

use
Redbox\Hooks\Filters;

require
'autoload.php';

/**
 * This is the first registered filter. It's going to prepend
 * '@@' in front of the text.
 */
Filters::addFilter('prepend_at', function ($text = '') {
    return
'@@' . $text;
});

/**
 * This is the second registered filter. It's going to append
 * '@@' to the text.
 */
Filters::addFilter('append_at', function ($text = '') {
    return
$text . '@@';
});

/**
 * The result should be
 *
 * Result: @@This is a text@@
 *
 */
$out = Filters::applyFilter(['prepend_at', 'append_at'], '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('prepend_at');
Filters::removeAllFilters('append_at');