PHP Classes

File: examples/intercepting/test3.php

Recommend this page to a friend!
  Classes of Nicola Covolo   Editable   examples/intercepting/test3.php   Download  
File: examples/intercepting/test3.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Editable
Add functions and variables dynamically to objects
Author: By
Last change: Update of examples/intercepting/test3.php
Date: 5 months ago
Size: 728 bytes
 

Contents

Class file image Download
<?php
/**
 * Intercepting dynamic function with another
*/
include("../../Editable.php");
include(
"B.php");


$authorize = function()
{
    echo
"authorizing..<br>";
};
$actionB = function()
{
    echo
"actionB done";
};
$actionBnew = function()
{
    echo
"actionBnew done";
};

$f = new B();
//adding new private dynamic function(will be the interceptor implementation).
$f->addPrivateFunction("authorize",$authorize);
//add the new action
$f->addPublicFunction("actionB",$actionB);
//intercept any call to function "actionB" invoking "authorize"
$f->interceptFunction(array($f,"actionB"),array($f,"authorize"));
//update the action
$f->replaceFunction(array($f,"actionB"),$actionBnew);
//run the action
$f->actionB();


?>