Completed
Push — master ( 579110...b52e58 )
by Pierre
02:10
created

AbstractApi   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 68
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A preflight() 0 4 1
A getService() 0 3 1
A getContainer() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
namespace App\Reuse\Controllers;
4
5
use App\Interfaces\Controllers\IApi;
6
use App\Container;
7
use App\Http\Request;
8
use App\Http\Response;
9
10
abstract class AbstractApi implements IApi
11
{
12
13
    use \App\Reuse\Controllers\Api\TFileCache;
14
15
    /**
16
     * request
17
     *
18
     * @var Request
19
     */
20
    protected $request;
21
22
    /**
23
     * response
24
     *
25
     * @var Response
26
     */
27
    protected $response;
28
29
    /**
30
     * di container
31
     *
32
     * @var Container
33
     */
34
    private $container;
35
36
    /**
37
     * instanciate
38
     *
39
     */
40
    public function __construct(Container $container)
41
    {
42
        $this->container = $container;
43
        $this->request = $this->getService(\App\Http\Request::class);
44
        $this->response = $this->getService(\App\Http\Response::class);
45
    }
46
47
    /**
48
     * preflight CORS with OPTIONS method
49
     *
50
     * @Methods OPTIONS
51
     * @return IApi
52
     */
53
    public function preflight(): IApi
54
    {
55
        $this->response->setCode(200)->setContent([]);
56
        return $this;
57
    }
58
59
    /**
60
     * returns container service from a service name
61
     *
62
     * @param string $serviceName
63
     * @return object
64
     */
65
    protected function getService(string $serviceName)
66
    {
67
        return $this->container->getService($serviceName);
68
    }
69
70
    /**
71
     * return container instance
72
     *
73
     * @return Container
74
     */
75
    protected function getContainer(): Container
76
    {
77
        return $this->container;
78
    }
79
}
80