Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractSimpleObject.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework\Api;
7 
12 abstract class AbstractSimpleObject
13 {
17  protected $_data;
18 
24  public function __construct(array $data = [])
25  {
26  $this->_data = $data;
27  }
28 
35  protected function _get($key)
36  {
37  return $this->_data[$key] ?? null;
38  }
39 
47  public function setData($key, $value)
48  {
49  $this->_data[$key] = $value;
50  return $this;
51  }
52 
58  public function __toArray()
59  {
61  $hasToArray = function ($model) {
62  return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);
63  };
64  foreach ($data as $key => $value) {
65  if ($hasToArray($value)) {
66  $data[$key] = $value->__toArray();
67  } elseif (is_array($value)) {
68  foreach ($value as $nestedKey => $nestedValue) {
69  if ($hasToArray($nestedValue)) {
70  $value[$nestedKey] = $nestedValue->__toArray();
71  }
72  }
73  $data[$key] = $value;
74  }
75  }
76  return $data;
77  }
78 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$value
Definition: gender.phtml:16