Location: PHPKode > projects > PWF > PWF_0.3.0/Core/Post.php
<?php
/**
 * _Core_Post is the class to access $_POST array and has some utilities over it
 * @copyright	Copyright (c) 2012, PWF
 * @license		http://phpwebframework.com/License 
 * @version PWF_0.3.0
 */
class _Core_Post
{
  /**
   * Returns if there is post data
   * @return boolean
   */
  public function isEmpty() 
  {
  	return $this->size()==0?true:false; 
  }	
  
  /**
   * Returns if the post data array contains the given key
   * @param string $key
   */
  public function containsKey($key)
  {
  	return isset($_POST[$key]); 
  }
  
  /**
   * Returns the value trimed of the post data array in the key that is given 
   * or null if the key don't exists
   * @param string $key
   * @return null,string
   */
  public function get($key)
  {
    return $this->containsKey($key)?is_string($_POST[$key])?trim($_POST[$key]):$_POST[$key]:null;
  }
	
  /**
   * Returns the size of the post data array
   * @return number
   */
  public function size() 
  {
  	return count($_POST); 
  }
  
  /**
   * Returns a PWF Post List if exists else null 
   * (e.g. if there is $_POST["id_1"]=33 and $_POST["id_2"]=18 and is called 
   * with key "id" it will return array(1=>33,2=>18) ) 
   * @param string $key
   * @return null,array
   */
  public function getList($key)
  {
  	$result = array(); 
  	$check = $key."_";
  	foreach($_POST as $name => $value)
  	{
  		if(strlen($name) > strlen($check) && substr($name, 0,strlen($check)) == $check)
  		{
  		  $id = substr($name,strlen($check));
  		  $result[$id] = trim($value); 
  		}
  	}
  	if(count($result)==0)
  	{
  		$result = null;
  	}
  	return $result; 
  }
  
  /**
   * It will remove a PWF Post List from post data if exists 
   * @see above 
   * @param string $key
   */
  public function removeList($key)
  {
  	$postList = $this->getList($key);
  	if(count($postList) > 0)
  	{
  		foreach ($postList as $key => $value)
  		{
  			unset($_POST[$key."_".$key]);
  		}
  	}
  }
}
?>
Return current item: PWF