File: examples/aggregations/strings.php

Recommend this page to a friend!
  Classes of Nicola Covolo  >  Decorate  >  examples/aggregations/strings.php  >  Download  
File: examples/aggregations/strings.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Decorate
Alter functions running code before and after
Author: By
Last change:
Date: 6 years ago
Size: 609 bytes
 

Contents

Class file image Download
<?php

require "../../Decorate.php";

$function = function ()
{
    return
" World";
}
;
$intercept = function ()
{
    return
"Hello";
}
;
$intercept2 = function ()
{
    return
", I'm Oliver";
}
;

/**
 * echo $function(); //will print " World"
 */


$function = Decorate::onBefore($function, $intercept);
/**
 * echo $function(); //now will print "Hello"
 */


$function = Decorate::onAfter($function, $intercept2);
/**
 * echo $function(); //now will print ", I'm Oliver"
 */


echo $function->getParent()->getPreReturn() . $function->getPreReturn() . $function();
// will print "Hello World, I'm Oliver"


For more information send a message to info at phpclasses dot org.