Pop\Data\Data::writeData PHP Méthode

writeData() public méthode

Write the data stream to a file and either save or output it
public writeData ( string $toFile, boolean $output = false, boolean $download = false ) : Data
$toFile string
$output boolean
$download boolean
Résultat Data
    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;
    }