*/ abstract class Mage_ImportExport_Model_Export_Adapter_Abstract { /** * Destination file path. * * @var string */ protected $_destination; /** * Header columns names. * * @var array */ protected $_headerCols = null; /** * Adapter object constructor. * * @param string $destination OPTIONAL Destination file path. * @throws Exception * @return void */ final public function __construct($destination = null) { if (!$destination) { $destination = tempnam(sys_get_temp_dir(), 'importexport_'); } if (!is_string($destination)) { Mage::throwException(Mage::helper('importexport')->__('Destination file path must be a string')); } $pathinfo = pathinfo($destination); if (empty($pathinfo['dirname']) || !is_writable($pathinfo['dirname'])) { Mage::throwException(Mage::helper('importexport')->__('Destination directory is not writable')); } if (is_file($destination) && !is_writable($destination)) { Mage::throwException(Mage::helper('importexport')->__('Destination file is not writable')); } $this->_destination = $destination; $this->_init(); } /** * Method called as last step of object instance creation. Can be overridden in child classes. * * @return Mage_ImportExport_Model_Export_Adapter_Abstract */ protected function _init() { return $this; } /** * Get contents of export file. * * @return string */ public function getContents() { return file_get_contents($this->_destination); } /** * MIME-type for 'Content-Type' header. * * @return string */ public function getContentType() { return 'application/octet-stream'; } /** * Return file extension for downloading. * * @return string */ public function getFileExtension() { return ''; } /** * Set column names. * * @param array $headerCols * @throws Exception * @return Mage_ImportExport_Model_Export_Adapter_Abstract */ public function setHeaderCols(array $headerCols) { if (null !== $this->_headerCols) { Mage::throwException(Mage::helper('importexport')->__('Header column names already set')); } if ($headerCols) { foreach ($headerCols as $colName) { $this->_headerCols[$colName] = false; } fputcsv($this->_fileHandler, array_keys($this->_headerCols), $this->_delimiter, $this->_enclosure); } return $this; } /** * Write row data to source file. * * @param array $rowData * @return Mage_ImportExport_Model_Export_Adapter_Abstract */ abstract public function writeRow(array $rowData); }