<?php

/**
 * Context object representing user request
 *
 * Holds the relevant data that came from client.
 * This class implements Singleton design pattern.
 *
 * @version DR1.4
 */
final class RequestContext {



	private $action = '';
	private $args;
	private static $instance;



	/**
	 * Dummy private constructor as in Singleton
	 */
	private function __construct() {

	}



	/**
	 * Returns instance of class
	 */
	public static function getInstance() {
		if (!self::$instance) {
			self::$instance = new RequestContext();
		}
		return self::$instance;
	}



	/**
	 * Returns action string
	 *
	 * @return string
	 */
	public function getAction() {
		return $this->action;
	}



	/**
	 * Returns a collection of arguments
	 *
	 * @return ArrayObject
	 */
	public function getArgs() {
		if (!$this->args) {
			return new ArrayObject();
		}
		return $this->args;
	}



	/**
	 * Fills object with context
	 *
	 * @since DR1.4
	 */
	public function configure($action, ArrayObject $args) {
		$this->action = $action;
		$this->args = $args;
	}



	public function clear() {
		$this->action = null;
		$this->args = null;
	}



} // class RequestContext

?>