application/Espo/Core/Utils/File/Manager.php
public function mergeContents($path, $content, $isReturnJson = false, $removeOptions = null, $isPhp = false)
    {
        if ($isPhp) {
            $fileContent = $this->getPhpContents($path);
        } else {
            $fileContent = $this->getContents($path);
        }

        $fullPath = $this->concatPaths($path);
        if (file_exists($fullPath) && ($fileContent === false || empty($fileContent))) {
            throw new Error('FileManager: Failed to read file [' . $fullPath .'].');
        }

        $savedDataArray = Utils\Json::getArrayData($fileContent);
        $newDataArray = Utils\Json::getArrayData($content);

        if (isset($removeOptions)) {
            $savedDataArray = Utils\Util::unsetInArray($savedDataArray, $removeOptions);
            $newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions);
        }

        $data = Utils\Util::merge($savedDataArray, $newDataArray);

        if ($isReturnJson) {
            $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }

        if ($isPhp) {
            return $this->putPhpContents($path, $data);
        }

        return $this->putContents($path, $data);
    }
public function mergeContents($path, $content, $isReturnJson = false, $removeOptions = null, $isPhp = false)
    {
        if ($isPhp) {
            $fileContent = $this->getPhpContents($path);
        } else {
            $fileContent = $this->getContents($path);
        }

        $fullPath = $this->concatPaths($path);
        if (file_exists($fullPath) && ($fileContent === false || empty($fileContent))) {
            throw new Error('FileManager: Failed to read file [' . $fullPath .'].');
        }

        $savedDataArray = Utils\Json::getArrayData($fileContent);
        $newDataArray = Utils\Json::getArrayData($content);

        if (isset($removeOptions)) {
            $savedDataArray = Utils\Util::unsetInArray($savedDataArray, $removeOptions);
            $newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions);
        }

        $data = Utils\Util::merge($savedDataArray, $newDataArray);

        if ($isReturnJson) {
            $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }

        if ($isPhp) {
            return $this->putPhpContents($path, $data);
        }

        return $this->putContents($path, $data);
    }
public function mergeContents ( $ path , $ content , $ isReturnJson = false , $ removeOptions = null , $ isPhp = false ) { if ( $ isPhp ) { $ fileContent = $ this -> getPhpContents ( $ path ) ; } else { $ fileContent = $ this -> getContents ( $ path ) ; } $ fullPath = $ this -> concatPaths ( $ path ) ; if ( file_exists ( $ fullPath ) && ( $ fileContent === false || empty ( $ fileContent ) ) ) { throw new Error ( 'FileManager: Failed to read file [' . $ fullPath . '].' ) ; } $ savedDataArray = Utils \ Json :: getArrayData ( $ fileContent ) ; $ newDataArray = Utils \ Json :: getArrayData ( $ content ) ; if ( isset ( $ removeOptions ) ) { $ savedDataArray = Utils \ Util :: unsetInArray ( $ savedDataArray , $ removeOptions ) ; $ newDataArray = Utils \ Util :: unsetInArray ( $ newDataArray , $ removeOptions ) ; } $ data = Utils \ Util :: merge ( $ savedDataArray , $ newDataArray ) ; if ( $ isReturnJson ) { $ data = Utils \ Json :: encode ( $ data , JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) ; } if ( $ isPhp ) { return $ this -> putPhpContents ( $ path , $ data ) ; } return $ this -> putContents ( $ path , $ data ) ; }
Merge file content and save it to a file

@param string | array $path
@param string $content JSON string
@param bool $isReturnJson
@param string | array $removeOptions - List of unset keys from content
@param bool $isPhp - Is merge php files

@return bool | array
Merge file content and save it to a file