Login   Register  
PHP Classes
elePHPant
Icontem

File: src/eMacros/Runtime/Callback/CallFunctionArray.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Emmanuel Antico  >  eMacros  >  src/eMacros/Runtime/Callback/CallFunctionArray.php  >  Download  
File: src/eMacros/Runtime/Callback/CallFunctionArray.php
Role: Class source
Content type: text/plain
Description: Class source
Class: eMacros
PHP LISP language interpreter
Author: By
Last change:
Date: 2014-01-13 05:23
Size: 941 bytes
 

Contents

Class file image Download
<?php
namespace eMacros\Runtime\Callback;

use 
eMacros\Applicable;
use 
eMacros\Scope;
use 
eMacros\GenericList;

class 
CallFunctionArray implements Applicable {
    public function 
apply(Scope $scopeGenericList $arguments) {
        if (
count($arguments) == 0) {
            throw new \
BadFunctionCallException("CallFunctionArray: No parameters found.");
        }
        
        
$callback $arguments[0]->evaluate($scope);
        
        
//check for valid callback
        
if (!is_callable($callback)) {
            throw new \
InvalidArgumentException("CallFunctionArray: Argument is not a valid callback.");
        }
        
        if (
count($arguments) > 1) {
            
$args $arguments[1]->evaluate($scope);
            
            if (!
is_array($args)) {
                throw new \
InvalidArgumentException(sprintf("CallFunctionArray: An array was expected as second argument but %s found instead."gettype($args)));
            }
            
            return 
call_user_func_array($callback$args);
        }
        
        return 
call_user_func_array($callback, array());
    }
}
?>