PHP Classes

File: src/eMacros/Runtime/Filter/FilterVar.php

Recommend this page to a friend!
  Classes of Emmanuel Antico   eMacros   src/eMacros/Runtime/Filter/FilterVar.php   Download  
File: src/eMacros/Runtime/Filter/FilterVar.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: 879 bytes
 

Contents

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

use
eMacros\Runtime\GenericFunction;

class
FilterVar extends GenericFunction {
   
/**
     * Filters a value according to a specified filter
     * Usage: (var 'yes' 'boolean')
     * Returns: mixed
     * (non-PHPdoc)
     * @see \eMacros\Runtime\GenericFunction::execute()
     */
   
public function execute(array $arguments) {
        if (empty(
$arguments)) {
           
//no args
           
throw new \BadFunctionCallException("FilterVar: No parameters found.");
        }
       
        if (!isset(
$arguments[1])) {
           
//no filter defined
           
throw new \BadFunctionCallException("FilterVar: No filter has been defined.");
        }
       
        if (!
in_array($arguments[1], filter_list())) {
           
//unrecognized filter
           
throw new \InvalidArgumentException(sprintf("FilterVar: '%s' is not a valid filter.", strval($arguments[1])));
        }
       
        return
filter_var($arguments[0], filter_id($arguments[1]));
    }
}
?>