SnapAuthenticationView

<?php include_once "autoload.php";
class SnapAuthenticationView extends ToolbarView
{

	public function getTitleComponent()
	{
		return new TitleComponent("Snap Authentication");
	}

	public function getToolbarComponent()
	{
		return new BreadCrumbComponent();
	}

	public function compose()
	{
		$ret = false;
		
		do
		{
			$username = new TextComponent("username", "snap.mattian@monahansen.com");
			$password = new TextComponent("password", "m1t0@sn1p");
			$button = new ButtonComponent("login", "Sign in");
			
			$layout = new VerticalLayout();
			if (!$layout->add($username))
			{
				ERROUT(get_class($this).":compose - Error adding username to layout");
				break;
			}
			if (!$layout->add($password))
			{
				ERROUT(get_class($this).":compose - Error adding password to layout");
				break;
			}
			if (!$layout->add($button))
			{
				ERROUT(get_class($this).":compose - Error adding button to layout");
				break;
			}
			if (!parent::compose())
			{
				ERROUT(get_class($this).":compose - Error composing parent");
				break;
			}
			
			if (!$this->document->add($layout))
			{
				ERROUT(get_class($this).":compose - Error adding layout to document");
				break;
			}

			$ret = true;
			
		} while (false);
		
		return $ret;
	}

}

?>

ToolbarView

<?php include_once "autoload.php";
abstract class ToolbarView extends TitlebarView
{
	public abstract function getToolbarComponent();
	
	public function compose()
	{
		$ret = false;
		
		do
		{
			if (!parent::compose())
			{
				ERROUT(get_class($this).":compose - Error composing parent");
				break;
			}
		
			$toolbar = $this->getToolbarComponent();
			
			if (!$this->document->add($toolbar))
			{
				ERROUT(get_class($this).":compose - Error adding toolbar to document");
				break;
			}
			
			$ret = true;
		} while (false);
		
		return $ret;
	}
}

?>

TitlebarView

<?php include_once "autoload.php";
abstract class TitlebarView extends ContainerComponent
{
	protected $document;
	protected $titlebar;
	protected $action;
	
	public function __construct(&$action)
	{
		$this->action = $action;
			
	}
	
	public function getLeftButtonComponent()
	{
		return new BackButtonComponent("back", "Back");
	}

	public function getRightButtonComponent()
	{
		return new ButtonComponent("done", "Done");
	}
	
	public abstract function getTitleComponent();
	
	public function compose()
	{
		$ret = false;
		
		do
		{
			$this->document = new HtmlDocument($this->action);
			if (!$this->add($this->document))
			{
				ERROUT(get_class($this).":compose - error adding document to view");
				break;
			}
			
			$this->titlebar = new Titlebar($this->getTitleComponent(), $this->getLeftButtonComponent(), $this->getRightButtonComponent());
			if (!$this->document->add($this->titlebar))
			{
				ERROUT(get_class($this).":compose - error adding titlebar to document");
				break;
			}

			$ret = true;

		} while (false);
	
		return $ret;
	}
}

?>

ContainerComponent

<?php require_once "autoload.php";

abstract class ContainerComponent extends Component
{
	protected $componentCollection;

	public function add(&$component)
	{
		$this->componentCollection[] = $component;
		return true;
	}

	public function render()
	{
		parent::render();
		foreach ($this->componentCollection as $component)
		{
			$component->render();
		}
		return true;
	}
}

?>

Component

<?php require_once "autoload.php";

abstract class Component extends Bean
{
	public function render()
	{
/*
		?><a href="Source.php?class=<?=get_class($this)?>" style="color: #888; text-decoration: none; font-family: courier new; font-size: 12pt;" target="_blank">≡</a><?
*/
		return true;
	}

}
?>

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];
		}
	}
}
?>