![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/shiplab/Helper/Config/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\Shiplab\Helper\Config; use Extmag\Shiplab\Model\Cache\Type; use Magento\Framework\App\ObjectManager; use Magento\Framework\Config\DataInterface; use Magento\Framework\Serialize\SerializerInterface; /** * Represents loaded and cached configuration data, should be used to gain access to different types * * @SuppressWarnings(PHPMD.NumberOfChildren) * @api * @since 100.0.2 */ class Data implements DataInterface { /** * Configuration reader * * @var ReaderInterface */ protected $_reader; /** * Configuration cache * * @var CacheInterface */ protected $_cache; /** * Cache tag * * @var string */ protected $_cacheId; /** * Cache tags * * @var array */ protected $cacheTags = []; /** * Config data * * @var array */ protected $_data = []; /** * @var ReaderInterface */ protected $reader; /** * @var CacheInterface */ protected $cache; /** * @var string */ protected $cacheId; /** * @var SerializerInterface */ protected $serializer; /** * @param Structure\Reader $reader * @param Type $cache * @param string $cacheId * @param SerializerInterface|null $serializer */ public function __construct( Structure\Reader $reader, Type $cache, $cacheId, SerializerInterface $serializer = null ) { $this->reader = $reader; $this->cache = $cache; $this->cacheId = $cacheId; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); $this->initData(); } /** * Initialise data for configuration * * @return void */ protected function initData() { $data = $this->cache->load($this->cacheId); if (false === $data) { $data = $this->reader->read(); $this->cache->save($this->serializer->serialize($data), $this->cacheId, $this->cacheTags); } else { $data = $this->serializer->unserialize($data); } $this->merge($data); } /** * Merge config data to the object * * @param array $config * * @return void */ public function merge(array $config) { if (isset($config['config']['system'])) { $config = $config['config']['system']; } $this->_data = array_replace_recursive($this->_data, $config); } /** * Get config value by key * * @param string $key * @param mixed $default * * @return array|mixed|null */ public function get($key = null, $default = null) { if ($key === null) { return $this->_data; } $keys = explode('/', $key); $data = $this->_data; foreach ($keys as $key) { if (is_array($data) && isset($data[$key])) { $data = $data[$key]; } else { return $default; } } return $data; } /** * Clear cache data * * @return void */ public function reset() { $this->cache->remove($this->cacheId); } }