Headers::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * For the full copyright and license information, please view the LICENSE
4
 * file that was distributed with this source code.
5
 *
6
 * @author Nikita Vershinin <[email protected]>
7
 * @license MIT
8
 */
9
namespace OpenStackStorage\Client;
10
11
/**
12
 * Contains response headers.
13
 */
14
class Headers implements \ArrayAccess, \IteratorAggregate
15
{
16
17
    /**
18
     * Array containing response headers.
19
     *
20
     * @var array
21
     */
22
    protected $headers = array();
23
24
    /**
25
     * Class constructor.
26
     *
27
     * @param array $headers
28
     */
29
    public function __construct(array $headers)
30
    {
31
        foreach ($headers as $k => $v) {
32
            $this->headers[strtolower($k)] = $v;
33
        }
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     *
39
     * @param  string  $offset
40
     * @return boolean
41
     */
42
    public function offsetExists($offset)
43
    {
44
        return isset($this->headers[strtolower($offset)]);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     *
50
     * @param  string      $offset
51
     * @return string|null
52
     */
53
    public function offsetGet($offset)
54
    {
55
        $name = strtolower($offset);
56
57
        if (isset($this->headers[$name])) {
58
            return $this->headers[$name];
59
        }
60
61
        return null;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     *
67
     * @param  string     $offset
68
     * @param  string     $value
69
     * @throws \Exception
70
     */
71
    public function offsetSet($offset, $value)
72
    {
73
        throw new \Exception('Headers are read-only.');
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     *
79
     * @param  string     $offset
80
     * @throws \Exception
81
     */
82
    public function offsetUnset($offset)
83
    {
84
        throw new \Exception('Headers are read-only.');
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     *
90
     * @return \ArrayObject
91
     */
92
    public function getIterator()
93
    {
94
        return new \ArrayObject($this->headers);
95
    }
96
}
97