SnapAuthenticationAction

<?php require_once "autoload.php";

class SnapAuthenticationAction extends ViewAction
{
	protected $username;
	protected $password;
	
	public function __construct($model)
	{
		parent::__construct($model);
		$this->username = $model["username"];
		$this->password = $model["password"];
		$this->view = new SnapAuthenticationView($this);
	}
	
	public function save()
	{
		INFOUT("SnapAuthentication.save");
	}
	
	
	public function getModel()
	{		
		$model["username"] = $this->username;
		$model["password"] = $this->password;
		return $model;
	}
	
	public function login()
	{

		$ret = false;

		do
		{
			$cm = CommunicationManager::getInstance();
			$pm = PersistenceManager::getInstance();
			
			$deviceId = $cm->authenticate($this->username,$this->password);
			if(!$deviceId)
			{
				INFOUT("SnapAuthenticationAction has failed to retrieve a device ID");
			
			}
		

		} while (false);

		$am = ApplicationManager::getInstance();
		return $am->notify("BACK", null);
		
	}

	public function back()
	{
		
		$am = ApplicationManager::getInstance();
		$am->notify("BACK", null);
	}
}
?>

ViewAction

<?php require_once "autoload.php";

abstract class ViewAction extends RouterAction
{
	protected $view;
	
	public abstract function save();
	
	public function execute()
	{
		$this->save();
		
		if (!$this->method)
			$this->method = "view";
		
		parent::execute();
	}
	
	
	public abstract function getModel();
	

	public function view()
	{
		$ret = false;
	
		do
		{
			$err = get_class($this)." - ViewAction:start - ";
		
			if (!$this->view)
			{
				ERROUT($err."no view defined for this action");
				break;
			}
			
			if (!$this->view->compose())
			{
				ERROUT($err."view ".get_class($this->view)." failed to compose");
				break;
			}
	
			$pm = PersistenceManager::getInstance();
			$pm->commit();

			if (!$this->view->render())
			{
				ERROUT($err."view ".get_class($this->view)." failed to render");
				break;
			}
			
			$ret = true;
		} while (false);
		
		return $ret;
	}
	
}
?>

RouterAction

<?php require_once "autoload.php";

abstract class RouterAction extends Action
{
	protected $method;
	protected $methodName;
	protected $args;
	
	public function __construct($model)
	{
		parent::__construct($model);
		do
		{
			$this->method = $model["method"];
			if (!$this->method)
			{
				break;
			}
			


		} while (false);
		
	}
	
	public function execute()
	{

		$ret = false;
		
		do
		{
			if (!$this->method)
			{
				ERROUT(get_class($this).":execute - Method not provided.");
				break;
			}

			$this->methodName = $this->method;

			if (is_array($this->method))
			{
				$this->methodName = reset(array_keys($this->method));
			}
		
			if (!is_string($this->methodName))
			{
				ERROUT(get_class($this)." - RouterAction:__construct - Method name incorrect format.");
				break;
			}

			preg_match("/^([^\(]+)(\((.*)\))?/", $this->methodName, $params);
			if ($params[1] != null)
			{
				$this->methodName = $params[1];
				$this->args = preg_split("/,/", $params[3]);
				
				
				foreach (array_keys($this->args) as $key)
				{
					preg_match("/{(.*)}/", $this->args[$key], $tokens);
					if (!$tokens)
						continue;
					$this->args[$key] = preg_split("/;/", $tokens[1]);
					
				}
			}
		

			$ret = call_user_func_array(array($this, $this->methodName), $this->args);
			
		} while (false);
		
		return $ret;
	}
}

?>

Action

<?php require_once "autoload.php";

abstract class Action extends Bean
{
	protected $action;
	
	public function __construct($model)
	{
		parent::__construct();
		//$this->map_to_vars($model);
	}

	public abstract function execute();
	
	

}
?>

Bean

<?php include_once "autoload.php";

abstract class Bean
{
	public function set($field, &$value) { $this->$field = $value; }
	public function &get($field) { return $this->$field; }

	public function __construct()
	{
	}

	public function map_to_vars(&$map)
	{
		foreach (array_keys(get_object_vars($this)) as $key)
		{
			$this->$key = $map[$key];
		}
	}
}
?>