Location: PHPKode > scripts > PHP Xforms > php-xforms/PhpXforms/ErrorList.php
<?php

/**
 * Class PhpXforms_ErrorList
 *
 * $Id$
 */

class PhpXforms_ErrorList {

	/**
	 * @var string
	 */
	protected $_encoding = 'utf-8';

	/**
	 * @var array
	 */
	protected $_errorList = array();

	/**
	 * @param string $encoding
	 */
	function __construct($encoding = null)
	{
		if (! empty($encoding))
		{
			$this->_encoding = $encoding;
		}
	}

	/**
	 * @param string $message
	 */
	function push($message)
	{
		$this->_errorList[] = $message;
	}

	/**
	 * Export error-list as XML string, optionally displaying appropriate Content-Type header
	 *
	 * @param bool $displayContentType
	 * @return string XML
	 */
	function toXml($output = true, $displayContentType = true)
	{
		if ($displayContentType && ! headers_sent())
		{
			header('Content-Type: application/xml; charset=' . $this->_encoding);
		}

		$xml  = "<?xml version='1.0' encoding='" . $this->_encoding . "' ?>\n";
		$xml .= "<errorList>";
		foreach ($this->_errorList as $message)
		{
			$xml .= "<error><![CDATA[" . $message . "]]></error>";
		}
		$xml .= "</errorList>";

		if ($output)
		{
			echo $xml;
		}

		return $xml;
	}

}
Return current item: PHP Xforms