module routing

This commit is contained in:
2024-09-13 16:51:41 +03:00
parent f48d6753e2
commit f20ba63277
5 changed files with 62 additions and 19 deletions

View File

@ -14,7 +14,7 @@ class ModuleService
{
$info = [];
$info['path'] = $module;
if (file_exists($module . "/manifest.json")){
if (file_exists($module . "/manifest.json")) {
$manifest = file_get_contents($module . "/manifest.json");
$manifest = Manifest::getWithVars($manifest);
$info = array_merge($info, $manifest);
@ -26,10 +26,10 @@ class ModuleService
public function isActive(string $slug): bool
{
$active_modules = Option::where("key", "active_modules")->first();
if ($active_modules){
if ($active_modules) {
$path = json_decode($active_modules->value);
foreach ($path->modules as $p){
if ($p === $slug){
foreach ($path->modules as $p) {
if ($p === $slug) {
return true;
}
}
@ -56,16 +56,16 @@ class ModuleService
{
$module_paths = Option::where("key", "module_paths")->first();
$dirs = [];
if ($module_paths){
if ($module_paths) {
$path = json_decode($module_paths->value);
foreach ($path->paths as $p){
foreach ($path->paths as $p) {
$dirs[] = getConst($p);
}
}
foreach ($dirs as $dir){
foreach ($dirs as $dir) {
foreach (new DirectoryIterator($dir) as $fileInfo) {
if(basename($fileInfo->getPathname()) === $slug) {
if (basename($fileInfo->getPathname()) === $slug) {
return $fileInfo->getPathname();
}
}
@ -73,4 +73,39 @@ class ModuleService
return false;
}
public function getActiveModules(): array
{
$modules = [];
$module_paths = Option::where("key", "module_paths")->first();
$dirs = [];
if ($module_paths) {
$path = json_decode($module_paths->value);
foreach ($path->paths as $p) {
$dirs[] = getConst($p);
}
}
foreach ($dirs as $dir) {
foreach (new DirectoryIterator($dir) as $fileInfo) {
if($fileInfo->isDot()) continue;
$modules[] = $this->getModuleInfo($fileInfo->getPathname());
}
}
return $modules;
}
public function getModulesRouts(): array
{
$routs = [];
$modules = $this->getActiveModules();
foreach ($modules as $module){
if (isset($module['routs'])){
$routs[] = $module['path'] . "/" . $module['routs'];
}
}
return $routs;
}
}