HttpApplicationServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 50
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A registerBootLoader() 0 10 1
A registerRoutingHandler() 0 9 1
A registerHttpApplication() 0 19 1
1
<?php
2
declare(strict_types=1);
3
4
namespace App\Providers;
5
6
use Illuminate\Container\Container;
7
use N1215\Http\Router\RouterInterface;
8
use N1215\Http\Router\Handler\RoutingErrorResponderInterface;
9
use N1215\Http\Router\Handler\RoutingHandler;
10
use N1215\Http\Router\Handler\RoutingHandlerInterface;
11
use N1215\Jugoya\RequestHandlerBuilderInterface;
12
use N1215\Tsukuyomi\BootLoader;
13
use N1215\Tsukuyomi\BootLoaderInterface;
14
use N1215\Tsukuyomi\Event\EventManagerInterface;
15
use N1215\Tsukuyomi\FrameworkInterface;
16
use N1215\Tsukuyomi\HttpApplication;
17
use N1215\Tsukuyomi\HttpApplicationInterface;
18
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
19
20
class HttpApplicationServiceProvider implements ServiceProviderInterface
21
{
22 1
    public function register(Container $container)
23
    {
24 1
        $this->registerBootLoader($container);
25 1
        $this->registerRoutingHandler($container);
26 1
        $this->registerHttpApplication($container);
27 1
    }
28
29 1
    private function registerBootLoader(Container $container)
30
    {
31
        $container->singleton(BootLoaderInterface::class, function (Container $container) {
32
            /** @var FrameworkInterface $framework */
33 1
            $framework = $container->get(FrameworkInterface::class);
34 1
            $bootstrapConfigPath = $framework->path('config/bootstrappers.php');
35 1
            $bootstrapperClasses = require $bootstrapConfigPath;
36 1
            return new BootLoader($bootstrapperClasses);
37 1
        });
38 1
    }
39
40 1
    private function registerRoutingHandler(Container $container)
41
    {
42
        $container->singleton(RoutingHandlerInterface::class, function (Container $container) {
43 1
            return new RoutingHandler(
44 1
                $container->get(RouterInterface::class),
45 1
                $container->get(RoutingErrorResponderInterface::class)
46
            );
47 1
        });
48 1
    }
49
50 1
    private function registerHttpApplication(Container $container)
51
    {
52
        $container->singleton(HttpApplicationInterface::class, function (Container $container) {
53
            /** @var RequestHandlerBuilderInterface $handlerBuilder */
54 1
            $handlerBuilder = $container->get(RequestHandlerBuilderInterface::class);
55
            /** @var FrameworkInterface $framework */
56 1
            $framework = $container->get(FrameworkInterface::class);
57 1
            $middlewareConfigPath = $framework->path('config/middlewares.php');
58 1
            $middlewareClasses = require $middlewareConfigPath;
59 1
            $requestHandler = $handlerBuilder->build(RoutingHandlerInterface::class, $middlewareClasses);
60
61 1
            return new HttpApplication(
62 1
                $container->get(BootLoaderInterface::class),
63 1
                $requestHandler,
64 1
                new SapiEmitter(),
65 1
                $container->get(EventManagerInterface::class)
66
            );
67 1
        });
68 1
    }
69
}
70