Example #1
0
 /**
  * @test
  */
 public function configMergeTest()
 {
     $xml1 = new \SimpleXMLElement($this->_xml1);
     $xml2 = new \SimpleXMLElement($this->_xml2);
     \Magelight\Components\Loaders\Config::mergeConfig($xml1, $xml2);
     $this->assertEquals('override', (string) $xml1->test->file);
 }
Example #2
0
 /**
  * Load config for application modules
  *
  * @return void
  */
 public function load()
 {
     $app = \Magelight\App::getInstance();
     $loader = \Magelight\Components\Loaders\Config::forge();
     $loader->loadConfig($app->getAppDir() . DS . 'etc' . DS . 'config.xml');
     $this->config = $loader->getConfig();
     $modulesConfigString = $this->getConfigBool('global/app/cache_modules_config', false) ? $this->cache()->get($this->buildCacheKey('modules_config')) : false;
     /* Loading modules config */
     if (!$modulesConfigString) {
         $loader->setConfig($this->config);
         foreach (array_reverse($app->getModuleDirectories()) as $modulesDir) {
             foreach (\Magelight\Components\Modules::getInstance()->getActiveModules() as $module) {
                 $filename = $loader->getModulesConfigFilePath($modulesDir, $module);
                 if ($filename) {
                     $loader->loadConfig($filename);
                 }
             }
         }
         $modulesConfig = $loader->getConfig();
         if ($this->getConfigBool('global/app/cache_modules_config', false)) {
             $this->cache()->set($this->buildCacheKey('modules_config'), $modulesConfig->asXML(), 3600);
         }
         $this->config = $modulesConfig;
     } else {
         $this->config = simplexml_load_string($modulesConfigString);
     }
     unset($loader);
 }
