Login   Register  
PHP Classes
elePHPant
Icontem

File: src/eMacros/Runtime/Filter/FilterHasVar.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/Filter/FilterHasVar.php  >  Download  
File: src/eMacros/Runtime/Filter/FilterHasVar.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: 1,070 bytes
 

Contents

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

use 
eMacros\Runtime\GenericFunction;

class 
FilterHasVar extends GenericFunction {
    
/**
     * Filter types
     * @var array
     */
    
public static $filter_types = array(INPUT_GETINPUT_POSTINPUT_COOKIEINPUT_SERVERINPUT_ENVINPUT_SESSION);
    
    
/**
     * Checks whether a given index is defined on a global array
     * Usage: (has-var POST 'message')
     * Returns: boolean
     * (non-PHPdoc)
     * @see \eMacros\Runtime\GenericFunction::execute()
     */
    
public function execute(array $arguments) {
        if (empty(
$arguments)) {
            
//no args
            
throw new \BadFunctionCallException("FilterHasVar: No parameters found.");
        }
        
        if (!isset(
$arguments[1])) {
            
//no filter defined
            
throw new \BadFunctionCallException("FilterHasVar: No filter has been defined.");
        }
        
        if (!
in_array($arguments[0], self::$filter_types)) {
            
//unknown filter
            
throw new \InvalidArgumentException(sprintf("FilterHasVar: Filter type '%s' "strval($arguments[0])));
        }
        
        return 
filter_has_var(self::$filter_types[$arguments[0]], $arguments[1]);
    }
}
?>