<?php
/**
 * @package XCube
 * @version $Id: XCube_Utils.class.php,v 1.1.2.4 2006/10/27 11:45:05 minahito Exp $
 */

/**
 * The utility class.
 */
class XCube_Utils
{
	/**
	Display redirect message and execute redirect.
	You can not continue your routine, because this method call exit().
	
	@todo I must solve direct HTML code.
	@param $url string
	@param $time intval
	@param $message If you want to multiline message, you must set message as array.
	
	@deprecated Don't use static function of XCube layer for redirect.
	 */
	function redirectHeader($url, $time, $messages = null)
	{
		$root =& XCube_Root::getSingleton();
		$root->mController->executeRedirect($url, $time, $messages);
	}
	
	function formatMessage()
	{
		$arr = func_get_args();
		
		if(count($arr)==0)
			return null;
		
		$message = $arr[0];
		for($i = 1; $i < count($arr); $i++) {
			$message = str_replace("{" . ($i-1) . "}", $arr[$i], $message);
		}
		
		return $message;
	}
	
	/**
	 * @deprecated
	 */
	function formatMessageByMap($subject,$arr)
	{
		$searches=array();
		$replaces=array();
		foreach($arr as $key=>$value) {
			$searches[]="{".$key."}";
			$replaces[]=$value;
		}

		return str_replace($searches,$replaces,$subject);
	}
}

?>