/** * @see BackBee\Config\Persistor\PersistorInterface::persist */ public function persist(Config $config, array $configToPersist) { if (array_key_exists('override_site', $configToPersist)) { $configToPersist = array('override_site' => $configToPersist['override_site']); } $baseScope = 'BUNDLE_CONFIG.'; $key = $this->app->getContainer()->get('bundle.loader')->getBundleIdByBaseDir($config->getBaseDir()); if (null === $key) { $key = $application; $baseScope = 'APPLICATION_CONFIG.'; } $scope = $baseScope . $this->app->getContext() . '.' . $this->app->getEnvironment(); $registry = $this->app->getEntityManager()->getRepository('BackBee\\Bundle\\Registry')->findOneBy(array('key' => $key, 'scope' => $scope)); if (null === $registry) { $registry = new RegistryEntity(); $registry->setKey($key); $registry->setScope($scope); $this->app->getEntityManager()->persist($registry); } $registry->setValue(serialize($configToPersist)); $success = true; try { $this->app->getEntityManager()->flush($registry); } catch (\Exception $e) { $success = false; } return $success; }
/** * Getters of toolbar complete config * * @return JsonResponse */ public function getAction() { $settings = $this->config->getSettingsConfig(); $corePlugins = $this->pluginManager->getPluginConfiguration(); $config = array_merge($settings ?: [], $corePlugins); return new JsonResponse($this->resolveResourceBaseUrl($config)); }
/** * test extend application config with and without context and environment. * * @covers ::__construct * @covers ::extend * @covers ::doApplicationConfigExtend */ public function testExtendApplicationConfig() { $this->application->setBB_Dir(__DIR__ . '/ConfiguratorTest_Resources/bbdir'); $this->application->setBase_Repository(__DIR__ . '/ConfiguratorTest_Resources/repository'); $this->application->setOverrided_Config(false); // Test without context and without environment $config = new Config($this->application->getBBDir()); $this->assertEquals(array('parameters' => array('base_directory' => 'bbdir', 'context' => 'default', 'environment' => '')), $config->getAllSections()); $config_builder = new Configurator($this->application, $this->bundleLoader); $config_builder->extend(Configurator::APPLICATION_CONFIG, $config); $this->assertEquals(array('parameters' => array('base_directory' => 'repository', 'context' => 'default', 'environment' => '', 'foo' => 'bar')), $config->getAllSections()); // Test with context and without environment $this->application->setContext('api'); $config = new Config($this->application->getBBDir()); $config_builder = new Configurator($this->application, $this->bundleLoader); $config_builder->extend(Configurator::APPLICATION_CONFIG, $config); $this->assertEquals(array('parameters' => array('base_directory' => 'repository', 'context' => 'api', 'environment' => '', 'foo' => 'bar', 'bar' => 'foo')), $config->getAllSections()); // Test with context and with environment; test also with override config setted at true $this->application->setContext('api'); $this->application->setEnvironment('preprod'); $this->application->setOverrided_Config(true); $config = new Config($this->application->getBBDir()); $config_builder = new Configurator($this->application, $this->bundleLoader); $config_builder->extend(Configurator::APPLICATION_CONFIG, $config); $this->assertEquals(array('parameters' => array('context' => 'api', 'environment' => 'preprod', 'overrided_config' => true)), $config->getAllSections()); }
/** * @see BackBee\Config\Persistor\PersistorInterface::persist */ public function persist(Config $config, array $configToPersist) { try { $success = file_put_contents($this->getConfigDumpRightDirectory($config->getBaseDir()) . DIRECTORY_SEPARATOR . 'config.yml', Yaml::dump($configToPersist)); } catch (\Exception $e) { $success = false; } return false !== $success; }
/** * Do every extend according to application context, environment and config target type (APPLICATION OR BUNDLE). * * @param integer $type define which kind of extend we want to apply * (self::APPLICATION_CONFIG or self::BUNDLE_CONFIG) * @param Config $config the config we want to extend * @param array $options options for extend config action */ public function extend($type, Config $config, $options = array()) { if (false === $config->isRestored()) { if (self::APPLICATION_CONFIG === $type) { return parent::extend($type, $config, $options); } elseif (self::BUNDLE_CONFIG === $type) { // do nothing } else { throw new InvalidConfigTypeException('extend', $type); } } }
/** * test restore of ConfigProxy. * * @covers ::__construct * @covers ::restore * @covers ::isRestored */ public function testConfigProxy() { // prepare variables we need to perform tests on Config\ConfigProxy $container = new Container(); $config = new Config(__DIR__ . '/ConfigTest_Resources'); $config_dump = $config->dump(); // set of tests on Config\ConfigProxy $config_proxy = new ConfigProxy(); $this->assertFalse($config_proxy->isRestored()); $config_proxy->restore($container, $config_dump); $this->assertTrue($config_proxy->isRestored()); $this->assertEquals($config_dump, $config_proxy->dump()); }
public function __call($name, $arguments) { $config = reset($arguments); if (true === isset($config['do_import']) && false === $config['do_import']) { $this->markAsSkipped('`' . str_replace('import', '', $name) . '`'); } $key = 0 === strpos($name, 'import') ? strtolower(str_replace('import', '', $name)) : ''; if ($key !== '') { $connectorName = '\\BackBee\\Importer\\Connector\\' . $config['connector']; $connector = new $connectorName($this->_application, $this->_config->getSection($config['config'])); $importer = new Importer($this->_application, $connector, $this->_config); $flushEvery = array_key_exists('flush_every', $config) ? (int) $config['flush_every'] : 1000; $checkForExisting = array_key_exists('check_exists', $config) ? (bool) $config['check_exists'] : true; $importer->run($key, $config, $flushEvery, $checkForExisting); unset($connector); unset($importer); } }
/** * Extracts and returns bundle loader recipes from Config. * * @param Config $config * * @return array|null */ private function getLoaderRecipesByConfig(Config $config) { $recipes = null; $bundleConfig = $config->getBundleConfig(); if (null !== $bundleConfig && isset($bundleConfig['bundle_loader_recipes'])) { $recipes = $bundleConfig['bundle_loader_recipes']; } return $recipes; }
/** * @covers ::deleteSection * @covers ::deleteAllSections */ public function testDeleteSection() { // init test environment $config = new Config($this->test_base_dir); $parameters_section_settings = array('foo' => 'bar'); $config->setSection('parameters', $parameters_section_settings); // pre test $this->assertTrue($config->getSection('say') !== null); $this->assertEquals(array_merge(array('say' => $config->getSection('say')), array('parameters' => $parameters_section_settings)), $config->getAllSections()); // call action to test $config->deleteSection('say'); // post test $this->assertFalse($config->getSection('say') !== null); $this->assertEquals(array('parameters' => $parameters_section_settings), $config->getAllSections()); // second test $config->deleteAllSections(); $this->assertEmpty($config->getAllSections()); }
/** * Reads metadata definitions from configuration. * * @param Config $config * @param string $sectionName * * @return MetaDataResolver */ public function setDefinitionsFromConfig(Config $config, $sectionName = 'metadata') { return $this->setDefinitions($config->getSection($sectionName)); }
/** * Overrides configuration of bundle from the registry. * * @param Config $config The Config to be extended. * @param string $bundleId The bundle Id. * @param boolean $scopePerContext If TRUE use context in registry scope. * @param boolean $scopePerEnvironment If TRUE use environment in regsitry scope. * * @return Configurator */ private function overrideConfigByRegistry(Config $config, $bundleId, $scopePerContext, $scopePerEnvironment) { $registry = $this->getRegistryConfig($bundleId, $scopePerContext, $scopePerEnvironment); if (null !== $registry) { $registryConfig = @unserialize($registry->getValue()); if (is_array($registryConfig)) { foreach ($registryConfig as $section => $value) { $config->setSection($section, $value, true); } } } return $this; }
public function __construct() { $path = dirname(__DIR__); parent::__construct($path); }
/** * @param Config $config * @param string $bundleId */ private function overrideConfigByRegistry(Config $config, $bundleId) { $registry = $this->getRegistryConfig($bundleId); if (null !== $registry) { $registryConfig = @unserialize($registry->getValue()); if (is_array($registryConfig)) { foreach ($registryConfig as $section => $value) { $config->setSection($section, $value, true); } } } }