diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index 259a00eca6..5e1522b242 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -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 { diff --git a/application/Espo/Core/ApplicationRunners/Client.php b/application/Espo/Core/ApplicationRunners/Client.php index 7af3e8cbd3..921f1c9367 100644 --- a/application/Espo/Core/ApplicationRunners/Client.php +++ b/application/Espo/Core/ApplicationRunners/Client.php @@ -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(); } } diff --git a/application/Espo/Core/Container/ContainerBuilder.php b/application/Espo/Core/Container/ContainerBuilder.php index aa4a62336d..cdb8b1b1dc 100644 --- a/application/Espo/Core/Container/ContainerBuilder.php +++ b/application/Espo/Core/Container/ContainerBuilder.php @@ -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 ); } } diff --git a/application/Espo/Core/Portal/ApplicationRunners/Client.php b/application/Espo/Core/Portal/ApplicationRunners/Client.php index fc5f5df814..7a4c0a41bc 100644 --- a/application/Espo/Core/Portal/ApplicationRunners/Client.php +++ b/application/Espo/Core/Portal/ApplicationRunners/Client.php @@ -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, diff --git a/application/Espo/Core/Portal/Utils/Url.php b/application/Espo/Core/Portal/Utils/Url.php index 7724ab3c81..f20fbe3e4a 100644 --- a/application/Espo/Core/Portal/Utils/Url.php +++ b/application/Espo/Core/Portal/Utils/Url.php @@ -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], '/'); diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php index 43338cf992..cab66c3405 100644 --- a/application/Espo/Core/Utils/Config.php +++ b/application/Espo/Core/Utils/Config.php @@ -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(); } diff --git a/index.php b/index.php index 0843edc0b7..8bea931e04 100644 --- a/index.php +++ b/index.php @@ -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; diff --git a/portal/index.php b/portal/index.php index 004de2edc7..7a5ae89298 100644 --- a/portal/index.php +++ b/portal/index.php @@ -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);