<?php
/**
 * Improved handling for request payload
 *
 * @author Ronald Vilbrandt <info@rvi-media.de>
 * @copyright 2013 Ronald Vilbrandt, RVI-Media (www.rvi-media.de)
 * @since 2013-01-18 
 */
namespace aRvi\ClientRequest;

class ClientRequest implements \Iterator {
    
    public $boolTriggerErrors = true;
    
    protected $arrPayload = array();
    
    /**
     * Constructor 
     * 
     * @param array $arrPayload Payload
     */
    public function __construct(array $arrPayload = array()) {
        $this->arrPayload = $arrPayload;
    }
    
    /**
     * Sets value for payload
     * 
     * @param string $strName Name
     * @param mixed $mixedValue Value
     * @return mixed Value
     */
    public function __set($strName, $mixedValue) {
        $this->arrPayload[$strName] = $mixedValue;
    }
    
    /**
     * Returns value from payload
     * 
     * @param string $strName Name
     * @return mixed Value
     */
    public function __get($strName) {
        return true === isset($this->arrPayload[$strName]) ? $this->arrPayload[$strName] : null;
    }
    
    /**
     * Returns whether a name exists or not
     * 
     * @param string $strName
     * @return boolean true
     */
    public function __isset($strName) {
        return true === isset($this->arrPayload[$strName]);
    }
    
    /**
     * Returns payload as array
     * 
     * @return array Payload
     */
    public function toArray() {
        return $this->arrPayload;
    }
    
    /**
     * Rewind container
     */
    public function rewind() {
        return reset($this->arrPayload);
    }

    /**
     * Returns current element
     * 
     * @return mixed Element
     */
    public function current() {
        return current($this->arrPayload);
    }

    /**
     * Returns current key
     * 
     * @return mixed Key
     */
    public function key() {
        return key($this->arrPayload);
    }

    /**
     * Returns next element
     * 
     * @return mixed Element 
     */
    public function next() {
        return next($this->arrPayload);
    }

    /**
     * Returns whether an element is valid or not
     * 
     * @return boolean true
     */
    public function valid() {
        return null !== key($this->arrPayload);
    }
    
}
