Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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);
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * 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);
     if (empty($decoded) && !is_array($decoded)) {
         $GLOBALS['log']->emergency('Syntax error or empty file - ' . Utils\Util::concatPath($folderPath, $fileName));
     } else {
         //Default values
         if (is_string($defaults) && !empty($defaults)) {
             $defType = $defaults;
             unset($defaults);
             $name = $this->getFileManager()->getFileName($fileName, '.json');
             $defaults = $this->loadDefaultValues($name, $defType);
         }
         $mergedValues = Utils\Util::merge($defaults, $decoded);
         //END: Default values
         return $mergedValues;
     }
     return array();
 }