/** * @see \Bolt\Database\Migration\File\MigrationFileInterface::addRecord() */ public function addRecord(array $data, $last) { // Generate the YAML string try { // Add the record as an indexed array of itself as we're writing @author gawain // recorc/row at a time and… YAML. $yaml = $this->dumper->dump(array($data), 4); } catch (\Exception $e) { $this->export->setError(true)->setErrorMessage("Unable to generate valid YAML data!"); return false; } $file = (string) $this->file; if (file_put_contents($file, $yaml, FILE_APPEND) === false) { $this->export->setError(true)->setErrorMessage("Unable to write YAML data to '{$file}'!"); return false; } return true; }
/** * @see \Bolt\Database\Migration\File\MigrationFileInterface::addRecord() */ public function addRecord(array $data, $last) { if (!$this->open) { $this->openJsonArray(); } // Generate the JSON string $json = json_encode($data, JSON_PRETTY_PRINT); if ($json === false) { $this->export->setError(true)->setErrorMessage("Unable to generate valid JSON data!"); return false; } elseif (!$last) { $json .= ",\n"; } $file = (string) $this->file; if (file_put_contents($file, $json, FILE_APPEND) === false) { $this->export->setError(true)->setErrorMessage("Unable to write JSON data to '{$file}'!"); return false; } return true; }