-
-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathHttpApplication.php
More file actions
39 lines (31 loc) · 1.04 KB
/
HttpApplication.php
File metadata and controls
39 lines (31 loc) · 1.04 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
<?php
declare(strict_types=1);
namespace Tempest\Router;
use Tempest\Container\Container;
use Tempest\Container\Singleton;
use Tempest\Core\Application;
use Tempest\Core\Kernel;
use Tempest\Core\Tempest;
use Tempest\Http\RequestFactory;
#[Singleton]
final readonly class HttpApplication implements Application
{
public function __construct(
private Container $container,
) {}
/** @param \Tempest\Discovery\DiscoveryLocation[] $discoveryLocations */
public static function boot(string $root, array $discoveryLocations = []): self
{
return Tempest::boot($root, $discoveryLocations)->get(HttpApplication::class);
}
public function run(): never
{
$router = $this->container->get(Router::class);
$psrRequest = $this->container->get(RequestFactory::class)->make();
$responseSender = $this->container->get(ResponseSender::class);
$responseSender->send(
response: $router->dispatch($psrRequest),
);
$this->container->get(Kernel::class)->shutdown();
}
}