module path refactoring

This commit is contained in:
Yuri Kuznetsov
2021-07-01 17:16:57 +03:00
parent ec31075fae
commit cb51839eb9
8 changed files with 55 additions and 18 deletions

3
.gitignore vendored
View File

@@ -18,4 +18,7 @@
/composer.phar
/vendor/
/custom/Espo/Custom/*
/custom/Espo/Modules/*
!/custom/Espo/Custom/.htaccess
!/custom/Espo/Modules/.htaccess
/install/config.php

View File

@@ -101,7 +101,9 @@ module.exports = grunt => {
beforeFinal: {
src: [
'build/tmp/custom/Espo/Custom/*',
'build/tmp/custom/Espo/Modules/*',
'!build/tmp/custom/Espo/Custom/.htaccess',
'!build/tmp/custom/Espo/Modules/.htaccess',
'build/tmp/install/config.php',
'build/tmp/vendor/*/*/.git',
]

View File

@@ -48,9 +48,13 @@ class Module
private $list = null;
private $internalList = null;
private $cacheKey = 'modules';
private $pathToModules = 'application/Espo/Modules';
private $internalPath = 'application/Espo/Modules';
private $customPath = 'custom/Espo/Modules';
private $moduleFilePath = 'Resources/module.json';
@@ -141,10 +145,34 @@ class Module
return array_keys($modulesToSort);
}
private function getInternalList(): array
{
if ($this->internalList === null) {
$this->internalList = $this->fileManager->getDirList($this->internalPath);
}
return $this->internalList;
}
private function isInternal(string $moduleName): bool
{
return in_array($moduleName, $this->getInternalList());
}
public function getModulePath(string $moduleName): string
{
$basePath = $this->isInternal($moduleName) ? $this->internalPath : $this->customPath;
return $basePath . '/' . $moduleName;
}
private function getList(): array
{
if ($this->list === null) {
$this->list = $this->fileManager->getDirList($this->pathToModules);
$this->list = array_merge(
$this->getInternalList(),
$this->fileManager->getDirList($this->customPath)
);
}
return $this->list;
@@ -155,7 +183,7 @@ class Module
$data = [];
foreach ($this->getList() as $moduleName) {
$path = $this->pathToModules . '/' . $moduleName . '/' . $this->moduleFilePath;
$path = $this->getModulePath($moduleName) . '/' . $this->moduleFilePath;
$itemContents = $this->fileManager->getContents($path);

View File

@@ -29,32 +29,33 @@
namespace Espo\Core\Utils\Module;
use Espo\Core\Utils\Module;
class PathProvider
{
private $core = 'application/Espo/';
private $corePath = 'application/Espo/';
private $module = 'application/Espo/Modules/{*}/';
private $customPath = 'custom/Espo/Custom/';
private $custom = 'custom/Espo/Custom/';
private $module;
public function __construct() {}
public function __construct(Module $module)
{
$this->module = $module;
}
public function getCore(): string
{
return $this->core;
return $this->corePath;
}
public function getCustom(): string
{
return $this->custom;
return $this->customPath;
}
public function getModule(?string $moduleName): string
public function getModule(string $moduleName): string
{
if ($moduleName === null) {
return $this->module;
}
return str_replace('{*}', $moduleName, $this->module);
return $this->module->getModulePath($moduleName) . '/';
}
}

View File

@@ -50,7 +50,7 @@ class PathProvider
return $this->provider->getCustom() . 'Resources/';
}
public function getModule(?string $moduleName): string
public function getModule(string $moduleName): string
{
return $this->provider->getModule($moduleName) . 'Resources/';
}

View File

@@ -48,7 +48,8 @@
"autoload": {
"psr-4": {
"Espo\\": "application/Espo/",
"Espo\\Custom\\": "custom/Espo/Custom/"
"Espo\\Custom\\": "custom/Espo/Custom/",
"Espo\\Modules\\": "custom/Espo/Modules/"
}
},
"autoload-dev": {

View File

@@ -0,0 +1,2 @@
Order Deny,Allow
Deny from all

View File

@@ -60,7 +60,7 @@ class MetadataTest extends \PHPUnit\Framework\TestCase
$module = new Module($this->fileManager);
$pathProvider = new PathProvider(new ModulePathProvider());
$pathProvider = new PathProvider(new ModulePathProvider($module));
$unifierObj = new UnifierObj($this->fileManager, $module, $pathProvider);
$unifier = new Unifier($this->fileManager, $module, $pathProvider);