<?php
//
// +----------------------------------------------------------------------+
// | PHP Version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license,      |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de>               |
// +----------------------------------------------------------------------+
//
// $Id: $
//

/**
* HTTP::GET_Validator
*
* Train implementation of Thies's idea in Brussles :-)
*/
class HTTP_GET_Validator {
    var $parameters;
    var $types;

    /**
    * Constructor.
    *
    * @param  array
    * @param  array
    * @access public
    */
    function HTTP_GET_Validator($parameters = array(), $types = array()) {
        $this->parameters = $parameters;
        $this->types      = $types;
    }

    /**
    * Returns validated $_GET array.
    *
    * @return array
    * @access public
    */
    function validate() {
        $validated_parameters = array();

        foreach ($_GET as $name => $value) {
            if ( isset($this->parameters[$name]) &&
                ($this->parameters[$name] === false ||
                 preg_match($this->parameters[$name], $value)
                )
               )
            {
                $validated_parameters[$name] = $value;
            }
        }

        return $validated_parameters;
    }

    /**
    * Adds a parameter.
    *
    * @param  string
    * @param  mixed
    * @access public
    */
    function add_parameter($name, $type = false) {
        $this->parameters[$name] = $type;
    }

    /**
    * Adds a type definition.
    *
    * @param  string
    * @param  string
    * @access public
    */
    function add_type($name, $regex) {
        $this->types[$name] = $regex;
    }
}
?>
