refactoring
This commit is contained in:
@@ -38,6 +38,9 @@ use Espo\Core\{
|
||||
use Exception;
|
||||
use StdClass;
|
||||
use Throwable;
|
||||
use InvalidArgumentException;
|
||||
|
||||
use const E_USER_DEPRECATED;
|
||||
|
||||
class Manager
|
||||
{
|
||||
@@ -171,17 +174,30 @@ class Manager
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads entire file into a string.
|
||||
* Get file contents.
|
||||
*
|
||||
* @param string | array $path Ex. 'path.php' OR array('dir', 'path.php').
|
||||
* @return mixed
|
||||
* @param string
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function getContents($path)
|
||||
{
|
||||
$fullPath = $this->concatPaths($path);
|
||||
if (is_array($path)) {
|
||||
// For backward compatibility.
|
||||
// @todo Remove support of arrays in v6.4.
|
||||
trigger_error(
|
||||
'Array parameter is deprecated for FileMaanger::getContents.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
if (file_exists($fullPath)) {
|
||||
return file_get_contents($fullPath);
|
||||
$path = $this->concatPaths($path);
|
||||
}
|
||||
else if (!is_string($path)) {
|
||||
throw new InvalidArgumentException();
|
||||
}
|
||||
|
||||
if (file_exists($path)) {
|
||||
return file_get_contents($path);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -164,7 +164,7 @@ class Unifier
|
||||
|
||||
} else {
|
||||
if ($fileName === $this->unsetFileName) {
|
||||
$fileContent = $this->fileManager->getContents(array($dirPath, $fileName));
|
||||
$fileContent = $this->fileManager->getContents($dirPath . '/' . $fileName);
|
||||
|
||||
if ($this->useObjects) {
|
||||
$unsets = Json::decode($fileContent);
|
||||
@@ -176,7 +176,7 @@ class Unifier
|
||||
continue;
|
||||
}
|
||||
|
||||
$mergedValues = $this->unifyGetContents([$dirPath, $fileName]);
|
||||
$mergedValues = $this->getContents($dirPath . '/' . $fileName);
|
||||
|
||||
if (!empty($mergedValues)) {
|
||||
$name = $this->fileManager->getFileName($fileName, '.json');
|
||||
@@ -204,9 +204,9 @@ class Unifier
|
||||
/**
|
||||
* Get content from files for unite files.
|
||||
*/
|
||||
protected function unifyGetContents(array $paths)
|
||||
protected function getContents(string $path)
|
||||
{
|
||||
$fileContent = $this->fileManager->getContents($paths);
|
||||
$fileContent = $this->fileManager->getContents($path);
|
||||
|
||||
return Json::decode($fileContent, !$this->useObjects);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user