diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index 625319378c..eb5ae285ed 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -161,19 +161,10 @@ class Application $slim->run(); } - /** - * Display the main HTML page. - */ - public function runClient() - { - $this->getClientManager()->display(); - exit; - } - /** * Run entryPoint. */ - public function runEntryPoint(string $entryPoint, array $data = [], bool $final = false) + public function runEntryPoint(string $entryPoint, $data = null, bool $final = false) { if (empty($entryPoint)) { throw new Error(); @@ -280,7 +271,7 @@ class Application } /** - * Whether the application is installed. + * Whether an application is installed. */ public function isInstalled() : bool { @@ -294,7 +285,7 @@ class Application } /** - * Get the service container. + * Get a service container. */ public function getContainer() : Container { diff --git a/application/Espo/Core/ApplicationRunners/Client.php b/application/Espo/Core/ApplicationRunners/Client.php new file mode 100644 index 0000000000..3c5bb430cf --- /dev/null +++ b/application/Espo/Core/ApplicationRunners/Client.php @@ -0,0 +1,52 @@ +clientManager = $clientManager; + } + + public function run() + { + $this->clientManager->display(); + } +} diff --git a/application/Espo/Core/EntryPointManager.php b/application/Espo/Core/EntryPointManager.php index 91eed89119..0173841d21 100644 --- a/application/Espo/Core/EntryPointManager.php +++ b/application/Espo/Core/EntryPointManager.php @@ -38,6 +38,8 @@ use Espo\Core\{ Api\Response, }; +use StdClass; + /** * Runs entry points. */ @@ -77,7 +79,7 @@ class EntryPointManager return $className::$notStrictAuth ?? false; } - public function run(string $name, Request $request, Response $response, array $data = []) + public function run(string $name, Request $request, Response $response, ?StdClass $data = null) { $className = $this->getClassName($name); if (!$className) { diff --git a/application/Espo/Core/Portal/Application.php b/application/Espo/Core/Portal/Application.php index de7b3e3d2e..33cbabaa6f 100644 --- a/application/Espo/Core/Portal/Application.php +++ b/application/Espo/Core/Portal/Application.php @@ -121,17 +121,6 @@ class Application extends BaseApplication return parent::getRunnerClassName($runnerName); } - public function runClient() - { - $this->container->get('clientManager')->display(null, null, [ - 'portalId' => $this->getPortal()->id, - 'applicationId' => $this->getPortal()->id, - 'apiUrl' => 'api/v1/portal-access/' . $this->getPortal()->id, - 'appClientClassName' => 'app-portal' - ]); - exit; - } - protected function initPreloads() { parent::initPreloads(); diff --git a/application/Espo/Core/Portal/ApplicationRunners/Client.php b/application/Espo/Core/Portal/ApplicationRunners/Client.php new file mode 100644 index 0000000000..377977589a --- /dev/null +++ b/application/Espo/Core/Portal/ApplicationRunners/Client.php @@ -0,0 +1,63 @@ +clientManager = $clientManager; + $this->applicationState = $applicationState; + } + + public function run() + { + $portalId = $this->applicationState->getPortal()->id; + + $this->clientManager->display(null, null, [ + 'portalId' => $portalId, + 'applicationId' => $portalId, + 'apiUrl' => 'api/v1/portal-access/' . $portalId, + 'appClientClassName' => 'app-portal', + ]); + } +} diff --git a/application/Espo/EntryPoints/Attachment.php b/application/Espo/EntryPoints/Attachment.php index 9653659ece..a3fcc576d9 100644 --- a/application/Espo/EntryPoints/Attachment.php +++ b/application/Espo/EntryPoints/Attachment.php @@ -36,6 +36,8 @@ use Espo\Core\Exceptions\BadRequest; use Espo\Core\EntryPoints\EntryPoint; use Espo\Core\Di; +use Espo\Core\Api\Request; + class Attachment implements EntryPoint, Di\EntityManagerAware, Di\AclAware @@ -50,7 +52,7 @@ class Attachment implements EntryPoint, 'image/webp', ]; - public function run($request) + public function run(Request $request) { $id = $request->get('id'); diff --git a/application/Espo/EntryPoints/Avatar.php b/application/Espo/EntryPoints/Avatar.php index b33faaee31..78a2891a38 100644 --- a/application/Espo/EntryPoints/Avatar.php +++ b/application/Espo/EntryPoints/Avatar.php @@ -37,6 +37,8 @@ use Espo\Core\Exceptions\Error; use Espo\Core\EntryPoints\NotStrictAuth; use Espo\Core\Di; +use Espo\Core\Api\Request; + class Avatar extends Image implements Di\MetadataAware { use Di\MetadataSetter; @@ -71,7 +73,7 @@ class Avatar extends Image implements Di\MetadataAware return $colorList[$index]; } - public function run($request) + public function run(Request $request) { $userId = $request->get('id'); $size = $request->get('size') ?? null; diff --git a/application/Espo/EntryPoints/ChangePassword.php b/application/Espo/EntryPoints/ChangePassword.php index 5693b78e46..8fae2894d3 100644 --- a/application/Espo/EntryPoints/ChangePassword.php +++ b/application/Espo/EntryPoints/ChangePassword.php @@ -42,6 +42,7 @@ use Espo\Core\{ Utils\Config, Utils\ClientManager, ORM\EntityManager, + Api\Request, }; class ChangePassword implements EntryPoint @@ -59,7 +60,7 @@ class ChangePassword implements EntryPoint $this->entityManager = $entityManager; } - public function run($request) + public function run(Request $request) { $requestId = $request->get('id'); diff --git a/application/Espo/EntryPoints/ConfirmOptIn.php b/application/Espo/EntryPoints/ConfirmOptIn.php index 0a194dc8fb..50a9992507 100644 --- a/application/Espo/EntryPoints/ConfirmOptIn.php +++ b/application/Espo/EntryPoints/ConfirmOptIn.php @@ -42,6 +42,7 @@ use Espo\Core\EntryPoints\{ use Espo\Core\{ Utils\ClientManager, ServiceFactory, + Api\Request, }; class ConfirmOptIn implements EntryPoint @@ -57,7 +58,7 @@ class ConfirmOptIn implements EntryPoint $this->serviceFactory = $serviceFactory; } - public function run($request) + public function run(Request $request) { $id = $request->get('id'); diff --git a/application/Espo/EntryPoints/Download.php b/application/Espo/EntryPoints/Download.php index cddfa2961b..07029de8c3 100644 --- a/application/Espo/EntryPoints/Download.php +++ b/application/Espo/EntryPoints/Download.php @@ -42,6 +42,8 @@ use Espo\Core\{ ORM\EntityManager, }; +use Espo\Core\Api\Request; + class Download implements EntryPoint { protected $fileTypesToShowInline = [ @@ -64,7 +66,7 @@ class Download implements EntryPoint $this->entityManager = $entityManager; } - public function run($request) + public function run(Request $request) { $id = $request->get('id'); diff --git a/application/Espo/EntryPoints/Image.php b/application/Espo/EntryPoints/Image.php index 492dae510b..d45558ff36 100644 --- a/application/Espo/EntryPoints/Image.php +++ b/application/Espo/EntryPoints/Image.php @@ -36,6 +36,9 @@ use Espo\Core\Exceptions\BadRequest; use Espo\Core\Exceptions\Error; use Espo\Core\EntryPoints\EntryPoint; + +use Espo\Core\Api\Request; + use Espo\Core\Di; class Image implements EntryPoint, @@ -73,7 +76,7 @@ class Image implements EntryPoint, protected $allowedFieldList = null; - public function run($request) + public function run(Request $request) { $id = $request->get('id'); $size = $request->get('size') ?? null; diff --git a/application/Espo/EntryPoints/LogoImage.php b/application/Espo/EntryPoints/LogoImage.php index 78040eb0cf..104bf0ddd0 100644 --- a/application/Espo/EntryPoints/LogoImage.php +++ b/application/Espo/EntryPoints/LogoImage.php @@ -38,6 +38,8 @@ use Espo\Core\EntryPoints\{ NoAuth, }; +use Espo\Core\Api\Request; + use Espo\Core\Di; class LogoImage extends Image implements Di\ConfigAware @@ -49,7 +51,7 @@ class LogoImage extends Image implements Di\ConfigAware protected $allowedFieldList = ['companyLogo']; - public function run($request) + public function run(Request $request) { $id = $request->get('id'); $size = $request->get('size') ?? null; diff --git a/application/Espo/EntryPoints/Pdf.php b/application/Espo/EntryPoints/Pdf.php index 6d070eadb5..fcaa569019 100644 --- a/application/Espo/EntryPoints/Pdf.php +++ b/application/Espo/EntryPoints/Pdf.php @@ -39,6 +39,7 @@ use Espo\Core\EntryPoints\{ use Espo\Core\{ ORM\EntityManager, ServiceFactory, + Api\Request, }; class Pdf implements EntryPoint @@ -52,7 +53,7 @@ class Pdf implements EntryPoint $this->serviceFactory = $serviceFactory; } - public function run($request) + public function run(Request $request) { $entityId = $request->get('entityId'); $entityType = $request->get('entityType'); diff --git a/application/Espo/EntryPoints/Portal.php b/application/Espo/EntryPoints/Portal.php index 3902c850f9..15fb52c873 100644 --- a/application/Espo/EntryPoints/Portal.php +++ b/application/Espo/EntryPoints/Portal.php @@ -40,8 +40,12 @@ use Espo\Core\{ Utils\ClientManager, Utils\Config, Portal\Application as PortalApplication, + Api\Request, + Api\Response, }; +use StdClass; + class Portal implements EntryPoint { use NoAuth; @@ -55,9 +59,11 @@ class Portal implements EntryPoint $this->config = $config; } - public function run($request, $response, $data = []) + public function run(Request $request, Response $response, ?StdClass $data = null) { - $id = $request->get('id') ?? $data['id'] ?? null; + $data = $data ?? (object) []; + + $id = $request->get('id') ?? $data->id ?? null; if (!$id) { $url = $_SERVER['REQUEST_URI']; @@ -78,6 +84,6 @@ class Portal implements EntryPoint $application = new PortalApplication($id); $application->setClientBasePath($this->clientManager->getBasePath()); - $application->runClient(); + $application->run('client'); } } diff --git a/index.php b/index.php index 631893e900..c846134eeb 100644 --- a/index.php +++ b/index.php @@ -30,6 +30,7 @@ include "bootstrap.php"; $app = new \Espo\Core\Application(); + if (!$app->isInstalled()) { header("Location: install/"); exit; @@ -40,4 +41,4 @@ if (!empty($_GET['entryPoint'])) { exit; } -$app->runClient(); +$app->run('client');