public function testGetters()
 {
     $this->reader->expects($this->once())->method('load')->willReturn(self::$fixture);
     $this->assertSame(self::$flattenedFixture, $this->_deploymentConfig->get());
     // second time to ensure loader will be invoked only once
     $this->assertSame(self::$flattenedFixture, $this->_deploymentConfig->get());
     $this->assertSame('scalar_value', $this->_deploymentConfig->getSegment('segment1'));
     $this->assertSame(self::$fixture['segment2'], $this->_deploymentConfig->getSegment('segment2'));
 }
Exemple #2
0
 /**
  * Retrieve settings for all cache front-ends known to the system
  *
  * @return array Format: array('<frontend_id>' => array(<cache_settings>), ...)
  */
 protected function _getCacheSettings()
 {
     /*
      * Merging is intentionally implemented through array_merge() instead of array_replace_recursive()
      * to avoid "inheritance" of the default settings that become irrelevant as soon as cache storage type changes
      */
     $cacheInfo = $this->_deploymentConfig->getSegment(CacheConfig::CONFIG_KEY);
     if (null !== $cacheInfo) {
         $cacheConfig = new CacheConfig($cacheInfo);
         return array_merge($this->_frontendSettings, $cacheConfig->getCacheFrontendSettings());
     }
     return $this->_frontendSettings;
 }
 /**
  * Returns list of available resources
  *
  * @return array
  */
 public function toOptionArray()
 {
     $resourceOptions = [];
     $resourceInfo = $this->_deploymentConfig->getSegment(ResourceConfig::CONFIG_KEY);
     if (null !== $resourceInfo) {
         $resourceConfig = new ResourceConfig($resourceInfo);
         foreach (array_keys($resourceConfig->getData()) as $resourceName) {
             $resourceOptions[] = ['value' => $resourceName, 'label' => $resourceName];
         }
         sort($resourceOptions);
         reset($resourceOptions);
     }
     return $resourceOptions;
 }
 /**
  * Retrieve cache frontend identifier, associated with a cache type
  *
  * @param string $cacheType
  * @return string
  */
 protected function _getCacheFrontendId($cacheType)
 {
     $result = null;
     $cacheInfo = $this->_deploymentConfig->getSegment(CacheConfig::CONFIG_KEY);
     if (null !== $cacheInfo) {
         $cacheConfig = new CacheConfig($cacheInfo);
         $result = $cacheConfig->getCacheTypeFrontendId($cacheType);
     }
     if (!$result) {
         if (isset($this->_typeFrontendMap[$cacheType])) {
             $result = $this->_typeFrontendMap[$cacheType];
         } else {
             $result = \Magento\Framework\App\Cache\Frontend\Pool::DEFAULT_FRONTEND_ID;
         }
     }
     return $result;
 }
Exemple #5
0
 /**
  * @param Config\Reader $reader
  * @param \Magento\Framework\Config\ScopeInterface $configScope
  * @param \Magento\Framework\Config\CacheInterface $cache
  * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
  * @param string $cacheId
  * @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')
 {
     parent::__construct($reader, $configScope, $cache, $cacheId);
     foreach ($deploymentConfig->getSegment('resource') as $resourceName => $resourceData) {
         if (!isset($resourceData['connection'])) {
             throw new \InvalidArgumentException('Invalid initial resource configuration');
         }
         $this->_connectionNames[$resourceName] = $resourceData['connection'];
     }
 }
Exemple #6
0
 /**
  * Load statuses (enabled/disabled) of cache types
  *
  * @return void
  */
 private function load()
 {
     if (null === $this->statuses) {
         $this->statuses = [];
         if ($this->banAll) {
             return;
         }
         $this->statuses = $this->config->getSegment(ConfigSegment::SEGMENT_KEY) ?: [];
     }
 }
 /**
  * Marks modules that are disabled in deploymentConfig as unselected.
  *
  * @return void
  */
 private function deselectDisabledModules()
 {
     $existingModules = $this->deploymentConfig->getSegment(ModuleDeployment::CONFIG_KEY);
     if (isset($existingModules)) {
         foreach ($existingModules as $module => $value) {
             if (!$value) {
                 $this->allModules[$module]['selected'] = false;
             }
         }
     }
 }
 /**
  * Retrieve connection by $connectionName
  *
  * @param string $connectionName
  * @return bool|\Magento\Framework\DB\Adapter\AdapterInterface
  */
 public function getConnectionByName($connectionName)
 {
     if (isset($this->_connections[$connectionName])) {
         return $this->_connections[$connectionName];
     }
     $dbInfo = $this->deploymentConfig->getSegment(DbConfig::CONFIG_KEY);
     if (null === $dbInfo) {
         return false;
     }
     $dbConfig = new DbConfig($dbInfo);
     $connectionConfig = $dbConfig->getConnection($connectionName);
     if ($connectionConfig) {
         $connection = $this->_connectionFactory->create($connectionConfig);
     }
     if (empty($connection)) {
         return false;
     }
     $this->_connections[$connectionName] = $connection;
     return $connection;
 }
 /**
  * Loads configuration data only
  *
  * @return void
  */
 private function loadConfigData()
 {
     if (null === $this->configData) {
         $this->configData = $this->config->getSegment(ModuleList\DeploymentConfig::CONFIG_KEY);
     }
 }
 /**
  * Validates that MySQL is accessible and MySQL version is supported
  *
  * @return void
  */
 private function assertDbAccessible()
 {
     $segment = $this->deploymentConfig->getSegment(DbConfig::CONFIG_KEY);
     $dbConfig = new DbConfig($segment);
     $config = $dbConfig->getConnection(\Magento\Framework\App\Resource\Config::DEFAULT_SETUP_CONNECTION);
     $this->checkDatabaseConnection($config[DbConfig::KEY_NAME], $config[DbConfig::KEY_HOST], $config[DbConfig::KEY_USER], $config[DbConfig::KEY_PASS]);
     if (isset($config[DbConfig::KEY_PREFIX])) {
         $this->checkDatabaseTablePrefix($config[DbConfig::KEY_PREFIX]);
     }
 }
 /**
  * Retrieve the database adapter instance
  *
  * @return \Magento\TestFramework\Db\AbstractDb
  */
 public function getDbInstance()
 {
     if (null === $this->_db) {
         if ($this->isInstalled()) {
             $deploymentConfig = new DeploymentConfig(new \Magento\Framework\App\DeploymentConfig\Reader($this->dirList), []);
             $dbConfig = new DbConfig($deploymentConfig->getSegment(DbConfig::CONFIG_KEY));
             $dbInfo = $dbConfig->getConnection('default');
             $host = $dbInfo['host'];
             $user = $dbInfo['username'];
             $password = $dbInfo['password'];
             $dbName = $dbInfo['dbname'];
         } else {
             $installConfig = $this->getInstallConfig();
             $host = $installConfig['db_host'];
             $user = $installConfig['db_user'];
             $password = $installConfig['db_pass'];
             $dbName = $installConfig['db_name'];
         }
         $this->_db = new Db\Mysql($host, $user, $password, $dbName, $this->getTempDir(), $this->_shell);
     }
     return $this->_db;
 }