draft app setup

This commit is contained in:
Dennis Eichhorn 2020-02-25 20:08:44 +01:00
parent bcfd1657f8
commit 354d4a321a
3 changed files with 132 additions and 14 deletions

View File

@ -1,48 +1,140 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package phpOMS
* @package phpOMS\Application
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace phpOMS\Application;
use phpOMS\Module\ModuleManager;
use phpOMS\System\File\Local\Directory;
use phpOMS\System\File\PathException;
/**
* Application manager class.
*
* General application managing functionality.
*
* @package phpOMS
* @package phpOMS\Application
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class ApplicationManager
{
/**
* Module manager
*
* @var ModuleManager
* @since 1.0.0
*/
private ModuleManager $moduleManager;
/**
* Applications
*
* @var ApplicationInfo[]
* @since 1.0.0
*/
private array $applications = [];
/**
* Constructor.
*
* @param ModuleManager $moduleManager Module manager
*
* @since. 1.0.0
*/
public function __construct(ModuleManager $moduleManager)
{
$this->moduleManager = $moduleManager;
}
/**
* Load info of application.
*
* @param string $appPath Application path
*
* @return ApplicationInfo
*
* @since 1.0.0
*/
private function loadInfo(string $appPath): ApplicationInfo
{
$path = \realpath($appPath);
if ($path === false) {
throw new PathException($appPath);
}
$info = new ApplicationInfo($path);
$info->load();
return $info;
}
/**
* Install the application
*
* @param string $source Source of the application
* @param string $destination Destination of the application
*
* @return void
*
* @since 1.0.0
*/
public function install(string $source, string $destination) : void
{
if (\file_exists($destination) || !\file_exists($source)) {
return;
}
$app = $this->loadInfo(\rtrim('/\\', $source) . '/info.json');
$this->applications[$app->getInternalName()] = $app;
$this->installFiles($source, $destination);
$this->installFromModules($app);
}
public function installModules() : void
/**
* Install the files to the destination
*
* @param string $source Source path
* @param string $destination Destination of the application
*
* @return void
*
* @since 1.0.0
*/
private function installFiles(string $source, string $destination) : void
{
Directory::copy($source, $destination);
}
public function installConfig() : void
/**
* Install routes and hooks from modules for application
*
* @param ApplicationInfo $info Application info
*
* @return void
*
* @since 1.0.0
*/
public function installFromModules(ApplicationInfo $info) : void
{
}
public function update(string $source, string $destination) : void
{
$installed = $this->moduleManager->getInstalledModules();
foreach ($installed as $module => $moduleInfo) {
$this->moduleManager->reInit($module, $info);
}
}
}

View File

@ -204,9 +204,21 @@ abstract class InstallerAbstract
foreach ($directories as $child) {
if ($child instanceof Directory) {
foreach ($child as $file) {
if (!\file_exists(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php'))
|| ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName())
) {
continue;
}
self::installRoutes(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Routes.php', $file->getPath());
}
} elseif ($child instanceof File) {
if (!\file_exists(__DIR__ . '/../../' . $child->getName())
|| ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName())
) {
continue;
}
self::installRoutes(__DIR__ . '/../../' . $child->getName() . '/Routes.php', $child->getPath());
}
}
@ -271,9 +283,21 @@ abstract class InstallerAbstract
foreach ($directories as $key => $child) {
if ($child instanceof Directory) {
foreach ($child as $key2 => $file) {
if (!\file_exists(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php'))
|| ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName())
) {
continue;
}
self::installHooks(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Hooks.php', $file->getPath());
}
} elseif ($child instanceof File) {
if (!\file_exists(__DIR__ . '/../../' . $child->getName())
|| ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName())
) {
continue;
}
self::installHooks(__DIR__ . '/../../' . $child->getName() . '/Hooks.php', $child->getPath());
}
}

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace phpOMS\Module;
use phpOMS\Application\ApplicationAbstract;
use phpOMS\Application\ApplicationInfo;
use phpOMS\Autoloader;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\Message\Http\HttpRequest;
@ -446,7 +447,8 @@ final class ModuleManager
/**
* Re-init module.
*
* @param string $module Module name
* @param string $module Module name
* @param ApplicationInfo $appInfo Application info
*
* @return void
*
@ -454,7 +456,7 @@ final class ModuleManager
*
* @since 1.0.0
*/
public function reInit(string $module) : void
public function reInit(string $module, ApplicationInfo $appInfo = null) : void
{
$info = $this->loadInfo($module);
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer';
@ -464,7 +466,7 @@ final class ModuleManager
}
/** @var $class InstallerAbstract */
$class::reInit($info);
$class::reInit($info, $appInfo);
}
/**