<?php
if(!defined('CTRL'))
{
	exit();
}
/**
* CtrlComponent
*
* Component will manage the magic methodis __set and __get for as propertys
*
* @date 9.03.2007
* @name CtrlComponent
* @author Margo Poolak <margo 'dot' poolak 'at' gmail 'dot' com>
* @copyright Copyright &copy;2007 Margo Poolak. All Rights Reserved.
* @version 2.0
* @package System
* @category 
*
*/
class CtrlComponent
{
	/**
	* Dummy construct
	*/
	public function __construct()
	{
		$this->execute();
	}
	/**
	* Setter for components
	* Will set class variables:
	* <code>
	* $this->DefaultPage = 'DefaultPage'; 
	*  //will use:
	* $this->SetDefaultPage($value);
	* </code>
	* @param string $var variable name
	* @param string $value variable value
	*/
	public function __set($var,$value)
	{
		$setter = 'set'.$var;
		/*
		* If has setter method then sets the value to it
		* If not then sets a new property to application
		*/
		if(method_exists($this,$setter))
		{
			$this->$setter($value);
		}
		else
		{
			Ctrl::getApplication()->setProperty($var,$value);
		}
	}
	/**
	* Getter for component
	* Can use as:
	* <code>
	* $this->Request->ConstructUrl();
	* //Uses this method as:
	* return $this->GetRequest()->ConstructUrl();
	* //If that method doesnt exists then uses application property as
	* Ctrl::GetApplication()->GetProperty($var);
	*</code>
	* @param string $var variable name
	*/	
	public function __get($var)
	{
		$getter = 'get'.$var;
		/*
		* If found getter method from component then use it
		* If no getter found then use application property getter
		*/		
		if(method_exists($this,$getter))
		{
			return $this->$getter();
		}
		else
		{
			return Ctrl::getApplication()->getProperty($var);
		}
	}
	/**
	* Getter for Response
	* @return object CtrlHttpResponse
	*/	
	public function getResponse()
	{
		return Ctrl::getApplication()->getResponse();
	}
	/**
	* Getter for Request
	* @return object CtrlHttpRequest
	*/	
	public function getRequest()
	{
		return Ctrl::getApplication()->getRequest();
	}
	/**
	* Getter for Session
	* @return object CtrlHttpSession
	*/
	public function getSession()
	{
		return Ctrl::getApplication()->getSession();
	}
	/**
	* Getter for Cookie
	* @return object CtrlHttpCookie
	*/	
	public function getCookie()
	{
		return Ctrl::getApplication()->getCookie();
	}	
	/**
	* Returns application object
	* @return object CtrlApplication
	*/
	public function getSystem()
	{
		return Ctrl::getApplication();
	}
	/**
	* Ends the component life
	*/
	public function __destruct()
	{
	}
}
?>