/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/App/ResourceConnection/Config.php
110 строк
4 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2015 Adobe * All Rights Reserved. */ namespace Magento\Framework\App\ResourceConnection; use Magento\Framework\Config\ConfigOptionsListConstants; use Magento\Framework\Serialize\SerializerInterface; /** * Resource configuration, uses application configuration to retrieve resource connection information */ class Config extends \Magento\Framework\Config\Data\Scoped implements ConfigInterface { /** * List of connection names per resource * * @var array */ protected $_connectionNames = []; /** * @var \Magento\Framework\App\DeploymentConfig */ private $deploymentConfig; /** * @var bool */ private $initialized = false; /** * Constructor * * @param Config\Reader $reader * @param \Magento\Framework\Config\ScopeInterface $configScope * @param \Magento\Framework\Config\CacheInterface $cache * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig * @param string|null $cacheId * @param SerializerInterface|null $serializer * @throws \InvalidArgumentException */ public function __construct( Config\Reader $reader, \Magento\Framework\Config\ScopeInterface $configScope, \Magento\Framework\Config\CacheInterface $cache, \Magento\Framework\App\DeploymentConfig $deploymentConfig, $cacheId = 'resourcesCache', ?SerializerInterface $serializer = null ) { parent::__construct($reader, $configScope, $cache, $cacheId, $serializer); $this->deploymentConfig = $deploymentConfig; } /** * Retrieve resource connection instance name * * @param string $resourceName * @return string */ public function getConnectionName($resourceName) { $this->initConnections(); $connectionName = \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION; if (!isset($this->_connectionNames[$resourceName])) { $resourcesConfig = $this->get(); $pointerResourceName = $resourceName; while (true) { if (isset($resourcesConfig[$pointerResourceName]['connection'])) { $connectionName = $resourcesConfig[$pointerResourceName]['connection']; $this->_connectionNames[$resourceName] = $connectionName; break; } elseif (isset($this->_connectionNames[$pointerResourceName])) { $this->_connectionNames[$resourceName] = $this->_connectionNames[$pointerResourceName]; $connectionName = $this->_connectionNames[$resourceName]; break; } elseif (isset($resourcesConfig[$pointerResourceName]['extends'])) { $pointerResourceName = $resourcesConfig[$pointerResourceName]['extends']; } else { break; } } } else { $connectionName = $this->_connectionNames[$resourceName]; } return $connectionName; } /** * Initialise connections * * @return void */ private function initConnections() { if (!$this->initialized) { $this->initialized = true; $resource = $this->deploymentConfig->getConfigData(ConfigOptionsListConstants::KEY_RESOURCE) ?: []; foreach ($resource as $resourceName => $resourceData) { if (!isset($resourceData['connection'])) { throw new \InvalidArgumentException('Invalid initial resource configuration'); } $this->_connectionNames[$resourceName] = $resourceData['connection']; } } } }