From b1edce46ffda7a0e2e8e646e0d30bb32d03c0ec1 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sun, 6 Sep 2020 11:12:52 +0300 Subject: [PATCH] cs fix --- application/Espo/Core/Utils/Module.php | 59 ++++++++++++++------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/application/Espo/Core/Utils/Module.php b/application/Espo/Core/Utils/Module.php index af1dcf446e..f10a72e8cd 100644 --- a/application/Espo/Core/Utils/Module.php +++ b/application/Espo/Core/Utils/Module.php @@ -29,6 +29,15 @@ namespace Espo\Core\Utils; +use Espo\Core\{ + Exceptions\Error, + Utils\File\Manager as FileManager, + Utils\File\FileUnifier, +}; + +/** + * Gets module parameters. + */ class Module { private $fileManager; @@ -41,36 +50,24 @@ class Module protected $cacheFile = 'data/cache/application/modules.php'; - protected $paths = array( + protected $paths = [ 'corePath' => 'application/Espo/Resources/module.json', 'modulePath' => 'application/Espo/Modules/{*}/Resources/module.json', 'customPath' => 'custom/Espo/Custom/Resources/module.json', - ); + ]; - public function __construct(File\Manager $fileManager, $useCache = false) + public function __construct(FileManager $fileManager, bool $useCache = false) { $this->fileManager = $fileManager; - $this->unifier = new \Espo\Core\Utils\File\FileUnifier($this->fileManager); + $this->unifier = new FileUnifier($this->fileManager); $this->useCache = $useCache; } - protected function getConfig() - { - return $this->config; - } - - protected function getFileManager() - { - return $this->fileManager; - } - - protected function getUnifier() - { - return $this->unifier; - } - + /** + * Get module parameters. + */ public function get($key = '', $returns = null) { if (!isset($this->data)) { @@ -84,6 +81,9 @@ class Module return Util::getValueByKey($this->data, $key, $returns); } + /** + * Get parameters of all modules. + */ public function getAll() { return $this->get(); @@ -92,16 +92,19 @@ class Module protected function init() { if (file_exists($this->cacheFile) && $this->useCache) { - $this->data = $this->getFileManager()->getPhpContents($this->cacheFile); - } else { - $this->data = $this->getUnifier()->unify($this->paths, true); + $this->data = $this->fileManager->getPhpContents($this->cacheFile); - if ($this->useCache) { - $result = $this->getFileManager()->putPhpContents($this->cacheFile, $this->data); - if ($result == false) { - throw new \Espo\Core\Exceptions\Error('Module - Cannot save unified modules.'); - } + return; + } + + $this->data = $this->unifier->unify($this->paths, true); + + if ($this->useCache) { + $result = $this->fileManager->putPhpContents($this->cacheFile, $this->data); + + if ($result === false) { + throw new Error('Module: Could not save unified module data.'); } } } -} \ No newline at end of file +}