* @copyright Copyright (c) 2008-9 TypeOneError Studios (http://www.typeoneerror.com) * @license MIT ~ http://www.opensource.org/licenses/mit-license.php * @version $Id$ * @link http://typeoneerror.com/asra * @category Asra * @package Export */ /** * @see Asra_Export_Data */ require_once "Asra/Export/Data.php"; /** * @see Asra_Export_Data_Interface */ require_once "Asra/Export/Data/Interface.php"; /** * @see Asra_Export_Interface */ require_once "Asra/Export/Interface.php"; /** * Base abstract class for exports. Extend this class * and register your new class with Asra_Export_Registry in * order to utilize it in an API build. * * @author Ben Borowski * @copyright Copyright (c) 2008-9 TypeOneError Studios (http://www.typeoneerror.com) * @license MIT ~ http://www.opensource.org/licenses/mit-license.php * @link http://typeoneerror.com/asra * @category Asra * @package Export */ abstract class Asra_Export_Abstract implements Asra_Export_Interface { //--------------------------------------- // PROTECTED VARIABLES //--------------------------------------- /** * Save the data * * @var object */ protected $_data; /** * There was an error * * @var bool */ protected $_errorOccurred = false; /** * Stores strings for export while looping * * @var string */ protected $_exportStr = ""; /** * Type of export * * @var string */ protected $_type; //--------------------------------------- // CONSTRUCTOR //--------------------------------------- /** * Sets the data and error status. * * @param mixed $data Data to export * @param bool $isError Whether the data contains an error * @return void */ public function __construct($data, $isError = false) { if (!($data instanceof Asra_Export_Data_Interface)) { if (is_array($data)) { // -- convert array to Asra_Export_Data $data = new Asra_Export_Data($data); } else { require_once "Asra/Export/Exception.php"; throw new Asra_Export_Exception("Arguement 1 (data) must be of type `Asra_Export_Data_Interface` or `Array`"); } } $this->setData($data); $this->isError($isError); } //--------------------------------------- // METHODS //--------------------------------------- /** * Show the string. * * @return string */ public function export() { return $this->_exportStr; } /** * Get the data object. * * @return Asra_Export_Data_Interface */ public function getData() { return $this->_data; } /** * Sets a flag indicating that an error occurred. * * @param bool $value Sets the error status * @return Asra_Export_Abstract */ public function isError($value = false) { $this->_errorOccurred = $value; return $this; } /** * Set the data to export. * * @param $value Data to set * @return Asra_Export_Abstract */ public function setData(Asra_Export_Data_Interface $value) { $this->_data = $value; return $this; } /** * Returns the data string. * * @return string */ public function toString() { return $this->_exportStr; } }