From baf9360bae4c2fb0ac94fbec173a6042f571076c Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 4 May 2015 16:39:32 -0500 Subject: [PATCH] MAGETWO-34513: Move list to modules.php - created env.php and moved related items to it. --- .gitignore | 1 + .../Backend/Setup/ConfigOptionsList.php | 2 +- .../Test/Unit/Setup/ConfigOptionsListTest.php | 2 +- .../Magento/Mtf/App/State/AbstractState.php | 8 +- .../Magento/TestFramework/Application.php | 6 +- .../TestFramework/ObjectManagerFactory.php | 2 +- .../Magento/Framework/App/Bootstrap.php | 14 +++- .../Magento/Framework/App/Cache/State.php | 2 +- .../Framework/App/DeploymentConfig/Reader.php | 50 ++++++----- .../Framework/App/DeploymentConfig/Writer.php | 10 ++- .../Framework/App/ObjectManagerFactory.php | 21 +++-- .../Magento/Framework/App/Resource.php | 7 +- .../App/Test/Unit/Cache/StateTest.php | 2 +- .../Test/Unit/DeploymentConfig/ReaderTest.php | 84 ++++++++++++++----- .../Test/Unit/DeploymentConfig/WriterTest.php | 2 +- .../Unit/DeploymentConfig/_files/config.php | 2 +- .../Unit/DeploymentConfig/_files/custom.php | 2 +- .../_files/duplicateConfig.php | 9 ++ .../Test/Unit/DeploymentConfig/_files/env.php | 7 ++ .../Framework/Config/ConfigGenerator.php | 12 +-- .../Framework/Config/ConfigOptionsList.php | 1 + .../Framework/Config/File/ConfigFilePool.php | 6 +- .../Config/Test/Unit/ConfigGeneratorTest.php | 18 ++-- .../Test/Unit/File/ConfigFilePoolTest.php | 1 + .../Magento/Framework/Module/ModuleList.php | 2 +- setup/src/Magento/Setup/Model/Installer.php | 7 +- .../src/Magento/Setup/Model/ModuleStatus.php | 2 +- 27 files changed, 188 insertions(+), 94 deletions(-) create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/duplicateConfig.php create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/env.php diff --git a/.gitignore b/.gitignore index 1e6c8cdcecef6..2c056b8004d8f 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/app/code/Magento/Backend/Setup/ConfigOptionsList.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php index 83a953cd2f223..2acaa7759decb 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptionsList.php +++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php @@ -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]); diff --git a/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php index 279d11ddfbff8..56f18a840a3b6 100644 --- a/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php +++ b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php @@ -42,7 +42,7 @@ public function testCreateConfig() $expectedData = [ [ - 'file' => ConfigFilePool::APP_CONFIG, + 'file' => ConfigFilePool::APP_ENV, 'segment' => 'backend', 'data' => [ 'backend' => ['frontName' => 'admin'] diff --git a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php index 39d384533ef6d..7548bc922bb4b 100644 --- a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php +++ b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php @@ -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']; diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index 4d13da77e94c5..ca3ee5dbc85ee 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -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']; diff --git a/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php b/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php index e499e0d929ae1..763011a315b36 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php +++ b/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php @@ -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( diff --git a/lib/internal/Magento/Framework/App/Bootstrap.php b/lib/internal/Magento/Framework/App/Bootstrap.php index aaf238eadacaa..05fd99ceaa7d2 100644 --- a/lib/internal/Magento/Framework/App/Bootstrap.php +++ b/lib/internal/Magento/Framework/App/Bootstrap.php @@ -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 @@ -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); } /** @@ -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 * diff --git a/lib/internal/Magento/Framework/App/Cache/State.php b/lib/internal/Magento/Framework/App/Cache/State.php index d7de86d9ba359..20d55a3f001fc 100644 --- a/lib/internal/Magento/Framework/App/Cache/State.php +++ b/lib/internal/Magento/Framework/App/Cache/State.php @@ -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]]); } /** diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php index de210b4287105..ecc591efecc79 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php @@ -7,6 +7,7 @@ namespace Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Config\File\ConfigFilePool; /** * Deployment configuration reader @@ -14,69 +15,80 @@ 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 ?: []; } } diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index 644af48555deb..8d447e295bf4c 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -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; } /** @@ -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 { diff --git a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php index c712e82a26470..fff951bef2503 100644 --- a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php +++ b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php @@ -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) @@ -71,6 +70,13 @@ class ObjectManagerFactory */ protected $driverPool; + /** + * Configuration file pool + * + * @var ConfigFilePool + */ + protected $configFilePool; + /** * Factory * @@ -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; } /** @@ -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), @@ -179,10 +187,11 @@ 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] @@ -190,7 +199,7 @@ protected function createDeploymentConfig(DirectoryList $directoryList, array $a $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); } diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php index b38629a460a4f..02edd51d59987 100644 --- a/lib/internal/Magento/Framework/App/Resource.php +++ b/lib/internal/Magento/Framework/App/Resource.php @@ -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); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php index c5767244b54ee..8278d0fdfe45b 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php @@ -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(); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ReaderTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ReaderTest.php index a1bce3da6da24..561a496192003 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ReaderTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ReaderTest.php @@ -6,9 +6,9 @@ namespace Magento\Framework\App\Test\Unit\DeploymentConfig; -use \Magento\Framework\App\DeploymentConfig\Reader; - +use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Config\File\ConfigFilePool; class ReaderTest extends \PHPUnit_Framework_TestCase { @@ -17,17 +17,33 @@ class ReaderTest extends \PHPUnit_Framework_TestCase */ private $dirList; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $configFilePool; + protected function setUp() { $this->dirList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); + $this->dirList->expects($this->any()) + ->method('getPath') + ->with(DirectoryList::CONFIG) + ->willReturn(__DIR__ . '/_files'); + $this->configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false); + $this->configFilePool + ->expects($this->any()) + ->method('getPaths') + ->willReturn(['configKeyOne' => 'config.php', 'configKeyTwo' => 'env.php']); } public function testGetFile() { - $object = new Reader($this->dirList); - $this->assertEquals(Reader::DEFAULT_FILE, $object->getFile()); - $object = new Reader($this->dirList, 'custom.php'); - $this->assertEquals('custom.php', $object->getFile()); + $object = new Reader($this->dirList, $this->configFilePool); + $files = $object->getFiles(); + $this->assertArrayHasKey('configKeyOne', $files); + $this->assertArrayHasKey('configKeyTwo', $files); + $object = new Reader($this->dirList, $this->configFilePool, 'customOne.php'); + $this->assertEquals(['customOne.php'], $object->getFiles()); } /** @@ -36,34 +52,62 @@ public function testGetFile() */ public function testWrongFile() { - new Reader($this->dirList, 'invalid_name'); + new Reader($this->dirList, $this->configFilePool, 'invalid_name'); + } + + public function testLoad() + { + $files = [['configKeyOne', 'config.php'], ['configKeyTwo','env.php']]; + $this->configFilePool + ->expects($this->any()) + ->method('getPath') + ->will($this->returnValueMap($files)); + $object = new Reader($this->dirList, $this->configFilePool); + $this->assertSame(['fooKey' =>'foo', 'barKey' => 'bar', 'envKey' => 'env'], $object->load()); } /** * @param string $file * @param array $expected - * @dataProvider loadDataProvider + * @dataProvider loadCustomDataProvider */ - public function testLoad($file, $expected) + public function testCustomLoad($file, $expected) { - $this->dirList->expects($this->once()) - ->method('getPath') - ->with(DirectoryList::CONFIG) - ->willReturn(__DIR__ . '/_files'); - $object = new Reader($this->dirList, $file); - $this->assertSame($expected, $object->load()); + $configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false); + $configFilePool->expects($this->any())->method('getPaths')->willReturn(['custom.php']); + $configFilePool->expects($this->any())->method('getPath')->willReturn('custom.php'); + $object = new Reader($this->dirList, $configFilePool, 'custom.php'); + $this->assertSame(['bazKey' => 'baz'], $object->load()); } /** * @return array */ - public function loadDataProvider() + public function loadCustomDataProvider() { return [ - [null, ['foo', 'bar']], - ['config.php', ['foo', 'bar']], - ['custom.php', ['baz']], - ['nonexistent.php', []] + ['custom.php', ['bazKey' => 'baz']], + ['nonexistent.php', []], ]; } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Duplicate keys are present + */ + public function testDuplicateLoad() + { + $configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false); + $files = [['configKeyOne', 'config.php'], ['configKeyTwo','duplicateConfig.php']]; + $configFilePool + ->expects($this->any()) + ->method('getPath') + ->will($this->returnValueMap($files)); + $configFilePool + ->expects($this->any()) + ->method('getPaths') + ->willReturn(['configKeyOne' => 'config.php', 'configKeyTwo' => 'duplicateConfig.php']); + $object = new Reader($this->dirList, $configFilePool); + $this->assertSame(['fooKey' =>'foo', 'barKey' => 'bar'], $object->load()); + } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php index e1ab784199fa3..d9494ec1c3c48 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php @@ -59,7 +59,7 @@ protected function setUp() $this->deploymentConfig, $this->formatter ); - $this->reader->expects($this->any())->method('getFile')->willReturn('test.php'); + $this->reader->expects($this->any())->method('getFiles')->willReturn('test.php'); $this->dirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $filesystem->expects($this->any()) ->method('getDirectoryWrite') diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/config.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/config.php index e5519913e59aa..569b3df839882 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/config.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/config.php @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ -return ['foo', 'bar']; +return ['fooKey' => 'foo', 'barKey' => 'bar']; diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/custom.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/custom.php index 22cd13edb6746..4e57bcc515846 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/custom.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/custom.php @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ -return ['baz']; +return ['bazKey' => 'baz']; diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/duplicateConfig.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/duplicateConfig.php new file mode 100644 index 0000000000000..c344e00adae9c --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/duplicateConfig.php @@ -0,0 +1,9 @@ + 'someOtherBar']; diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/env.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/env.php new file mode 100644 index 0000000000000..660088939bca8 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/env.php @@ -0,0 +1,7 @@ + 'env']; diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index c7f4ac934ae47..dd15c2cae8c83 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -63,7 +63,7 @@ public function __construct(Random $random, DeploymentConfig $deploymentConfig) */ public function createInstallConfig() { - $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + $configData = new ConfigData(ConfigFilePool::APP_ENV); if ($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE) === null) { $configData->set(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE, date('r')); @@ -80,7 +80,7 @@ public function createCryptConfig(array $data) { $currentKey = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY); - $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + $configData = new ConfigData(ConfigFilePool::APP_ENV); if (isset($data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY])) { if ($currentKey !== null) { $key = $currentKey . "\n" . $data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]; @@ -106,7 +106,7 @@ public function createCryptConfig(array $data) */ public function createSessionConfig(array $data) { - $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + $configData = new ConfigData(ConfigFilePool::APP_ENV); if (isset($data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) { $configData->set( @@ -126,7 +126,7 @@ public function createSessionConfig(array $data) */ public function createDefinitionsConfig(array $data) { - $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + $configData = new ConfigData(ConfigFilePool::APP_ENV); if (!empty($data[ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT])) { $configData->set( @@ -146,7 +146,7 @@ public function createDefinitionsConfig(array $data) */ public function createDbConfig(array $data) { - $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + $configData = new ConfigData(ConfigFilePool::APP_ENV); $optional = [ ConfigOptionsList::INPUT_KEY_DB_HOST, @@ -188,7 +188,7 @@ public function createDbConfig(array $data) */ public function createResourceConfig() { - $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + $configData = new ConfigData(ConfigFilePool::APP_ENV); if ($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP) === null) { $configData->set(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP, 'default'); diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php index ac1a90652f40c..0e994e29ac29d 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php @@ -25,6 +25,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface const CONFIG_PATH_DEFINITION_FORMAT = 'definition/format'; const CONFIG_PATH_RESOURCE_DEFAULT_SETUP = 'resource/default_setup/connection'; const CONFIG_PATH_DB_CONNECTION_DEFAULT = 'db/connection/default/'; + const CONFIG_PATH_DB_CONNECTIONS= 'db/connection/'; const CONFIG_PATH_DB_PREFIX = 'db/table_prefix'; /**#@-*/ diff --git a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php index 882e846ec144e..b1d8e2d462371 100644 --- a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php +++ b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php @@ -6,14 +6,13 @@ namespace Magento\Framework\Config\File; -use Magento\Framework\App\Filesystem\DirectoryList; - /** * Stores file key to file name config */ class ConfigFilePool { const APP_CONFIG = 'app_config'; + const APP_ENV = 'app_env'; /** * Default application config @@ -21,7 +20,8 @@ class ConfigFilePool * @var array */ private $applicationConfigFiles = [ - self::APP_CONFIG => 'config.php' + self::APP_CONFIG => 'config.php', + self::APP_ENV => 'env.php', ]; /** diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php index 8479894c4e7ba..fd6498d592442 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php @@ -29,21 +29,21 @@ public function testCreateInstallConfig() { $returnValue = $this->configGeneratorObject->createInstallConfig([]); $this->assertInstanceOf('Magento\Framework\Config\Data\ConfigData', $returnValue); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); } public function testCreateCryptConfigWithInput() { $testData = [ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'some-test_key']; $returnValue = $this->configGeneratorObject->createCryptConfig($testData); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); $this->assertEquals(['crypt' => ['key' => 'some-test_key']], $returnValue->getData()); } public function testCreateCryptConfigWithoutInput() { $returnValue = $this->configGeneratorObject->createCryptConfig([]); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); $this->assertEquals(['crypt' => ['key' => md5('key')]], $returnValue->getData()); } @@ -51,19 +51,19 @@ public function testCreateSessionConfigWithInput() { $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'files']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_FILES]], $returnValue->getData()); $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'db']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_DB]], $returnValue->getData()); } public function testCreateSessionConfigWithoutInput() { $returnValue = $this->configGeneratorObject->createSessionConfig([]); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); $this->assertEquals([], $returnValue->getData()); } @@ -71,7 +71,7 @@ public function testCreateDefinitionsConfig() { $testData = [\Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; $returnValue = $this->configGeneratorObject->createDefinitionsConfig($testData); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); $this->assertEquals(['definition' => ['format' => 'test-format']], $returnValue->getData()); } @@ -84,7 +84,7 @@ public function testCreateDbConfig() ConfigOptionsList::INPUT_KEY_DB_PREFIX => 'testSomePrefix', ]; $returnValue = $this->configGeneratorObject->createDbConfig($testData); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); $dbData = $returnValue->getData(); $dbData = $dbData['db']; $this->assertArrayHasKey('table_prefix', $dbData); @@ -104,7 +104,7 @@ public function testCreateDbConfig() public function testCreateResourceConfig() { $returnValue = $this->configGeneratorObject->createResourceConfig(); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); $this->assertEquals(['resource' => ['default_setup' => ['connection' => 'default']]], $returnValue->getData()); } } diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php index 52bc10dc59b89..24452acb4336f 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php @@ -27,6 +27,7 @@ public function testGetPaths() { $expected['new_key'] = 'new_config.php'; $expected[ConfigFilePool::APP_CONFIG] = 'config.php'; + $expected[ConfigFilePool::APP_ENV] = 'env.php'; $this->assertEquals($expected, $this->configFilePool->getPaths()); } diff --git a/lib/internal/Magento/Framework/Module/ModuleList.php b/lib/internal/Magento/Framework/Module/ModuleList.php index aa5cf2dc92096..604d43fa04c4f 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList.php +++ b/lib/internal/Magento/Framework/Module/ModuleList.php @@ -140,7 +140,7 @@ public function isModuleInfoAvailable() private function loadConfigData() { if (null === $this->configData && ($this->config->isAvailable())) { - $this->configData = $this->config->getConfigData(ConfigOptionsList::KEY_MODULES); + $this->configData = $this->config->get(ConfigOptionsList::KEY_MODULES); } } } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 5db3a546a6611..a3a8f298bbdae 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -1028,9 +1028,7 @@ public function cleanupDb() { // stops cleanup if app/etc/config.php does not exist if ($this->deploymentConfig->isAvailable()) { - $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB); - $config = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION]; - + $config = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT); if ($config) { try { $connection = $this->connectionFactory->create($config); @@ -1093,8 +1091,7 @@ private function assertDeploymentConfigExists() */ private function assertDbAccessible() { - $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB); - $connectionConfig = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION]; + $connectionConfig = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT); $this->checkDatabaseConnection( $connectionConfig[ConfigOptionsList::KEY_NAME], $connectionConfig[ConfigOptionsList::KEY_HOST], diff --git a/setup/src/Magento/Setup/Model/ModuleStatus.php b/setup/src/Magento/Setup/Model/ModuleStatus.php index d49206b274a48..bfc8d9349a349 100644 --- a/setup/src/Magento/Setup/Model/ModuleStatus.php +++ b/setup/src/Magento/Setup/Model/ModuleStatus.php @@ -145,7 +145,7 @@ public function setIsEnabled($status, $moduleName) */ private function deselectDisabledModules() { - $existingModules = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_MODULES); + $existingModules = $this->deploymentConfig->get(ConfigOptionsList::KEY_MODULES); if (isset($existingModules)) { foreach ($existingModules as $module => $value) { if (!$value) {