diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 7f9df9c..d33cff5 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2436,16 +2436,7 @@ function drupal_container(Container $reset = NULL) { $container = new ContainerBuilder(); // Register configuration storage class and options. - // @todo The active store and its options need to be configurable. - // Use either global $conf (recursion warning) or global $config, or a - // bootstrap configuration *file* to allow to set/override this very - // lowest of low level configuration. - $container->setParameter('config.storage.options', array( - 'connection' => 'default', - 'target' => 'default', - )); - $container->register('config.storage', 'Drupal\Core\Config\DatabaseStorage') - ->addArgument('%config.storage.options%'); + $container->register('config.storage', 'Drupal\Core\Config\DatabaseStorage'); $container->register('config.subscriber.globalconf', 'Drupal\Core\EventSubscriber\ConfigGlobalOverrideSubscriber'); $container->register('dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher') diff --git a/core/includes/config.inc b/core/includes/config.inc index 369a0d1..cbd3fd5 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -24,7 +24,7 @@ use Drupal\Core\Config\StorageInterface; function config_install_default_config($type, $name) { $config_dir = drupal_get_path($type, $name) . '/config'; if (is_dir($config_dir)) { - $source_storage = new FileStorage(array('directory' => $config_dir)); + $source_storage = new FileStorage($config_dir); $target_storage = drupal_container()->get('config.storage'); $null_storage = new NullStorage(); diff --git a/core/includes/update.inc b/core/includes/update.inc index 5582bb4..9dd8456 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -1056,7 +1056,7 @@ function update_variables_to_config($config_name, array $variable_map) { $module = strtok($config_name, '.'); // Load and set default configuration values. - $file = new FileStorage(array('directory' => drupal_get_path('module', $module) . '/config')); + $file = new FileStorage(drupal_get_path('module', $module) . '/config'); if (!$file->exists($config_name)) { throw new ConfigException("Default configuration file $config_name for $module extension not found but is required to exist."); } diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index ad8c155..6d73be1 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Config; +use Drupal\Core\Database\Connection; use Drupal\Core\Database\Database; use Exception; @@ -26,21 +27,16 @@ class DatabaseStorage implements StorageInterface { protected $options; /** - * Implements Drupal\Core\Config\StorageInterface::__construct(). + * The database connection object to be used. */ - public function __construct(array $options = array()) { - $options += array( - 'connection' => 'default', - 'target' => 'default', - ); - $this->options = $options; - } + protected $connection = NULL; /** - * Returns the database connection to use. + * Constructs DatabaseStorage. */ - protected function getConnection() { - return Database::getConnection($this->options['target'], $this->options['connection']); + public function __construct($target = 'default', $key = NULL) { + // This will be ripped out in the next patch, anyways. + $this->connection = Database::getConnection($target, $key); } /** @@ -59,7 +55,7 @@ class DatabaseStorage implements StorageInterface { // @todo Remove this and use appropriate config.storage service definition // in the installer instead. try { - $raw = $this->getConnection()->query('SELECT data FROM {config} WHERE name = :name', array(':name' => $name), $this->options)->fetchField(); + $raw = $this->connection->query('SELECT data FROM {config} WHERE name = :name', array(':name' => $name))->fetchField(); if ($raw !== FALSE) { $data = $this->decode($raw); } @@ -78,8 +74,7 @@ class DatabaseStorage implements StorageInterface { */ public function write($name, array $data) { $data = $this->encode($data); - $options = array('return' => Database::RETURN_AFFECTED) + $this->options; - return (bool) $this->getConnection()->merge('config', $options) + return (bool) $this->connection->merge('config', array('return' => Database::RETURN_AFFECTED)) ->key(array('name' => $name)) ->fields(array('data' => $data)) ->execute(); @@ -93,8 +88,7 @@ class DatabaseStorage implements StorageInterface { * @todo Ignore slave targets for data manipulation operations. */ public function delete($name) { - $options = array('return' => Database::RETURN_AFFECTED) + $this->options; - return (bool) $this->getConnection()->delete('config', $options) + return (bool) $this->connection->delete('config', array('return' => Database::RETURN_AFFECTED)) ->condition('name', $name) ->execute(); } @@ -106,8 +100,7 @@ class DatabaseStorage implements StorageInterface { * @throws PDOException */ public function rename($name, $new_name) { - $options = array('return' => Database::RETURN_AFFECTED) + $this->options; - return (bool) $this->getConnection()->update('config', $options) + return (bool) $this->connection->update('config', array('return' => Database::RETURN_AFFECTED)) ->fields(array('name' => $new_name)) ->condition('name', $name) ->execute(); @@ -139,8 +132,8 @@ class DatabaseStorage implements StorageInterface { * Only thrown in case $this->options['throw_exception'] is TRUE. */ public function listAll($prefix = '') { - return $this->getConnection()->query('SELECT name FROM {config} WHERE name LIKE :name', array( + return $this->connection->query('SELECT name FROM {config} WHERE name LIKE :name', array( ':name' => db_like($prefix) . '%', - ), $this->options)->fetchCol(); + ))->fetchCol(); } } diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php index d96af7e..c068ab8 100644 --- a/core/lib/Drupal/Core/Config/FileStorage.php +++ b/core/lib/Drupal/Core/Config/FileStorage.php @@ -26,11 +26,11 @@ class FileStorage implements StorageInterface { /** * Implements Drupal\Core\Config\StorageInterface::__construct(). */ - public function __construct(array $options = array()) { - if (!isset($options['directory'])) { - $options['directory'] = config_get_config_directory(); + public function __construct($directory = '') { + if (empty($directory)) { + $directory = config_get_config_directory(); } - $this->options = $options; + $this->directory = $directory; } /** @@ -40,7 +40,7 @@ class FileStorage implements StorageInterface { * The path to the configuration file. */ public function getFilePath($name) { - return $this->options['directory'] . '/' . $name . '.' . self::getFileExtension(); + return $this->directory . '/' . $name . '.' . self::getFileExtension(); } /** @@ -99,8 +99,8 @@ class FileStorage implements StorageInterface { */ public function delete($name) { if (!$this->exists($name)) { - if (!file_exists($this->options['directory'])) { - throw new StorageException($this->options['directory'] . '/ not found.'); + if (!file_exists($this->directory)) { + throw new StorageException($this->directory . '/ not found.'); } return FALSE; } @@ -149,11 +149,11 @@ class FileStorage implements StorageInterface { public function listAll($prefix = '') { // glob() silently ignores the error of a non-existing search directory, // even with the GLOB_ERR flag. - if (!file_exists($this->options['directory'])) { - throw new StorageException($this->options['directory'] . '/ not found.'); + if (!file_exists($this->directory)) { + throw new StorageException($this->directory . '/ not found.'); } $extension = '.' . self::getFileExtension(); - $files = glob($this->options['directory'] . '/' . $prefix . '*' . $extension); + $files = glob($this->directory . '/' . $prefix . '*' . $extension); $clean_name = function ($value) use ($extension) { return basename($value, $extension); }; diff --git a/core/lib/Drupal/Core/Config/NullStorage.php b/core/lib/Drupal/Core/Config/NullStorage.php index ea21be1..09ae3e9 100644 --- a/core/lib/Drupal/Core/Config/NullStorage.php +++ b/core/lib/Drupal/Core/Config/NullStorage.php @@ -22,11 +22,6 @@ namespace Drupal\Core\Config; * This also can be used for testing purposes. */ class NullStorage implements StorageInterface { - /** - * Implements Drupal\Core\Config\StorageInterface::__construct(). - */ - public function __construct(array $options = array()) { - } /** * Implements Drupal\Core\Config\StorageInterface::read(). diff --git a/core/lib/Drupal/Core/Config/StorageInterface.php b/core/lib/Drupal/Core/Config/StorageInterface.php index a466538..2d3dcda 100644 --- a/core/lib/Drupal/Core/Config/StorageInterface.php +++ b/core/lib/Drupal/Core/Config/StorageInterface.php @@ -16,15 +16,6 @@ namespace Drupal\Core\Config; interface StorageInterface { /** - * Constructs the storage controller. - * - * @param array $options - * An associative array containing configuration options specific to the - * storage controller. - */ - public function __construct(array $options = array()); - - /** * Reads configuration data from the storage. * * @param string $name diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 2c5d180..cc0d32b 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -43,14 +43,6 @@ class CoreBundle extends Bundle $container->register('language_manager', 'Drupal\Core\Language\LanguageManager') ->addArgument(new Reference('request')) ->setScope('request'); - $container->register('database', 'Drupal\Core\Database\Connection') - ->setFactoryClass('Drupal\Core\Database\Database') - ->setFactoryMethod('getConnection') - ->addArgument('default'); - $container->register('database.slave', 'Drupal\Core\Database\Connection') - ->setFactoryClass('Drupal\Core\Database\Database') - ->setFactoryMethod('getConnection') - ->addArgument('slave'); // @todo Replace below lines with the commented out block below it when it's // performant to do so: http://drupal.org/node/1706064. diff --git a/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php b/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php index 2e1599f..f50fa64 100644 --- a/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php @@ -24,7 +24,7 @@ class DatabaseStorageTest extends ConfigStorageTestBase { function setUp() { parent::setUp(); $this->storage = new DatabaseStorage(); - $this->invalidStorage = new DatabaseStorage(array('connection' => 'invalid')); + $this->invalidStorage = new DatabaseStorage('invalid'); } protected function read($name) { diff --git a/core/modules/config/lib/Drupal/config/Tests/Storage/FileStorageTest.php b/core/modules/config/lib/Drupal/config/Tests/Storage/FileStorageTest.php index 0fd2ba4..3c617c8 100644 --- a/core/modules/config/lib/Drupal/config/Tests/Storage/FileStorageTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/Storage/FileStorageTest.php @@ -25,7 +25,7 @@ class FileStorageTest extends ConfigStorageTestBase { function setUp() { parent::setUp(); $this->storage = new FileStorage(); - $this->invalidStorage = new FileStorage(array('directory' => $this->configDirectories[CONFIG_ACTIVE_DIRECTORY] . '/nonexisting')); + $this->invalidStorage = new FileStorage($this->configDirectories[CONFIG_ACTIVE_DIRECTORY] . '/nonexisting'); // FileStorage::listAll() requires other configuration data to exist. $this->storage->write('system.performance', config('system.performance')->get()); diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php index 1698737..36f4be3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php @@ -99,7 +99,7 @@ abstract class ModuleTestBase extends WebTestBase { if (!is_dir($module_config_dir)) { return; } - $module_file_storage = new FileStorage(array('directory' => $module_config_dir)); + $module_file_storage = new FileStorage($module_config_dir); $names = $module_file_storage->listAll(); // Verify that the config directory is not empty.