Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class Config extends \Magento\Framework\Config\Data\Scoped implements ConfigInterface
15 {
21  protected $_connectionNames = [];
22 
26  private $deploymentConfig;
27 
31  private $initialized = false;
32 
44  public function __construct(
45  Config\Reader $reader,
46  \Magento\Framework\Config\ScopeInterface $configScope,
47  \Magento\Framework\Config\CacheInterface $cache,
48  \Magento\Framework\App\DeploymentConfig $deploymentConfig,
49  $cacheId = 'resourcesCache',
50  SerializerInterface $serializer = null
51  ) {
52  parent::__construct($reader, $configScope, $cache, $cacheId, $serializer);
53  $this->deploymentConfig = $deploymentConfig;
54  }
55 
62  public function getConnectionName($resourceName)
63  {
64  $this->initConnections();
66 
67  if (!isset($this->_connectionNames[$resourceName])) {
68  $resourcesConfig = $this->get();
69  $pointerResourceName = $resourceName;
70  while (true) {
71  if (isset($resourcesConfig[$pointerResourceName]['connection'])) {
72  $connectionName = $resourcesConfig[$pointerResourceName]['connection'];
73  $this->_connectionNames[$resourceName] = $connectionName;
74  break;
75  } elseif (isset($this->_connectionNames[$pointerResourceName])) {
76  $this->_connectionNames[$resourceName] = $this->_connectionNames[$pointerResourceName];
77  $connectionName = $this->_connectionNames[$resourceName];
78  break;
79  } elseif (isset($resourcesConfig[$pointerResourceName]['extends'])) {
80  $pointerResourceName = $resourcesConfig[$pointerResourceName]['extends'];
81  } else {
82  break;
83  }
84  }
85  } else {
86  $connectionName = $this->_connectionNames[$resourceName];
87  }
88 
89  return $connectionName;
90  }
91 
97  private function initConnections()
98  {
99  if (!$this->initialized) {
100  $this->initialized = true;
101  $resource = $this->deploymentConfig->getConfigData(ConfigOptionsListConstants::KEY_RESOURCE) ?: [];
102  foreach ($resource as $resourceName => $resourceData) {
103  if (!isset($resourceData['connection'])) {
104  throw new \InvalidArgumentException('Invalid initial resource configuration');
105  }
106  $this->_connectionNames[$resourceName] = $resourceData['connection'];
107  }
108  }
109  }
110 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$resource
Definition: bulk.php:12
__construct(Config\Reader $reader, \Magento\Framework\Config\ScopeInterface $configScope, \Magento\Framework\Config\CacheInterface $cache, \Magento\Framework\App\DeploymentConfig $deploymentConfig, $cacheId='resourcesCache', SerializerInterface $serializer=null)
Definition: Config.php:44
$deploymentConfig