/** * Load data from a file * * @param string $filePath * @param array $returns * @return array */ protected function loadData($filePath, $returns = array()) { if (file_exists($filePath)) { $content = $this->getFileManager()->getContents($filePath); $data = Json::getArrayData($content); if (empty($data)) { $GLOBALS['log']->warning('FileUnifier::unify() - Empty file or syntax error - [' . $filePath . ']'); return $returns; } return $data; } return $returns; }
/** * Unset some element of content data * * @param string | array $path * @param array | string $unsets * @return bool */ public function unsetContents($path, $unsets, $isJSON = true) { $currentData = $this->getContents($path); if ($currentData == false) { $GLOBALS['log']->notice('FileManager::unsetContents: File [' . $this->concatPaths($path) . '] does not exist.'); return false; } $currentDataArray = Utils\Json::getArrayData($currentData); $unsettedData = Utils\Util::unsetInArray($currentDataArray, $unsets, true); if (is_null($unsettedData) || is_array($unsettedData) && empty($unsettedData)) { $fullPath = $this->concatPaths($path); return $this->unlink($fullPath); } if ($isJSON) { return $this->putContentsJson($path, $unsettedData); } return $this->putContents($path, $unsettedData); }
/** * Helpful method for get content from files for unite Files * * @param string | array $paths * @param string | array() $defaults - It can be a string like ["metadata","layouts"] OR an array with default values * * @return array */ protected function unifyGetContents($paths, $defaults) { $fileContent = $this->getFileManager()->getContents($paths); $decoded = Utils\Json::getArrayData($fileContent, null); if (!isset($decoded)) { $GLOBALS['log']->emergency('Syntax error in ' . Utils\Util::concatPath($paths)); return array(); } return $decoded; }