Mother::offsetGet()   A
last analyzed

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
/**
4
 * Mother Manager
5
 *
6
 * @category  	core
7
 * @package   	core\Controller
8
 * @author    	Judicaël Paquet <[email protected]>
9
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
10
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
11
 * @version   	Release: 1.0.0
12
 * @filesource	https://github.com/las93/venus2
13
 * @link      	https://github.com/las93
14
 * @since     	1.0
15
 */
16
namespace Venus\core;
17
18
/**
19
 * The Mother Manager
20
 *
21
 * @category  	core
22
 * @package   	core\Controller
23
 * @author    	Judicaël Paquet <[email protected]>
24
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
25
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
26
 * @version   	Release: 1.0.0
27
 * @filesource	https://github.com/las93/venus2
28
 * @link      	https://github.com/las93
29
 * @since     	1.0
30
 */
31
class Mother implements \ArrayAccess
32
{
33
	/**
34
	 * containts the closures
35
	 * @var array
36
	 */
37
	private $_aClosures = array();
38
39
	/**
40
	 * containts data type
41
	 * @var array
42
	 */
43
	private $_aDataType = array();
44
45
	/**
46
	 * containts datas
47
	 * @var array
48
	 */
49
	protected $_aData = array();
50
51
	/**
52
	 * get a property
53
	 *
54
	 * @access public
55
	 * @param  unknown_type $mKey
56
	 * @return void
57
	 */
58
	public function __get($mKey)
59
	{
60
		if (isset($this->_aDataType[$mKey])) {
61
62
			if (!is_callable($data = $this->_aDataType[$mKey][$mKey]) || (is_string($data) && function_exists($data))) {
63
64
				return $data;
65
			} else {
66
67
				$dataStore = &$this->_aDataType[$mKey];
68
				$dataStore[$mKey] = call_user_func($data, null);
69
				return $dataStore[$mKey];
70
			}
71
		} else {
72
73
			return null;
74
		}
75
	}
76
77
	/**
78
	 * set a property
79
	 *
80
	 * @access public
81
	 * @param  unknown_type $mKey
82
	 * @return void
83
	 */
84
	public function __set($mKey, $mValue)
85
	{
86
		if (is_callable($mValue) && !is_string($mValue)) {
87
88
			$this->_aClosures[$mKey] = $mValue;
89
			$this->_aDataType[$mKey] = &$this->_aClosures;
90
		} else {
91
92
			$this->_aData[$mKey] = $mValue;
93
			$this->_aDataType[$mKey] = &$this->_aData;
94
		}
95
	}
96
97
	/**
98
	 * unset a property
99
	 *
100
	 * @access public
101
	 * @param  mixed $mKey
102
	 * @return void
103
	 */
104
	public function __unset($mKey)
105
	{
106
		if ($this->__isset($mKey)) {
107
108
			unset($this->_aDataType[$mKey][$mKey]);
109
			unset($this->_aDataType[$mKey]);
110
		}
111
	}
112
113
	/**
114
	 * test existance of property
115
	 *
116
	 * @access public
117
	 * @param  mixed $mKey
118
	 * @return boolean
119
	 */
120
	public function __isset($mKey)
121
	{
122
		return isset($this->_aDataType[$mKey]);
123
	}
124
125
	/**
126
	 * if offsetExists of \ArrayAccess
127
	 *
128
	 * @access public
129
	 * @param  mixed $mOffset
130
	 * @return boolean
131
	 */
132
    public function offsetExists($mOffset)
133
	{
134
		return $this->__isset($mOffset);
135
	}
136
137
	/**
138
	 * if offsetGet of \ArrayAccess
139
	 *
140
	 * @access public
141
	 * @param  mixed $mOffset
142
	 * @return mixed
143
	 */
144
	public function offsetGet($mOffset)
145
	{
146
		return $this->__get($mOffset);
147
	}
148
149
	/**
150
	 * if offsetSet of \ArrayAccess
151
	 *
152
	 * @access public
153
	 * @param  mixed $mOffset
154
	 * @param  mixed $mValue
155
	 * @return void
156
	 */
157
	public function offsetSet($mOffset, $mValue)
158
	{
159
		$this->__set($mOffset, $mValue);
160
	}
161
162
	/**
163
	 * if offsetUnset of \ArrayAccess
164
	 *
165
	 * @access public
166
	 * @param  mixed $mOffset
167
	 * @return void
168
	 */
169
	public function offsetUnset($mOffset)
170
	{
171
		$this->__unset($mOffset);
172
	}
173
}
174