PHP Classes

File: src/eMacros/Runtime/Type/IsType.php

Recommend this page to a friend!
  Classes of Emmanuel Antico   eMacros   src/eMacros/Runtime/Type/IsType.php   Download  
File: src/eMacros/Runtime/Type/IsType.php
Role: Class source
Content type: text/plain
Description: Class source
Class: eMacros
PHP LISP language interpreter
Author: By
Last change:
Date: 10 years ago
Size: 800 bytes
 

Contents

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

use
eMacros\Runtime\GenericFunction;

class
IsType extends GenericFunction {
   
/**
     * Callback to invoke
     * @var callable
     */
   
public $callback;
       
    public function
__construct($callback) {
       
$this->callback = $callback;
    }
   
   
/**
     * Determines if a value is of a given type
     * Usage: (integer? 'hey') (string? _val) (null? _val1 _val2)
     * Returns: boolean
     * (non-PHPdoc)
     * @see \eMacros\Runtime\GenericFunction::execute()
     */
   
public function execute(array $arguments) {
       
//check number of parameters
       
if (empty($arguments)) {
            throw new \
BadFunctionCallException("IsType: No arguments found.");
        }
       
        foreach (
$arguments as $arg) {
            if (
call_user_func($this->callback, $arg) === false) {
                return
false;
            }
        }
       
        return
true;
    }
}
?>