Completed
Push — master ( 84e322...4c12f0 )
by Charis
02:20
created

AbstractRenderer::mergeData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Resilient;
4
5
use \Psr\Http\Message\ResponseInterface;
6
7
/**
8
 * Abstract AbstractRenderer class.
9
 *
10
 * @abstract
11
 */
12
abstract class AbstractRenderer implements \ArrayAccess
13
{
14
    protected $offset = [];
15
16
    /**
17
     * template function.
18
     *
19
     * @access protected
20
     * @abstract
21
     * @param mixed $template
22
     */
23
    abstract protected function template($template);
24
25
    /**
26
     * render function.
27
     *
28
     * @access public
29
     * @abstract
30
     * @param ResponseInterface $response
31
     * @param mixed $template
32
     * @param mixed $data (default: [])
33
     * @return ResponseInterface
34
     */
35
    abstract public function render(ResponseInterface $response, $template, $data = []);
36
37
    /**
38
     * mergeData function.
39
     *
40
     * @access protected
41
     * @param mixed $data
42
     * @return array
43
     */
44
    protected function mergeData($data)
45
    {
46
        return array_merge($this->offset, $data);
47
    }
48
49
    /**
50
     * loadConfig function.
51
     *
52
     * @access public
53
     * @param array $offset
54
     * @return $this
55
     */
56
    public function loadConfig(array $offset)
57
    {
58
        $this->offset = $this->mergeData($offset);
59
60
        return $this;
61
    }
62
63
    /**
64
     * ArrayAccess Implementations
65
     */
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function offsetExists($key)
71
    {
72
        return array_key_exists($key, $this->offset);
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function offsetGet($key)
79
    {
80
        return $this->offset[$key];
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function offsetSet($key, $value)
87
    {
88
        $this->offset[$key] = $value;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function offsetUnset($key)
95
    {
96
        unset($this->offset[$key]);
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function count()
103
    {
104
        return count($this->offset);
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function getIterator()
111
    {
112
        return new \ArrayIterator($this->offset);
113
    }
114
}
115