<?php
/**
 * This file is part of the set of generic classes available for implementations
 * of the DDR Simple API to speed up implementation. It contains a generic
 * implementation of the {@link Evidence} interface.
 * 
 * @author Sylvain Lequeux
 * @author Francois Daoust <fd@w3.org>
 * @package AskPythia
 * @subpackage Implementation
 * @version $Revision: 1.9 $
 * @license http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.html W3C Software Notice and License
 * @copyright Copyright (c) 2009, W3C (MIT, ERCIM, Keio)
 */

/**
 * Include the {@link Evidence} interface description.
 */
require_once(dirname(__FILE__).'/../../interface/evidence.php');
/**
 * Include the {@link SystemException} class description.
 */
require_once(dirname(__FILE__).'/../../interface/systemException.php');

/**
 * A basic {@link Evidence} consists of HTTP header name and value pairs.
 * 
 * HTTP header names are treated in a case-insensitive way.
 * HTTP header values are stored untouched.
 * 
 * @author Sylvain Lequeux
 * @author Francois Daoust <fd@w3.org>
 * @package AskPythia
 * @subpackage Implementation
 * @link http://www.w3.org/TR/DDR-Simple-API/ Device Description Repository Simple API
 * @version $Revision: 1.9 $
 * @license http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231.html W3C Software Notice and License
 * @copyright Copyright (c) 2009, W3C (MIT, ERCIM, Keio)
 */
class BasicEvidence implements Evidence{
	/**
	 * @var array(string=>string) The key/value pairs that compose the evidence.
	 * @access private
	 */
	private $evidences;
	
	/**
	 * Creates an instance of the BasicEvidence class.
	 * 
	 * @access public
	 */
	public function __construct() {
		$this->evidences = array();
	}
	
	public function get($key){
		if(!isset($key)){
			throw new SystemException(
				"The key to retrieve cannot be null",
				SystemException::$ILLEGAL_ARGUMENT);
		}
		
		if(!$this->exists($key)){
			throw new SystemException(
				"The key to retrieve doesn't exist.",
				SystemException::$ILLEGAL_ARGUMENT);
		}
		
		return $this->evidences[strtolower($key)];
	}
	
	public function exists($key){
		if(!isset($key)){
			throw new SystemException(
				"The key to check cannot be null",
				SystemException::$ILLEGAL_ARGUMENT);
		}
		return array_key_exists(strtolower($key), $this->evidences);
	}
	
	public function put($key, $value){
		if(!isset($key)){
			throw new SystemException(
				"The key cannot be null",
				SystemException::$ILLEGAL_ARGUMENT);
		}
		
		if(!isset($value)){
			throw new SystemException(
				"The value cannot be null",
				SystemException::$ILLEGAL_ARGUMENT);
		}
		
		$this->evidences[strtolower($key)] = $value;
	}
}

?>