Repository navigation
Expand file tree
/
Copy pathKernel.php
More file actions
50 lines (44 loc) · 1.52 KB
/
Copy pathKernel.php
File metadata and controls
50 lines (44 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);
namespace Opengento\Application;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\ObjectManagerInterface;
use Opengento\Application\ObjectManager\AppBootstrap;
use Opengento\Application\ObjectManager\BootstrapPool;
class Kernel
{
private BootstrapPool $bootstrapPool;
private ?AppBootstrap $appBootstrap = null;
private ?ObjectManagerInterface $omInstance = null;
public function __construct(array $initParams, private string $applicationType)
{
$this->bootstrapPool = new BootstrapPool($initParams);
}
public function handle(array $server, array $get): void
{
try {
$this->appBootstrap = $this->bootstrapPool->get($server, $get);
$this->omInstance = ObjectManager::getInstance();
ObjectManager::setInstance($this->appBootstrap->getObjectManager());
$app = $this->appBootstrap->createApplication($this->applicationType);
if ($app !== null) {
$this->appBootstrap->run($app);
}
} catch (LocalizedException $e) {
echo $e->getMessage();
exit(1);
}
}
public function terminate(): void
{
$this->appBootstrap?->resetState();
if ($this->omInstance !== null) {
ObjectManager::setInstance($this->omInstance);
}
}
}