Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Core\Data\Data Class Reference
Inheritance diagram for Hoa\Core\Data\Data:

Public Member Functions

 __get ($name)
 
 __set ($name, $value)
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 toArray ()
 

Protected Attributes

 $_data = []
 
 $_temp = null
 

Detailed Description

Class .

Polymorphic data.

Definition at line 66 of file Data.php.

Member Function Documentation

Hoa\Core\Data\Data::__get (   $name)

Get a branch.

Parameters
string$nameBranch name.
Returns

Definition at line 90 of file Data.php.

91  {
92  if (null !== $this->_temp) {
93  return $this->offsetGet(0)->__get($name);
94  }
95 
96  $this->_temp = $name;
97 
98  return $this;
99  }
offsetGet($offset)
Definition: Data.php:142

Here is the call graph for this function:

Hoa\Core\Data\Data::__set (   $name,
  $value 
)

Set a branch. Notice that it will always reach the (n+1)-th branch.

Parameters
string$nameBranch name.
mixed$valueBranch value (scalar or array value).
Returns

Definition at line 109 of file Data.php.

110  {
111  if (null !== $this->_temp) {
112  return $this->offsetGet(0)->__set($name, $value);
113  }
114 
115  $this->_temp = $name;
116 
117  return $this->offsetSet(null, $value);
118  }
offsetSet($offset, $value)
Definition: Data.php:178
offsetGet($offset)
Definition: Data.php:142

Here is the call graph for this function:

Hoa\Core\Data\Data::offsetExists (   $offset)

Check if the n-th branch exists.

Parameters
mixed$offsetBranch index.
Returns
bool

Definition at line 126 of file Data.php.

127  {
128  if (null === $this->_temp || !is_int($offset)) {
129  return false;
130  }
131 
132  return true === array_key_exists($offset, $this->_data[$this->_temp]);
133  }
Hoa\Core\Data\Data::offsetGet (   $offset)

Get the n-th branch.

Parameters
mixed$offsetBranch index. Could be null to auto-increment.
Returns

Definition at line 142 of file Data.php.

143  {
144  if (null === $this->_temp) {
145  return;
146  }
147 
148  $handle = $this->_temp;
149  $this->_temp = null;
150 
151  if (false === array_key_exists($handle, $this->_data)) {
152  $this->_data[$handle] = [];
153 
154  if (null === $offset) {
155  return $this->_data[$handle][] = new self();
156  }
157 
158  return $this->_data[$handle][$offset] = new self();
159  }
160 
161  if (null === $offset ||
162  false === array_key_exists($offset, $this->_data[$handle])) {
163  return $this->_data[$handle][] = new self();
164  }
165 
166  return $this->_data[$handle][$offset];
167  }

Here is the caller graph for this function:

Hoa\Core\Data\Data::offsetSet (   $offset,
  $value 
)

Set the n-th branch.

Parameters
mixed$offsetBranch index. Could be null to auto-increment.
mixed$valueBranche value (scalar, array or Datable value).
Returns

Definition at line 178 of file Data.php.

179  {
180  if (null === $this->_temp) {
181  return;
182  }
183 
184  if ($value instanceof Datable) {
185  $value = $value->toArray();
186  }
187 
188  if (!is_array($value)) {
189  if (null === $offset) {
190  $this->_data[$this->_temp][] = $value;
191  } else {
192  $this->_data[$this->_temp][$offset] = $value;
193  }
194 
195  $this->_temp = null;
196 
197  return;
198  }
199 
200  if (null === $offset) {
201  $offset = 0;
202 
203  if (isset($this->_data[$this->_temp])) {
204  foreach ($this->_data[$this->_temp] as $i => $_) {
205  if (is_int($i)) {
206  $offset = $i;
207  }
208  }
209  }
210 
211  foreach ($value as $k => $v) {
212  if (is_int($k)) {
213  $temp = $this->_temp;
214  $this->offsetSet($k, $v);
215  $this->_temp = $temp;
216  } else {
217  $temp = $this->_temp;
218  $this->offsetGet($offset)->__set($k, $v);
219  $this->_temp = $temp;
220  }
221  }
222  } else {
223  foreach ($value as $k => $v) {
224  if (is_int($k)) {
225  continue;
226  }
227 
228  $temp = $this->_temp;
229  $this->offsetGet($offset)->__set($k, $v);
230  $this->_temp = $temp;
231  }
232  }
233 
234  $this->_temp = null;
235 
236  return;
237  }
offsetSet($offset, $value)
Definition: Data.php:178
offsetGet($offset)
Definition: Data.php:142

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Core\Data\Data::offsetUnset (   $offset)

Unset the n-th branch.

Parameters
mixed$offsetBranch index.
Returns

Definition at line 245 of file Data.php.

246  {
247  if (null === $this->_temp) {
248  return;
249  }
250 
251  if (null === $offset) {
252  return;
253  }
254 
255  unset($this->_data[$this->_temp][$offset]);
256  $this->_temp = null;
257 
258  return;
259  }
Hoa\Core\Data\Data::toArray ( )

Transform data as an array.

Returns
array

Implements Hoa\Core\Data\Datable.

Definition at line 266 of file Data.php.

267  {
268  $out = [];
269 
270  foreach ($this->_data as $key => &$ii) {
271  foreach ($ii as $i => &$value) {
272  if (is_object($value)
273  && $value instanceof Datable) {
274  $out[$i][$key] = $value->toArray();
275  } else {
276  $out[$i][$key] = &$value;
277  }
278  }
279  }
280 
281  return $out;
282  }

Member Data Documentation

Hoa\Core\Data\Data::$_data = []
protected

Definition at line 73 of file Data.php.

Hoa\Core\Data\Data::$_temp = null
protected

Definition at line 80 of file Data.php.


The documentation for this class was generated from the following file: