mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Optimize code order
This commit is contained in:
parent
16a0b79cc2
commit
57a93bd60a
|
|
@ -16,7 +16,6 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Module;
|
||||
|
||||
use phpOMS\ApplicationAbstract;
|
||||
use phpOMS\Autoloader;
|
||||
|
||||
/**
|
||||
* ModuleFactory class.
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Module;
|
||||
|
||||
use phpOMS\ApplicationAbstract;
|
||||
use phpOMS\Autoloader;
|
||||
use phpOMS\DataStorage\Database\DatabaseType;
|
||||
use phpOMS\Message\Http\Request;
|
||||
use phpOMS\System\File\PathException;
|
||||
|
|
@ -107,7 +106,7 @@ class ModuleManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Get modules that run on this page.
|
||||
* Get language files.
|
||||
*
|
||||
* @param Request $request Request
|
||||
*
|
||||
|
|
@ -115,18 +114,18 @@ class ModuleManager
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getRoutedModules(Request $request) : array
|
||||
public function getLanguageFiles(Request $request) : array
|
||||
{
|
||||
$files = $this->getUriLoad($request);
|
||||
$modules = [];
|
||||
$files = $this->getUriLoad($request);
|
||||
|
||||
if (isset($files[4])) {
|
||||
foreach ($files[4] as $module) {
|
||||
$modules[] = $module['module_load_file'];
|
||||
$lang = [];
|
||||
if (isset($files[5])) {
|
||||
foreach ($files[5] as $module) {
|
||||
$lang[] = '/Modules/' . $module['module_load_from'] . '/Theme/' . $this->app->appName . '/Lang/' . $module['module_load_file'];
|
||||
}
|
||||
}
|
||||
|
||||
return $modules;
|
||||
return $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -181,29 +180,6 @@ class ModuleManager
|
|||
return $this->uriLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language files.
|
||||
*
|
||||
* @param Request $request Request
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getLanguageFiles(Request $request) : array
|
||||
{
|
||||
$files = $this->getUriLoad($request);
|
||||
|
||||
$lang = [];
|
||||
if (isset($files[5])) {
|
||||
foreach ($files[5] as $module) {
|
||||
$lang[] = '/Modules/' . $module['module_load_from'] . '/Theme/' . $this->app->appName . '/Lang/' . $module['module_load_file'];
|
||||
}
|
||||
}
|
||||
|
||||
return $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all installed modules that are active (not just on this uri).
|
||||
*
|
||||
|
|
@ -302,6 +278,74 @@ class ModuleManager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all installed modules.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getInstalledModules() : array
|
||||
{
|
||||
if ($this->installed === null) {
|
||||
switch ($this->app->dbPool->get('core')->getType()) {
|
||||
case DatabaseType::MYSQL:
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare('SELECT `module_id`,`module_theme`,`module_version` FROM `' . $this->app->dbPool->get('core')->prefix . 'module`');
|
||||
$sth->execute();
|
||||
$this->installed = $sth->fetchAll(\PDO::FETCH_GROUP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load info of module.
|
||||
*
|
||||
* @param string $module Module name
|
||||
*
|
||||
* @return InfoManager
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function loadInfo(string $module) : InfoManager
|
||||
{
|
||||
$path = realpath($oldPath = $this->modulePath . '/' . $module . '/' . 'info.json');
|
||||
|
||||
if ($path === false) {
|
||||
throw new PathException($oldPath);
|
||||
}
|
||||
|
||||
$info = new InfoManager($path);
|
||||
$info->load();
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate module.
|
||||
*
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InvalidModuleException Throws this exception in case the deactiviation doesn't exist
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function deactivateModule(InfoManager $info) /* : void */
|
||||
{
|
||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Deactivate';
|
||||
|
||||
if (!Autoloader::exists($class)) {
|
||||
throw new InvalidModuleException($info->getDirectory());
|
||||
}
|
||||
|
||||
/** @var $class DeactivateAbstract */
|
||||
$class::deactivate($this->app->dbPool, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate module.
|
||||
*
|
||||
|
|
@ -337,6 +381,29 @@ class ModuleManager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate module.
|
||||
*
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InvalidModuleException Throws this exception in case the activation doesn't exist
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function activateModule(InfoManager $info) /* : void */
|
||||
{
|
||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Activate';
|
||||
|
||||
if (!Autoloader::exists($class)) {
|
||||
throw new InvalidModuleException($info->getDirectory());
|
||||
}
|
||||
|
||||
/** @var $class ActivateAbstract */
|
||||
$class::activate($this->app->dbPool, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-init module.
|
||||
*
|
||||
|
|
@ -453,97 +520,6 @@ class ModuleManager
|
|||
$class::install($this->modulePath, $this->app->dbPool, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate module.
|
||||
*
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InvalidModuleException Throws this exception in case the deactiviation doesn't exist
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function deactivateModule(InfoManager $info) /* : void */
|
||||
{
|
||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Deactivate';
|
||||
|
||||
if (!Autoloader::exists($class)) {
|
||||
throw new InvalidModuleException($info->getDirectory());
|
||||
}
|
||||
|
||||
/** @var $class DeactivateAbstract */
|
||||
$class::deactivate($this->app->dbPool, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate module.
|
||||
*
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InvalidModuleException Throws this exception in case the activation doesn't exist
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function activateModule(InfoManager $info) /* : void */
|
||||
{
|
||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Activate';
|
||||
|
||||
if (!Autoloader::exists($class)) {
|
||||
throw new InvalidModuleException($info->getDirectory());
|
||||
}
|
||||
|
||||
/** @var $class ActivateAbstract */
|
||||
$class::activate($this->app->dbPool, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load info of module.
|
||||
*
|
||||
* @param string $module Module name
|
||||
*
|
||||
* @return InfoManager
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function loadInfo(string $module) : InfoManager
|
||||
{
|
||||
$path = realpath($oldPath = $this->modulePath . '/' . $module . '/' . 'info.json');
|
||||
|
||||
if ($path === false) {
|
||||
throw new PathException($oldPath);
|
||||
}
|
||||
|
||||
$info = new InfoManager($path);
|
||||
$info->load();
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all installed modules.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getInstalledModules() : array
|
||||
{
|
||||
if ($this->installed === null) {
|
||||
switch ($this->app->dbPool->get('core')->getType()) {
|
||||
case DatabaseType::MYSQL:
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare('SELECT `module_id`,`module_theme`,`module_version` FROM `' . $this->app->dbPool->get('core')->prefix . 'module`');
|
||||
$sth->execute();
|
||||
$this->installed = $sth->fetchAll(\PDO::FETCH_GROUP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install providing.
|
||||
*
|
||||
|
|
@ -565,6 +541,30 @@ class ModuleManager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module instance.
|
||||
*
|
||||
* @param string $module Module name
|
||||
*
|
||||
* @return \phpOMS\Module\ModuleAbstract
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get(string $module) : ModuleAbstract
|
||||
{
|
||||
try {
|
||||
if (!isset($this->running[$module])) {
|
||||
$this->initModule($module);
|
||||
}
|
||||
|
||||
return $this->running[$module];
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize module.
|
||||
*
|
||||
|
|
@ -612,30 +612,6 @@ class ModuleManager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module instance.
|
||||
*
|
||||
* @param string $module Module name
|
||||
*
|
||||
* @return \phpOMS\Module\ModuleAbstract
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get(string $module) : ModuleAbstract
|
||||
{
|
||||
try {
|
||||
if (!isset($this->running[$module])) {
|
||||
$this->initModule($module);
|
||||
}
|
||||
|
||||
return $this->running[$module];
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all modules for a request.
|
||||
*
|
||||
|
|
@ -653,4 +629,27 @@ class ModuleManager
|
|||
$this->initModuleController($module);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get modules that run on this page.
|
||||
*
|
||||
* @param Request $request Request
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getRoutedModules(Request $request) : array
|
||||
{
|
||||
$files = $this->getUriLoad($request);
|
||||
$modules = [];
|
||||
|
||||
if (isset($files[4])) {
|
||||
foreach ($files[4] as $module) {
|
||||
$modules[] = $module['module_load_file'];
|
||||
}
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user