mirror of
https://github.com/espocrm/espocrm.git
synced 2026-03-02 22:47:01 +00:00
module path refactoring
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -18,4 +18,7 @@
|
||||
/composer.phar
|
||||
/vendor/
|
||||
/custom/Espo/Custom/*
|
||||
/custom/Espo/Modules/*
|
||||
!/custom/Espo/Custom/.htaccess
|
||||
!/custom/Espo/Modules/.htaccess
|
||||
/install/config.php
|
||||
|
||||
@@ -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',
|
||||
]
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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) . '/';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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/';
|
||||
}
|
||||
|
||||
@@ -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": {
|
||||
|
||||
2
custom/Espo/Modules/.htaccess
Normal file
2
custom/Espo/Modules/.htaccess
Normal file
@@ -0,0 +1,2 @@
|
||||
Order Deny,Allow
|
||||
Deny from all
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user