File: examples/onBefore/login.php

Recommend this page to a friend!
  Classes of Nicola Covolo  >  Decorate  >  examples/onBefore/login.php  >  Download  
File: examples/onBefore/login.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: 423 bytes
 

Contents

Class file image Download
<?php

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

$login = function ($name)
{
    if (
$name !== 'Oliver')
    {
        throw new
Exception("sorry $name, this secret is not for you!<br>");
    }
}
;

$secret = function ($name)
{
    echo
"welcome to the secret, $name<br>";
}
;

$secret = Decorate::onBefore($secret, $login);

try
{
   
$secret('Oliver');
   
$secret('Giulio');
}
catch (
exception $e)
{
    echo (
$e->getMessage());
}


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