Completed
Push — master ( e4c888...b002ee )
by Alexander
10:41 queued 05:38
created

Application::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
1
<?php
2
namespace Yiisoft\Yii\Web;
3
4
use Psr\Http\Message\ServerRequestInterface;
5
use Yiisoft\Router\Method;
6
use Yiisoft\Yii\Web\Emitter\EmitterInterface;
7
use Yiisoft\Yii\Web\ErrorHandler\ErrorHandler;
8
9
/**
10
 * Application is the entry point for a web application.
11
 *
12
 * For more details and usage information on Application, see the [guide article on applications](guide:structure-applications).
13
 */
14
final class Application
15
{
16
    /**
17
     * @var MiddlewareDispatcher
18
     */
19
    private $dispatcher;
20
21
    /**
22
     * @var EmitterInterface
23
     */
24
    private $emitter;
25
26
    /**
27
     * Application constructor.
28
     * @param MiddlewareDispatcher $dispatcher
29
     * @param EmitterInterface $emitter
30
     */
31
    public function __construct(MiddlewareDispatcher $dispatcher, EmitterInterface $emitter, ErrorHandler $errorHandler)
32
    {
33
        $this->dispatcher = $dispatcher;
34
        $this->emitter = $emitter;
35
36
        $errorHandler->register();
37
    }
38
39
    public function handle(ServerRequestInterface $request): bool
40
    {
41
        $response = $this->dispatcher->handle($request);
42
        $this->dispatcher->reset();
43
        return $this->emitter->emit($response, $request->getMethod() === Method::HEAD);
44
    }
45
}
46