PHP Classes

File: demos/filters_annotation.php

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

Contents

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

use
Redbox\Hooks\Filters;

/*
 * Please note: This use statement is actualy required.
 * Without this use statement Filters::registerFilterObject
 * will not work.
 */
use Redbox\Hooks\Annotations\Filter;

require
'autoload.php';

class
Test
{
   
/**
     * This function is going to be called second
     * It has priority 1.
     *
     * @Filter("prepend_at", priority=1)
     * @param string $text
     * @return string
     */
   
public function prependAt($text = '')
    {
        return
'@' . $text;
    }

   
/**
     * This is the first function going to be called.
     * It has priority 0.
     *
     * @Filter("prepend_at", priority=0)
     * @param string $text
     * @return string
     */
   
public function prependAtSecond($text = '')
    {
        return
'!!' . $text;
    }
}
Filters::registerFilterObject(new Test());

/**
 * The result should be:
 *
 * Result: @!!Hello world
 */
echo "Result: ".Filters::applyFilter('prepend_at', 'Hello world');

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