Example #3
0
 public function testLoadFromCacheMiss()
 {
     $appConfig = '<config><global>
         <app>
             <cache_modules_config>1</cache_modules_config>
         </app>
     </global></config>';
     $expectedConfig = new \SimpleXMLElement('<config><global>
         <app>
             <cache_modules_config>0</cache_modules_config>
             <framework_config_data>framework</framework_config_data>
             <app_module_config_data>app.domain</app_module_config_data>
             <bool_data_true>1</bool_data_true>
             <bool_data_false>0</bool_data_false>
             <int_data>123</int_data>
             <float_data>123.456</float_data>
             <array_data>
                 <node_1>data</node_1>
                 <node_2>data_node_2</node_2>
             </array_data>
             <string_data>some string</string_data>
             <config_with_attribute attribute_1="attribute_value">config_string</config_with_attribute>
         </app>
     </global></config>');
     $this->appMock->expects($this->once())->method('getAppDir')->will($this->returnValue('/app'));
     $this->appMock->expects($this->once())->method('getModuleDirectories')->will($this->returnValue(['/app/modules', '/framework/modules']));
     $this->configLoaderMock->expects($this->at(0))->method('loadConfig')->with('/app' . DS . 'etc' . DS . 'config.xml');
     $this->configLoaderMock->expects($this->at(1))->method('getConfig')->will($this->returnValue(new \SimpleXMLElement($appConfig)));
     $this->modulesMock->expects($this->any())->method('getActiveModules')->will($this->returnValue([['name' => 'Magelight_Module', 'path' => 'Magelight\\Module'], ['name' => 'App_Module', 'path' => 'App\\Module']]));
     $this->configLoaderMock->expects($this->any())->method('getModulesConfigFilePath')->will($this->returnValueMap([['/framework/modules', ['name' => 'Magelight_Module', 'path' => 'Magelight\\Module'], '/framework/modules/Magelight\\Module' . DS . 'etc' . DS . 'config.xml'], ['/app/modules', ['name' => 'Magelight_Module', 'path' => 'Magelight\\Module'], null], ['/framework/modules', ['name' => 'App_Module', 'path' => 'App\\Module'], null], ['/app/modules', ['name' => 'App_Module', 'path' => 'App\\Module'], '/app/modules/App\\Module' . DS . 'etc' . DS . 'config.xml']]));
     $this->configLoaderMock->expects($this->at(3))->method('loadConfig')->with('/framework/modules/Magelight\\Module' . DS . 'etc' . DS . 'config.xml');
     $this->configLoaderMock->expects($this->at(7))->method('loadConfig')->with('/app/modules/App\\Module' . DS . 'etc' . DS . 'config.xml');
     $this->configLoaderMock->expects($this->at(8))->method('getConfig')->will($this->returnValue($expectedConfig));
     $this->cacheAdapterMock->expects($this->once())->method('set')->with($this->config->buildCacheKey('modules_config'), $expectedConfig->asXML(), 3600);
     $this->config->load();
     $this->assertEquals('framework', $this->config->getConfigString('/global/app/framework_config_data'));
     $this->assertEquals('app.domain', $this->config->getConfigString('/global/app/app_module_config_data'));
     $this->assertTrue($this->config->getConfigBool('/global/app/bool_data_true'));
     $this->assertFalse($this->config->getConfigBool('/global/app/bool_data_false'));
     $this->assertInternalType('int', $this->config->getConfigInt('/global/app/int_data'));
     $this->assertEquals(123, $this->config->getConfigInt('/global/app/int_data'));
     $this->assertInternalType('float', $this->config->getConfigFloat('/global/app/float_data'));
     $this->assertEquals(123.456, $this->config->getConfigFloat('/global/app/float_data'));
     $this->assertInternalType('array', $this->config->getConfigArray('/global/app/array_data'));
     $this->assertEquals(['node_1' => 'data', 'node_2' => 'data_node_2'], $this->config->getConfigArray('/global/app/array_data'));
     $this->assertInternalType('string', $this->config->getConfigString('/global/app/string_data'));
     $this->assertEquals('some string', $this->config->getConfigString('/global/app/string_data'));
     $this->assertInternalType('string', $this->config->getConfigAttribute('/global/app/config_with_attribute', 'attribute_1'));
     $this->assertEquals('attribute_value', $this->config->getConfigAttribute('/global/app/config_with_attribute', 'attribute_1'));
     $this->assertInternalType('string', $this->config->getConfigString('/global/app/unexistent_node', 'default_value'));
     $this->assertEquals('default_value', $this->config->getConfigString('/global/app/unexistent_node', 'default_value'));
     $this->assertInternalType('array', $this->config->getConfigSet('/global/app'));
     $this->assertInternalType('string', $this->config->getConfigXmlString());
     $this->assertEquals($expectedConfig->asXML(), $this->config->getConfigXmlString());
 }
Example #4
0
 /**
  * Get entities configuration
  *
  * @return mixed|\SimpleXMLElement
  */
 public function getEntitiesConfig()
 {
     if (empty($this->entitiesConfig)) {
         $entitiesConfig = clone \Magelight\Config::getInstance()->getConfig('admin/scaffold/entities');
         $this->defaultEntityConfig = clone $entitiesConfig->default;
         unset($entitiesConfig->default);
         foreach ($entitiesConfig->children() as $child) {
             /** @var $child \SimpleXMLElement */
             /** @var $draft \SimpleXMLElement */
             /** @var $fieldDraft \SimpleXMLElement */
             $draft = clone $this->defaultEntityConfig;
             \Magelight\Components\Loaders\Config::mergeConfig($draft, $child);
             \Magelight\Components\Loaders\Config::mergeConfig($entitiesConfig->{$child->getName()}, $draft);
             $defaultFieldConfig = clone $entitiesConfig->{$child->getName()}->fields->default;
             unset($entitiesConfig->{$child->getName()}->fields->default);
             foreach ($entitiesConfig->{$child->getName()}->fields->children() as $field) {
                 $fieldDraft = clone $defaultFieldConfig;
                 \Magelight\Components\Loaders\Config::mergeConfig($fieldDraft, $field);
                 \Magelight\Components\Loaders\Config::mergeConfig($entitiesConfig->{$child->getName()}->fields->{$field->getName()}, $fieldDraft);
             }
         }
         $this->entitiesConfig = $entitiesConfig;
     }
     return $this->entitiesConfig;
 }