From b2fa3936739a5793b910e6f10d114af2bd64c614 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 22 Jun 2020 15:29:12 +0300 Subject: [PATCH] portal application changes --- application/Espo/Core/Portal/Application.php | 38 ++++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/application/Espo/Core/Portal/Application.php b/application/Espo/Core/Portal/Application.php index e8c45b8d8c..9250385c78 100644 --- a/application/Espo/Core/Portal/Application.php +++ b/application/Espo/Core/Portal/Application.php @@ -38,9 +38,10 @@ use Espo\Core\Exceptions\{ use Espo\Core\{ Portal\Container as PortalContainer, Portal\ContainerConfiguration as PortalContainerConfiguration, + Application as BaseApplication, }; -class Application extends \Espo\Core\Application +class Application extends BaseApplication { public function __construct(?string $portalId) { @@ -48,11 +49,24 @@ class Application extends \Espo\Core\Application $this->initContainer(); + $this->initPortal($portalId); + + $this->initAutoloads(); + $this->initPreloads(); + } + + protected function initContainer() + { + $this->container = new PortalContainer(PortalContainerConfiguration::class, $this->loaderClassNames); + } + + protected function initPortal(?string $portalId) + { if (!$portalId) { throw new Error("Portal ID was not passed to Portal\Application."); } - $entityManager = $this->getContainer()->get('entityManager'); + $entityManager = $this->container->get('entityManager'); $portal = $entityManager->getEntity('Portal', $portalId); @@ -69,14 +83,7 @@ class Application extends \Espo\Core\Application $this->portal = $portal; - $this->getContainer()->setPortal($portal); - - $this->initAutoloads(); - } - - protected function initContainer() - { - $this->container = new PortalContainer(PortalContainerConfiguration::class, $this->loaderClassNames); + $this->container->setPortal($portal); } protected function getPortal() @@ -101,7 +108,7 @@ class Application extends \Espo\Core\Application public function runClient() { - $this->getContainer()->get('clientManager')->display(null, null, [ + $this->container->get('clientManager')->display(null, null, [ 'portalId' => $this->getPortal()->id, 'applicationId' => $this->getPortal()->id, 'apiUrl' => 'api/v1/portal-access/' . $this->getPortal()->id, @@ -109,4 +116,13 @@ class Application extends \Espo\Core\Application ]); exit; } + + protected function initPreloads() + { + foreach ($this->getMetadata()->get(['app', 'portalContainerServices']) ?? [] as $name => $defs) { + if ($defs['preload'] ?? false) { + $this->container->get($name); + } + } + } }