<?php

/**
 * Response renderer for HTML requests
 *
 * @version DR1.7
 */
class ResponseHTMLBackend extends ResponseBackend {



	public $requireRootView;



	/**
	 * Returns HTTP response in HTML format
	 */
	public function render(ArrayObject $stack) {
		$view = null;
		$js = array();
		foreach ($stack as $entry) {
			list($handler, $args) = $entry;
			if ($handler == 'update') {
				$view = $args[0];
			} else {
				$js[] = $handler . '(' . implode(', ', $this->argsToString($args, true)) . ')';
			}
		}
		if (!$view->isRootView()) {
			if ($this->requireRootView) {
				throw new Exception('root view must be returned');
			}
			$index = new Index();
			$index->add($view);
			$view = $index;
		}
		$view->onLoad = implode('; ', $js);
		return $view->__toString();
	}



} // class ResponseHTMLBackend

?>