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

Recommend this page to a friend!
  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: 7 years ago
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 $scope, GenericList $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());
    }
}
?>

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