Completed
Pull Request — master (#39)
by Daniel
03:46
created

HttpLeagueFacade::map()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Jellyfish\HttpLeague;
4
5
use Jellyfish\Http\ControllerInterface;
6
use Jellyfish\Http\HttpFacadeInterface;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
10
class HttpLeagueFacade implements HttpFacadeInterface
11
{
12
    /**
13
     * @var \Jellyfish\HttpLeague\HttpLeagueFactory
14
     */
15
    protected $factory;
16
17
    /**
18
     * @param \Jellyfish\HttpLeague\HttpLeagueFactory $factory
19
     */
20
    public function __construct(HttpLeagueFactory $factory)
21
    {
22
        $this->factory = $factory;
23
    }
24
25
    /**
26
     * @param \Psr\Http\Message\ServerRequestInterface $request
27
     * @return \Psr\Http\Message\ResponseInterface
28
     */
29
    public function dispatch(ServerRequestInterface $request): ResponseInterface
30
    {
31
        return $this->factory->createRouter()->dispatch($request);
32
    }
33
34
    /**
35
     * @return \Psr\Http\Message\ServerRequestInterface
36
     */
37
    public function getCurrentRequest(): ServerRequestInterface
38
    {
39
        return $this->factory->createRequest();
40
    }
41
42
    /**
43
     * @param \Psr\Http\Message\ResponseInterface $response
44
     *
45
     * @return bool
46
     */
47
    public function emit(ResponseInterface $response): bool
48
    {
49
        return $this->factory->createEmitter()->emit($response);
50
    }
51
52
    /**
53
     * @param string $method
54
     * @param string $path
55
     * @param \Jellyfish\Http\ControllerInterface $controller
56
     *
57
     * @return \Jellyfish\Http\HttpFacadeInterface
58
     */
59
    public function map(string $method, string $path, ControllerInterface $controller): HttpFacadeInterface
60
    {
61
        $this->factory->createRouter()->map($method, $path, $controller);
62
63
        return $this;
64
    }
65
}
66