Location: PHPKode > scripts > param > paramList.php
<?php
/**
 *  @package Param
 *  @author Domenico Pontari <hide@address.com>
 *  @copyright Copyright (c) 2009, Domenico Pontari
 *  @license http://opensource.org/licenses/bsd-license.php New and Simplified BSD licenses
 *  @version 1.0
 *
 *  If your application is following a REST architecture
 *  (http://en.wikipedia.org/wiki/Representational_State_Transfer)
 *  and you store all the input params in a paramList object,
 *  you'll have an easy way to determinate the state of your application.
 */

    require_once ('param.php');

    /**
      *  @package Param
      */
    class paramList {
        protected $params = array();
        
        function __construct ($params = array()) {
            if ((!empty($params)) && (!$this->set($params)))
                trigger_error ('unableToSetupParamList', E_USER_ERROR);
        }
        
        /**
         *  @param array it can be an array of "param" objects OR an array of arrays
         *  @return bool
         */
        function set ($params) {
            if (!is_array($params)) return false;
            foreach ($params as $param) {
                $el = param::register ($param);
                if ($el === false) return false;
                $this->params[$el->name] = $el;
            }
            return true;
        }
        
        function __get ($paramName) {
            if (!in_array($paramName, array_keys($this->params))) {
                trigger_error ('paramNameNotDefinedInTheList');
                return NULL;
            }
            return $this->params[$paramName]->value;
        }
        
        /**
         *  The state of a param list is defined as the array of all actual
         *  param values
         *
         *  @param bool it true only the minimized state will be returned that
         *  means that all params in which current value is the same of the default value
         *  won't be returned
         */
        function getState ($minimized = true) {
            $result = array();
            foreach ($this->params as $name => $param)
                if (!$minimized || !$param->isInIrrelevantState()) $result[$name] = $param->value;
            return $result;
        }
    }

?>
Return current item: param