Host::getSettings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace NBN\LoadBalancer\Host;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
8
/**
9
 * @author Nicolas Bastien <[email protected]>
10
 */
11
class Host implements HostInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $id;
17
18
    /**
19
     * @var string
20
     */
21
    protected $url;
22
23
    /**
24
     * @var array
25
     */
26
    protected $settings;
27
28
    /**
29
     * @param string $id
30
     * @param string $url
31
     * @param array  $settings
32
     */
33
    public function __construct($id, $url, array $settings)
34
    {
35
        $this->id = $id;
36
        $this->url = $url;
37
        $this->settings = $settings;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getId()
44
    {
45
        return $this->id;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getUrl()
52
    {
53
        return $this->url;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getSettings()
60
    {
61
        return $this->settings;
62
    }
63
64
    /**
65
     * @param  string $name     Setting name
66
     * @param  mixed  $default  Default value is setting is not set
67
     * @return mixed
68
     */
69
    public function getSetting($name, $default = null)
70
    {
71
        if (isset($this->settings[$name])) {
72
            return $this->settings[$name];
73
        }
74
75
        return $default;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function getLoad()
82
    {
83
        //if load is not defined presume it's overloaded
84
        return $this->getSetting('load', 1);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function handleRequest(Request $request)
91
    {
92
        $response = new Response();
93
        $response->setStatusCode($this->getSetting('response-status', 200));
94
        $response->setContent(sprintf($this->getSetting('response-content-format', '%s'), $request->getUri()));
95
96
        return $response;
97
    }
98
}
99