<?php

/**
 * Abstract response rendering backend
 *
 * @version DR1.7
 */
abstract class ResponseBackend {



	/**
	 * Returns HTTP response in desired format
	 */
	abstract public function render(ArrayObject $stack);



	protected function argsToString($args, $addQuotes = false) {
		$out = array();
		foreach ((array)$args as $arg) {
			$a = '';
			if (is_string($arg) or is_numeric($arg) or !$arg) {
				$a = $arg;
			} elseif (is_object($arg)) {
				if (method_exists($arg, '__toString')) {
					$a = $arg->__toString();
				} else {
					throw new Exception('cannot convert ' . get_class($arg) . ' to string');
				}
			} else {
				print_r($arg);
				throw new Exception('cannot convert to string');
			}
			$out[] = ($addQuotes and !is_numeric($a)) ? '\'' . addslashes($a) . '\'' : $a;

		}
		return $out;
	}



} // class ResponseBackend

?>