Completed
Push — master ( 620fe4...c35a3d )
by Derek Stephen
02:47
created

Headers::setHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * bone
4
 * delboy1978uk
5
 * 29/06/2014
6
 */
7
8
namespace Bone\Mvc\Response;
9
10
class Headers
11
{
12
    /** @var array */
13
    private $headers;
14
15
    public function __construct()
16
    {
17
        $this->headers = array();
18
    }
19
20
    /**
21
     * @param string $key
22
     * @param string $value
23
     * @return $this
24
     */
25
    public function setHeader($key,$value)
26
    {
27
        $this->headers[$key] = $value;
28
        return $this;
29
    }
30
31
    /**
32
     * @param $key
33
     * @return bool
34
     */
35
    public function getHeader($key)
36
    {
37
        if(array_key_exists($key,$this->headers))
38
        {
39
            return $this->headers[$key];
40
        }
41
        return false;
42
    }
43
44
    /**
45
     *
46
     * @return array
47
     */
48
    public function toArray()
49
    {
50
        return $this->headers;
51
    }
52
53
    /**
54
     *  Fire th' cannons!
55
     */
56
    public function dispatch()
57
    {
58
        foreach($this->headers as $key => $val)
59
        {
60
            header($key.': '.$val);
61
        }
62
        return true;
63
    }
64
65
    /**
66
     *  we be wantin' t' see Json
67
     */
68
    public function setJsonResponse()
69
    {
70
        $this->setHeader('Cache-Control', 'no-cache, must-revalidate');
71
        $this->setHeader('Expires','Mon, 26 Jul 1997 05:00:00 GMT');
72
        $this->setHeader('Content-Type','application/json');
73
    }
74
}