Skip to content

Commit

Permalink
MAGETWO-34513: Move list to modules.php
Browse files Browse the repository at this point in the history
- created env.php and moved related items to it.
  • Loading branch information
mazhalai committed May 4, 2015
1 parent 38b327f commit baf9360
Show file tree
Hide file tree
Showing 27 changed files with 188 additions and 94 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ atlassian*
/.gitattributes
/app/config_sandbox
/app/etc/config.php
/app/etc/env.php
/app/code/Magento/TestModule*
/lib/internal/flex/uploader/.actionScriptProperties
/lib/internal/flex/uploader/.flexProperties
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Setup/ConfigOptionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getOptions()
*/
public function createConfig(array $options, DeploymentConfig $deploymentConfig)
{
$configData = new ConfigData(ConfigFilePool::APP_CONFIG);
$configData = new ConfigData(ConfigFilePool::APP_ENV);

if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])) {
$configData->set(self::CONFIG_PATH_BACKEND_FRONTNAME, $options[self::INPUT_KEY_BACKEND_FRONTNAME]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testCreateConfig()

$expectedData = [
[
'file' => ConfigFilePool::APP_CONFIG,
'file' => ConfigFilePool::APP_ENV,
'segment' => 'backend',
'data' => [
'backend' => ['frontName' => 'admin']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public function clearInstance()
$dirList = \Magento\Mtf\ObjectManagerFactory::getObjectManager()
->get('Magento\Framework\Filesystem\DirectoryList');

$reader = new Reader($dirList);
$configFilePool = \Magento\Mtf\ObjectManagerFactory::getObjectManager()
->get('\Magento\Framework\Config\File\ConfigFilePool');

$reader = new Reader($dirList, $configFilePool);
$deploymentConfig = new DeploymentConfig($reader);
$dbConfig = $deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB);
$dbInfo = $dbConfig['connection']['default'];
$dbInfo = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT);
$host = $dbInfo['host'];
$user = $dbInfo['username'];
$password = $dbInfo['password'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ public function getDbInstance()
{
if (null === $this->_db) {
if ($this->isInstalled()) {
$reader = new Reader($this->dirList);
$configPool = new \Magento\Framework\Config\File\ConfigFilePool();
$reader = new Reader($this->dirList, $configPool);
$deploymentConfig = new DeploymentConfig($reader, []);
$dbConfig = $deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB);
$dbInfo = $dbConfig['connection']['default'];
$dbInfo = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT);
$host = $dbInfo['host'];
$user = $dbInfo['username'];
$password = $dbInfo['password'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function restore(ObjectManager $objectManager, $directoryList, array $arg
$objectManager->configure($this->_primaryConfigData);
$objectManager->addSharedInstance($this->directoryList, 'Magento\Framework\App\Filesystem\DirectoryList');
$objectManager->addSharedInstance($this->directoryList, 'Magento\Framework\Filesystem\DirectoryList');
$deploymentConfig = $this->createDeploymentConfig($directoryList, $arguments);
$deploymentConfig = $this->createDeploymentConfig($directoryList, $this->configFilePool, $arguments);
$this->factory->setArguments($arguments);
$objectManager->addSharedInstance($deploymentConfig, 'Magento\Framework\App\DeploymentConfig');
$objectManager->addSharedInstance(
Expand Down
14 changes: 13 additions & 1 deletion lib/internal/Magento/Framework/App/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\Autoload\Populator;
use Magento\Framework\Filesystem\DriverPool;
use Magento\Framework\Profiler;
use Magento\Framework\Config\File\ConfigFilePool;

/**
* A bootstrap of Magento application
Expand Down Expand Up @@ -147,7 +148,8 @@ public static function createObjectManagerFactory($rootDir, array $initParams)
{
$dirList = self::createFilesystemDirectoryList($rootDir, $initParams);
$driverPool = self::createFilesystemDriverPool($initParams);
return new ObjectManagerFactory($dirList, $driverPool);
$configFilePool = self::createConfigFilePool();
return new ObjectManagerFactory($dirList, $driverPool, $configFilePool);
}

/**
Expand Down Expand Up @@ -181,6 +183,16 @@ public static function createFilesystemDriverPool(array $initParams)
return new DriverPool($extraDrivers);
}

/**
* Creates instance of configuration files pool
*
* @return DriverPool
*/
public static function createConfigFilePool()
{
return new ConfigFilePool();
}

/**
* Constructor
*
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/App/Cache/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function setEnabled($cacheType, $isEnabled)
public function persist()
{
$this->load();
$this->writer->saveConfig([ConfigFilePool::APP_CONFIG => [self::CACHE_KEY => $this->statuses]]);
$this->writer->saveConfig([ConfigFilePool::APP_ENV => [self::CACHE_KEY => $this->statuses]]);
}

/**
Expand Down
50 changes: 31 additions & 19 deletions lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,88 @@
namespace Magento\Framework\App\DeploymentConfig;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Config\File\ConfigFilePool;

/**
* Deployment configuration reader
*/
class Reader
{
/**
* Default configuration file name
* @var DirectoryList
*/
const DEFAULT_FILE = 'config.php';
private $dirList;

/**
* Directory list object
*
* @var DirectoryList
* @var ConfigFilePool
*/
private $dirList;
private $configFilePool;

/**
* Custom file name
* Configuration file names
*
* @var string
* @var array
*/
private $file;
private $files;

/**
* Constructor
*
* @param DirectoryList $dirList
* @param ConfigFilePool $configFilePool
* @param null|string $file
* @throws \InvalidArgumentException
*/
public function __construct(DirectoryList $dirList, $file = null)
public function __construct(DirectoryList $dirList, ConfigFilePool $configFilePool, $file = null)
{
$this->dirList = $dirList;
$this->configFilePool = $configFilePool;
if (null !== $file) {
if (!preg_match('/^[a-z\d\.\-]+\.php$/i', $file)) {
throw new \InvalidArgumentException("Invalid file name: {$file}");
}
$this->file = $file;
$this->files = [$file];
} else {
$this->file = self::DEFAULT_FILE;
$this->files = $this->configFilePool->getPaths();
}
}

/**
* Gets the file name
*
* @return string
* @return array
*/
public function getFile()
public function getFiles()
{
return $this->file;
return $this->files;
}

/**
* Loads the configuration file
*
* @param string $configFile
* @throws \Exception
* @return array
*/
public function load($configFile = null)
{
$path = $this->dirList->getPath(DirectoryList::CONFIG);
if ($configFile) {
$file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $configFile;
$result = @include $path . '/' . $this->configFilePool->getPath($configFile);
} else {
$file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $this->file;
}
$configFiles = $this->configFilePool->getPaths();
$result = [];
foreach ($configFiles as $fileKey => $config) {
$configFile = $path . '/' . $this->configFilePool->getPath($fileKey);
$fileData = @include $configFile;

$result = @include $file;
if (empty(array_intersect_key($result, $fileData))) {
$result = array_replace_recursive($result, $fileData ?: []);
} else {
throw new \Exception('Duplicate keys are present');
}
}
}
return $result ?: [];
}
}
10 changes: 6 additions & 4 deletions lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ public function __construct(
public function checkIfWritable()
{
$configDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG);
if ($configDirectory->isWritable($this->reader->getFile())) {
return true;
foreach ($this->reader->getFiles() as $file) {
if (!$configDirectory->isWritable($file)) {
return false;
}
}
return false;
return true;
}

/**
Expand All @@ -99,7 +101,7 @@ public function saveConfig(array $data, $override = false)
if (isset($paths[$fileKey])) {

if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) {
$currentData = $this->reader->load($paths[$fileKey]);
$currentData = $this->reader->load($fileKey);
if ($override) {
$config = array_merge($currentData, $config);
} else {
Expand Down
21 changes: 15 additions & 6 deletions lib/internal/Magento/Framework/App/ObjectManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
use Magento\Framework\Interception\ObjectManager\ConfigInterface;
use Magento\Framework\ObjectManager\Definition\Compiled\Serialized;
use Magento\Framework\App\ObjectManager\Environment;
use Magento\Framework\App\EnvironmentFactory;
use Magento\Framework\App\EnvironmentInterface;
use Magento\Framework\Config\File\ConfigFilePool;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -71,6 +70,13 @@ class ObjectManagerFactory
*/
protected $driverPool;

/**
* Configuration file pool
*
* @var ConfigFilePool
*/
protected $configFilePool;

/**
* Factory
*
Expand All @@ -83,11 +89,13 @@ class ObjectManagerFactory
*
* @param DirectoryList $directoryList
* @param DriverPool $driverPool
* @param ConfigFilePool $configFilePool
*/
public function __construct(DirectoryList $directoryList, DriverPool $driverPool)
public function __construct(DirectoryList $directoryList, DriverPool $driverPool, ConfigFilePool $configFilePool)
{
$this->directoryList = $directoryList;
$this->driverPool = $driverPool;
$this->configFilePool = $configFilePool;
}

/**
Expand All @@ -100,7 +108,7 @@ public function __construct(DirectoryList $directoryList, DriverPool $driverPool
*/
public function create(array $arguments)
{
$deploymentConfig = $this->createDeploymentConfig($this->directoryList, $arguments);
$deploymentConfig = $this->createDeploymentConfig($this->directoryList, $this->configFilePool, $arguments);
$arguments = array_merge($deploymentConfig->get(), $arguments);
$definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory(
$this->driverPool->getDriver(DriverPool::FILE),
Expand Down Expand Up @@ -179,18 +187,19 @@ public function create(array $arguments)
* Creates deployment configuration object
*
* @param DirectoryList $directoryList
* @param ConfigFilePool $configFilePool
* @param array $arguments
* @return DeploymentConfig
*/
protected function createDeploymentConfig(DirectoryList $directoryList, array $arguments)
protected function createDeploymentConfig(DirectoryList $directoryList, ConfigFilePool $configFilePool, array $arguments)
{
$customFile = isset($arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG_FILE])
? $arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG_FILE]
: null;
$customData = isset($arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG])
? $arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG]
: [];
$reader = new DeploymentConfig\Reader($directoryList, $customFile);
$reader = new DeploymentConfig\Reader($directoryList, $configFilePool, $customFile);
return new DeploymentConfig($reader, $customData);
}

Expand Down
7 changes: 2 additions & 5 deletions lib/internal/Magento/Framework/App/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ public function getConnectionByName($connectionName)
return $this->_connections[$connectionName];
}

$dbInfo = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB);
if (null === $dbInfo) {
return false;
}
$connectionConfig = $dbInfo['connection'][$connectionName];
$connections = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTIONS);
$connectionConfig = $connections[$connectionName];
if ($connectionConfig) {
$connection = $this->_connectionFactory->create($connectionConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testPersist()
{
$model = new State($this->config, $this->writer);
$this->config->expects($this->once())->method('getConfigData')->willReturn(['test_cache_type' => true]);
$configValue = [ConfigFilePool::APP_CONFIG => ['cache_types' => ['test_cache_type' => true]]];
$configValue = [ConfigFilePool::APP_ENV => ['cache_types' => ['test_cache_type' => true]]];
$this->writer->expects($this->once())->method('saveConfig')->with($configValue);
$model->persist();
}
Expand Down
Loading

0 comments on commit baf9360

Please sign in to comment.