Completed
Push — master ( 9a342a...a162ae )
by Andrii
13:06
created

ResolveEndpointMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace hiapi\Core\Http\Psr15\Middleware;
4
5
use hiapi\Core\Endpoint\EndpointRepository;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Server\MiddlewareInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
11
/**
12
 * Class ResolveEndpointMiddleware
13
 *
14
 * @author Dmytro Naumenko <[email protected]>
15
 */
16
class ResolveEndpointMiddleware implements MiddlewareInterface
17
{
18
    /**
19
     * @var EndpointRepository
20
     */
21
    private $endpointRepository;
22
23
    public function __construct(EndpointRepository $endpointRepository)
24
    {
25
        $this->endpointRepository = $endpointRepository;
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
32
    {
33
        $endpoint = $this->endpointRepository->getByName(trim($request->getUri()->getPath(), '/'));
34
35
        return $handler->handle(
36
            $request->withAttribute(self::class, $endpoint)
37
        );
38
    }
39
}
40