refactoring

This commit is contained in:
Yuri Kuznetsov
2021-06-22 22:24:23 +03:00
parent 5b1d060e5a
commit bf4a01971d
8 changed files with 60 additions and 49 deletions

View File

@@ -104,21 +104,15 @@ class Application
}
/**
* Whether an application is installed.
* Whether the application is installed.
*/
public function isInstalled(): bool
{
$config = $this->getConfig();
if (file_exists($config->getConfigPath()) && $config->get('isInstalled')) {
return true;
}
return false;
return $this->getConfig()->get('isInstalled');
}
/**
* Get a service container.
* Get the service container.
*/
public function getContainer(): Container
{

View File

@@ -32,6 +32,7 @@ namespace Espo\Core\ApplicationRunners;
use Espo\Core\{
Application\Runner,
Utils\ClientManager,
Utils\Config,
};
/**
@@ -41,13 +42,22 @@ class Client implements Runner
{
private $clientManager;
public function __construct(ClientManager $clientManager)
private $config;
public function __construct(ClientManager $clientManager, Config $config)
{
$this->clientManager = $clientManager;
$this->config = $config;
}
public function run(): void
{
if (!$this->config->get('isInstalled')) {
header("Location: install/");
return;
}
$this->clientManager->display();
}
}

View File

@@ -163,7 +163,10 @@ class ContainerBuilder
$bindingContainer = new BindingContainer($bindingLoader->load());
return new $this->containerClassName(
$this->containerConfigurationClassName, $this->loaderClassNames, $this->services, $bindingContainer
$this->containerConfigurationClassName,
$this->loaderClassNames,
$this->services,
$bindingContainer
);
}
}

View File

@@ -52,7 +52,7 @@ class Client implements Runner
public function run(): void
{
$portalId = $this->applicationState->getPortal()->id;
$portalId = $this->applicationState->getPortal()->getId();
$this->clientManager->display(null, null, [
'portalId' => $portalId,

View File

@@ -33,9 +33,11 @@ class Url
{
public static function detectPortalIdForApi(): ?string
{
if (!empty($_GET['portalId'])) {
return $_GET['portalId'];
}
$portalId = filter_input(INPUT_GET, 'portalId');
if ($portalId) {
return $portalId;
}
$url = $_SERVER['REQUEST_URI'];
@@ -90,9 +92,7 @@ class Url
return false;
}
$url = $_SERVER['REQUEST_URI'];
$a = explode('?', $url);
$a = explode('?', $_SERVER['REQUEST_URI']);
$url = rtrim($a[0], '/');

View File

@@ -34,7 +34,7 @@ use Espo\Core\{
Utils\Config\ConfigFileManager,
};
use StdClass;
use stdClass;
use E_USER_DEPRECATED;
/**
@@ -91,16 +91,22 @@ class Config
$lastBranch = $this->loadConfig();
foreach ($keys as $keyName) {
if (isset($lastBranch[$keyName]) && (is_array($lastBranch) || is_object($lastBranch))) {
if (is_array($lastBranch)) {
$lastBranch = $lastBranch[$keyName];
} else {
$lastBranch = $lastBranch->$keyName;
}
} else {
foreach ($keys as $key) {
if (!is_array($lastBranch) && !is_object($lastBranch)) {
return $default;
}
if (!isset($lastBranch[$key])) {
return $default;
}
if (is_array($lastBranch)) {
$lastBranch = $lastBranch[$key];
continue;
}
$lastBranch = $lastBranch->$key;
}
return $lastBranch;
@@ -115,16 +121,22 @@ class Config
$lastBranch = $this->loadConfig();
foreach ($keys as $keyName) {
if (isset($lastBranch[$keyName]) && (is_array($lastBranch) || is_object($lastBranch))) {
if (is_array($lastBranch)) {
$lastBranch = $lastBranch[$keyName];
} else {
$lastBranch = $lastBranch->$keyName;
}
} else {
foreach ($keys as $key) {
if (!is_array($lastBranch) && !is_object($lastBranch)) {
return false;
}
if (!isset($lastBranch[$key])) {
return false;
}
if (is_array($lastBranch)) {
$lastBranch = $lastBranch[$key];
continue;
}
$lastBranch = $lastBranch->$key;
}
return true;
@@ -269,8 +281,8 @@ class Config
}
$configPath = $this->fileManager->isFile($this->configPath) ?
$this->configPath :
$this->defaultConfigPath;
$this->configPath :
$this->defaultConfigPath;
$this->data = $this->fileManager->getPhpContents($configPath);
@@ -286,7 +298,7 @@ class Config
/**
* Get all parameters.
*/
public function getAllData(): StdClass
public function getAllData(): stdClass
{
return (object) $this->loadConfig();
}

View File

@@ -37,13 +37,7 @@ use Espo\Core\{
$app = new Application();
if (!$app->isInstalled()) {
header("Location: install/");
exit;
}
if (!empty($_GET['entryPoint'])) {
if (filter_has_var(INPUT_GET, 'entryPoint')) {
$app->run(EntryPoint::class);
exit;

View File

@@ -53,14 +53,12 @@ if (Url::detectIsInPortalDir()) {
$app->setClientBasePath($basePath);
}
if (!empty($_GET['entryPoint'])) {
if (filter_has_var(INPUT_GET, 'entryPoint')) {
$app->run(EntryPoint::class);
exit;
}
$params = RunnerParams::fromArray([
'basePath' => $basePath,
]);
$params = RunnerParams::create()->with('basePath', $basePath);
$app->run(PortalClient::class, $params);