Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Write JSON encoded data to disk.
*/
protected function writeJson($filename, $data) {
if (!file_exists($this->getJsonDirectory())) {
if (!drush_mkdir($this->getJsonDirectory())) {
return drush_set_error('NO_JSON_DIR', dt('Unable to create JSON directory at !file', array('!file' => $this->getJsonDirectory())));
}
}
// Remove headers.
array_shift($data);
$json_filename = str_replace('xml', 'json', $filename);
$file = $this->getJsonDirectory() . '/' . $json_filename;
if (file_exists($file)) {
unlink($file);
}
$json_data = json_encode($data);
if (!file_put_contents($file, $json_data)) {
return drush_set_error(dt('Failed to write JSON for file !file', array('!file' => $json_filename)));
}
drush_log(dt('Wrote JSON to file !file', array('!file' => $file)), 'ok');
return TRUE;
}
@phucle2901

This comment has been minimized.

Copy link

@phucle2901 phucle2901 commented Oct 16, 2014

fdg g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment