<?php
/** @see FLY_Func_Interface */
require_once 'FLY/Func/Interface.php';
/**
* This class can be used to register and call global functions.
*
* @package FLY
* @subpackage Func
* @author Yves Feupi Lepatio
*/
class FLY_Func_Function implements FLY_Func_Interface
{
/**
* The reflection function.
* @var ReflectionFunction
*/
protected $_reflectionFunction = null;
/**
* getReflectionFunction()
*
* @return ReflectionFunction
*/
public function getReflectionFunction()
{
return $this->_reflectionFunction;
}
/**
* Constructor
*
* @param string $functionName
* @return void
* @throws FLY_Func_FunctionNotFoundException
*/
public function __construct($functionName)
{
if ( ! function_exists($functionName))
{
/** @see FLY_Func_FunctionNotFoundException */
require_once 'FLY/Func/FunctionNotFoundException.php';
throw new FLY_Func_FunctionNotFoundException(
'The function `' . $functionName . '()` is not found');
}
$this->_reflectionFunction = new ReflectionFunction($functionName);
}
/**
* @see FLY_Func_Interface::invoke()
*/
public function invoke()
{
$params = func_get_args();
$evalParams = '';
for ($i = 0, $length = func_num_args(); $i < $length; $i++)
{
$evalParams .= '$params[' . $i . '], ';
}
$evalParams = substr($evalParams, 0, -2);
return (($evalParams == '')
? $this->_reflectionFunction->invoke()
: $this->_reflectionFunction->invoke(eval('return ' . $evalParams . ';')));
}
}