diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 6fc2a87..8e1c332 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -13,7 +13,7 @@ /** * Defines the default configuration object. */ -class Config { +class Config implements ArrayAccess{ /** * The name of the configuration object. @@ -416,4 +416,54 @@ public function merge(array $data_to_merge) { $this->data = NestedArray::mergeDeepArray(array($this->data, $data_to_merge), TRUE); return $this; } + + /* ArrayAccess Aliases */ + + /** + * Implements ArrayAccess::offsetExists. + * + * Allows you to do this: + * @code + * isset($config['foo']); + * @endcode + */ + public function offsetExists($name) { + $this->get()->isset($name); + } + + /** + * Implements ArrayAccess::offsetGet. + * + * Alias of DrupalConfig::get. Allows you to do this: + * @code + * $value = $config['foo']; + * @endcode + */ + public function offsetGet($name){ + return $this->get($name); + } + + /** + * Implements ArrayAccess::offsetSet. + * + * Alias of DrupalConfig::set. Allows you to do this: + * @code + * $config['foo'] = 'bar'; + * @endcode + */ + public function offsetSet($name, $value){ + return $this->set($name, $value); + } + + /** + * Implements ArrayAccess::offsetUnset. + * + * Alias of DrupalConfig::clear. Allows you to do this: + * @code + * isset($config['foo']); + * @endcode + */ + public function offsetUnset($name){ + $this->clear($name); + } } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php index 56e5ecf..758eeb7 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php @@ -41,7 +41,7 @@ function testCRUD() { $this->assertIdentical($actual_data, array('value' => 'initial')); // Update the configuration object instance. - $config->set('value', 'instance-update'); + $config['value'] = 'instance-update'; $config->save(); $this->assertIdentical($config->isNew(), FALSE); @@ -99,7 +99,7 @@ function testCRUD() { ); $new_config->merge($expected_values); $new_config->save(); - $this->assertIdentical($new_config->get('value'), $expected_values['value']); + $this->assertIdentical($new_config['value'], $expected_values['value']); $this->assertIdentical($new_config->get('404'), $expected_values['404']); }