self = $self; $keys = array( 'sep', 'headers', 'dest_path', 'postfix', 'params', ); global $config; for($i=0, $l=count($keys); $i<$l; $i++) { if(isset($params[$keys[$i]])) { $this->{$keys[$i]} = $params[$keys[$i]]; } elseif(isset($config[$this->self][$keys[$i]])) { $this->{$keys[$i]} = $config[$this->self][$keys[$i]]; } } } protected function preProcess() {} protected function process() { // Do stuff here } protected function postProcess() {} protected function w($line=array()) { fputcsv($this->file, array_values($line), $this->sep); } public function run() { $this->preProcess(); $this->filename = _PS_ROOT_DIR_.$this->dest_path.'/'.date('Y-m-d', mktime()).$this->postfix.'.csv'; touch($this->filename); $this->filename = realpath($this->filename); $this->file = fopen($this->filename, 'w'); $this->w($this->headers); $this->process(); fclose($this->file); $this->postProcess(); } }