<?php

/**
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package fusionLib
 * @copyright Copyright (c) 2011 - 2013 fusionLib. All rights reserved.
 * @link http://fusionlib.com
 */

/**
 * flFormDecoratorList Class
 *
 * Manage a list of decorators and apply them to content.
 *
 * @package fusionLib
 */
class flFormDecoratorList {

	/**
	 * The decorators.
	 *
	 * @var array
	 */
	private $decorators;

	/**
	 * Construct the object.
	 */
	function __construct() {
		$this->decorators = func_get_args();
	}

	/**
	 * Add a decorator to the list.
	 *
	 * @param flFormDecorator The decorator to add.
	 * @return flFormDecoratorList This object.
	 */
	function addDecorator($decorator) {
		$this->decorators[] = $decorator;
		return $this;
	}

	/**
	 * Clear all current decorators.
	 *
	 * @return flFormDecoratorList This object.
	 */
	function clear() {
		$this->decorators = array();
		return $this;
	}

	/**
	 * Decorate the given content.
	 *
	 * @param mixed $elem The element being decorated.
	 * @param string $content The content for the element e.g. <input ...>
	 * @return string The decorated element
	 */
	function decorate($elem, $content) {
		foreach($this->decorators as $d)
			$content = $d->decorate($elem, $content);
		return $content;
	}
}
