public function writeData($toFile, $output = false, $download = false)
{
$file = new \Pop\File\File($toFile);
$to = strtolower($file->getExt()) == 'yml' ? 'yaml' : strtolower($file->getExt());
$types = array('csv', 'json', 'sql', 'xml', 'yaml');
if (!in_array($to, $types)) {
throw new Exception('That data type is not supported.');
}
$class = 'Pop\\Data\\Type\\' . ucfirst($to);
if ($to == 'sql') {
$this->file = $class::encode($this->data, $this->table, $this->idQuote);
} else {
if ($to == 'xml') {
$this->file = $class::encode($this->data, $this->table, $this->pma);
} else {
$this->file = $class::encode($this->data);
}
}
$file->write($this->file);
// Output or save file
if ($output) {
$file->output($download);
} else {
$file->save();
}
return $this;
}