/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Api/AbstractSimpleObject.php
82 строки
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2014 Adobe * All Rights Reserved. */ declare(strict_types=1); namespace Magento\Framework\Api; /** * Base Class for simple data Objects * @SuppressWarnings(PHPMD.NumberOfChildren) * * @api */ abstract class AbstractSimpleObject { /** * @var array */ protected $_data; /** * Initialize internal storage * * @param array $data */ public function __construct(array $data = []) { $this->_data = $data; } /** * Retrieves a value from the data array if set, or null otherwise. * * @param string $key * @return mixed|null */ protected function _get($key) { return $this->_data[$key] ?? null; } /** * Set value for the given key * * @param string $key * @param mixed $value * @return $this */ public function setData($key, $value) { $this->_data[$key] = $value; return $this; } /** * Return Data Object data in array format. * * @return array */ public function __toArray() { $data = $this->_data; $hasToArray = function ($model) { return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']); }; foreach ($data as $key => $value) { if ($hasToArray($value)) { $data[$key] = $value->__toArray(); } elseif (is_array($value)) { foreach ($value as $nestedKey => $nestedValue) { if ($hasToArray($nestedValue)) { $value[$nestedKey] = $nestedValue->__toArray(); } } $data[$key] = $value; } } return $data; } }