module path refactoring
This commit is contained in:
@@ -18,4 +18,7 @@
|
|||||||
/composer.phar
|
/composer.phar
|
||||||
/vendor/
|
/vendor/
|
||||||
/custom/Espo/Custom/*
|
/custom/Espo/Custom/*
|
||||||
|
/custom/Espo/Modules/*
|
||||||
|
!/custom/Espo/Custom/.htaccess
|
||||||
|
!/custom/Espo/Modules/.htaccess
|
||||||
/install/config.php
|
/install/config.php
|
||||||
|
|||||||
@@ -101,7 +101,9 @@ module.exports = grunt => {
|
|||||||
beforeFinal: {
|
beforeFinal: {
|
||||||
src: [
|
src: [
|
||||||
'build/tmp/custom/Espo/Custom/*',
|
'build/tmp/custom/Espo/Custom/*',
|
||||||
|
'build/tmp/custom/Espo/Modules/*',
|
||||||
'!build/tmp/custom/Espo/Custom/.htaccess',
|
'!build/tmp/custom/Espo/Custom/.htaccess',
|
||||||
|
'!build/tmp/custom/Espo/Modules/.htaccess',
|
||||||
'build/tmp/install/config.php',
|
'build/tmp/install/config.php',
|
||||||
'build/tmp/vendor/*/*/.git',
|
'build/tmp/vendor/*/*/.git',
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -48,9 +48,13 @@ class Module
|
|||||||
|
|
||||||
private $list = null;
|
private $list = null;
|
||||||
|
|
||||||
|
private $internalList = null;
|
||||||
|
|
||||||
private $cacheKey = 'modules';
|
private $cacheKey = 'modules';
|
||||||
|
|
||||||
private $pathToModules = 'application/Espo/Modules';
|
private $internalPath = 'application/Espo/Modules';
|
||||||
|
|
||||||
|
private $customPath = 'custom/Espo/Modules';
|
||||||
|
|
||||||
private $moduleFilePath = 'Resources/module.json';
|
private $moduleFilePath = 'Resources/module.json';
|
||||||
|
|
||||||
@@ -141,10 +145,34 @@ class Module
|
|||||||
return array_keys($modulesToSort);
|
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
|
private function getList(): array
|
||||||
{
|
{
|
||||||
if ($this->list === null) {
|
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;
|
return $this->list;
|
||||||
@@ -155,7 +183,7 @@ class Module
|
|||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
foreach ($this->getList() as $moduleName) {
|
foreach ($this->getList() as $moduleName) {
|
||||||
$path = $this->pathToModules . '/' . $moduleName . '/' . $this->moduleFilePath;
|
$path = $this->getModulePath($moduleName) . '/' . $this->moduleFilePath;
|
||||||
|
|
||||||
$itemContents = $this->fileManager->getContents($path);
|
$itemContents = $this->fileManager->getContents($path);
|
||||||
|
|
||||||
|
|||||||
@@ -29,32 +29,33 @@
|
|||||||
|
|
||||||
namespace Espo\Core\Utils\Module;
|
namespace Espo\Core\Utils\Module;
|
||||||
|
|
||||||
|
use Espo\Core\Utils\Module;
|
||||||
|
|
||||||
class PathProvider
|
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
|
public function getCore(): string
|
||||||
{
|
{
|
||||||
return $this->core;
|
return $this->corePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCustom(): string
|
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->getModulePath($moduleName) . '/';
|
||||||
return $this->module;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str_replace('{*}', $moduleName, $this->module);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class PathProvider
|
|||||||
return $this->provider->getCustom() . 'Resources/';
|
return $this->provider->getCustom() . 'Resources/';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getModule(?string $moduleName): string
|
public function getModule(string $moduleName): string
|
||||||
{
|
{
|
||||||
return $this->provider->getModule($moduleName) . 'Resources/';
|
return $this->provider->getModule($moduleName) . 'Resources/';
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -48,7 +48,8 @@
|
|||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Espo\\": "application/Espo/",
|
"Espo\\": "application/Espo/",
|
||||||
"Espo\\Custom\\": "custom/Espo/Custom/"
|
"Espo\\Custom\\": "custom/Espo/Custom/",
|
||||||
|
"Espo\\Modules\\": "custom/Espo/Modules/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
|
|||||||
@@ -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);
|
$module = new Module($this->fileManager);
|
||||||
|
|
||||||
$pathProvider = new PathProvider(new ModulePathProvider());
|
$pathProvider = new PathProvider(new ModulePathProvider($module));
|
||||||
|
|
||||||
$unifierObj = new UnifierObj($this->fileManager, $module, $pathProvider);
|
$unifierObj = new UnifierObj($this->fileManager, $module, $pathProvider);
|
||||||
$unifier = new Unifier($this->fileManager, $module, $pathProvider);
|
$unifier = new Unifier($this->fileManager, $module, $pathProvider);
|
||||||
|
|||||||
Reference in New Issue
Block a user