portal application changes

This commit is contained in:
Yuri Kuznetsov
2020-06-22 15:29:12 +03:00
parent 5292d13ae6
commit b2fa393673
+27 -11
View File
@@ -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);
}
}
}
}