PHP Classes

File: demos/filters_functions.php

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

Contents

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

use
Redbox\Hooks\Filters;

require
'autoload.php';

/**
 * This function will return '@@This is a text';
 *
 * @param string $text
 * @return string
 */
function prependAt($text = '')
{
    return
'@@' . $text;
}

/**
 * If you are using your own custom namespace it is highly important
 * to prefix your functions with a the correct namespace.
 */
Filters::addFilter('prepend_at', 'Sandbox\Demos\prependAt');
$out = Filters::applyFilter('prepend_at', 'This is a text');

/**
 * 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('prepend_at');