Completed
Push — master ( 9a93ca...bf97fc )
by Pierre
04:17
created

AbstractApi::getParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Reuse\Controllers;
4
5
use App\Interfaces\Controllers\IApi;
6
use Nymfonya\Component\Container;
7
use Nymfonya\Component\Http\Request;
8
use Nymfonya\Component\Http\Response;
9
use \Monolog\Logger;
10
11
abstract class AbstractApi implements IApi
12
{
13
14
    use \App\Reuse\Controllers\Api\TFileCache;
15
16
    /**
17
     * request
18
     *
19
     * @var Request
20
     */
21
    protected $request;
22
23
    /**
24
     * response
25
     *
26
     * @var Response
27
     */
28
    protected $response;
29
30
    /**
31
     * logger
32
     *
33
     * @var Logger
34
     */
35
    protected $logger;
36
37
    /**
38
     * di container
39
     *
40
     * @var Container
41
     */
42
    private $container;
43
44
    /**
45
     * instanciate
46
     *
47
     */
48 6
    public function __construct(Container $container)
49
    {
50 6
        $this->container = $container;
51 6
        $this->request = $this->getService(Request::class);
52 6
        $this->response = $this->getService(Response::class);
53 6
        $this->logger = $this->getService(Logger::class);
54
    }
55
56
    /**
57
     * preflight CORS with OPTIONS method
58
     *
59
     * @Methods OPTIONS
60
     * @return IApi
61
     */
62 1
    public function preflight(): IApi
63
    {
64 1
        $this->response->setCode(200)->setContent([]);
65 1
        return $this;
66
    }
67
68
    /**
69
     * returns container service from a service name
70
     *
71
     * @param string $serviceName
72
     * @return object
73
     */
74 1
    protected function getService(string $serviceName)
75
    {
76 1
        return $this->container->getService($serviceName);
77
    }
78
79
    /**
80
     * return container instance
81
     *
82
     * @return Container
83
     */
84 1
    protected function getContainer(): Container
85
    {
86 1
        return $this->container;
87
    }
88
89
    /**
90
     * get request instance
91
     *
92
     * @return Request
93
     */
94 1
    protected function getRequest(): Request
95
    {
96 1
        return $this->request;
97
    }
98
99
    /**
100
     * get request params
101
     *
102
     * @return array
103
     */
104 1
    protected function getParams(): array
105
    {
106 1
        return $this->getRequest()->getParams();
107
    }
108
}
109