From d2f1b2560f7d1e78dc0e344c00ffaa892e095c61 Mon Sep 17 00:00:00 2001
From: Dries <dries@buytaert.net>
Date: Fri, 23 Mar 2012 15:35:53 -0600
Subject: [PATCH] - Patch #1484690 by Pol, jhedstrom, beejeebus: implement 
 overrides in the configuration system.

---
 core/lib/Drupal/Core/Config/DrupalConfig.php  | 16 +++++++++--
 .../Config/DrupalConfigVerifiedStorage.php    |  7 +++++
 .../DrupalConfigVerifiedStorageInterface.php  |  5 ++++
 core/modules/config/config.test               | 28 +++++++++++++++++++
 4 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/core/lib/Drupal/Core/Config/DrupalConfig.php b/core/lib/Drupal/Core/Config/DrupalConfig.php
index 54397e7a03f..71f2095060f 100644
--- a/core/lib/Drupal/Core/Config/DrupalConfig.php
+++ b/core/lib/Drupal/Core/Config/DrupalConfig.php
@@ -81,17 +81,27 @@ class DrupalConfig {
    *   The data that was requested.
    */
   public function get($key = '') {
+    global $conf;
+
+    $name = $this->_verifiedStorage->getName();
+    if (isset($conf[$name])) {
+      $merged_data = drupal_array_merge_deep($this->data, $conf[$name]);
+    }
+    else {
+      $merged_data = $this->data;
+    }
+
     if (empty($key)) {
-      return $this->data;
+      return $merged_data;
     }
     else {
       $parts = explode('.', $key);
       if (count($parts) == 1) {
-        return isset($this->data[$key]) ? $this->data[$key] : NULL;
+        return isset($merged_data[$key]) ? $merged_data[$key] : NULL;
       }
       else {
         $key_exists = NULL;
-        $value = drupal_array_get_nested_value($this->data, $parts, $key_exists);
+        $value = drupal_array_get_nested_value($merged_data, $parts, $key_exists);
         return $key_exists ? $value : NULL;
       }
     }
diff --git a/core/lib/Drupal/Core/Config/DrupalConfigVerifiedStorage.php b/core/lib/Drupal/Core/Config/DrupalConfigVerifiedStorage.php
index ca37cdd6592..267c834d22f 100644
--- a/core/lib/Drupal/Core/Config/DrupalConfigVerifiedStorage.php
+++ b/core/lib/Drupal/Core/Config/DrupalConfigVerifiedStorage.php
@@ -99,4 +99,11 @@ abstract class DrupalConfigVerifiedStorage implements DrupalConfigVerifiedStorag
     $this->deleteFromActive();
     $this->deleteFile();
   }
+
+  /**
+   * Implements DrupalConfigVerifiedStorageInterface::getName().
+   */
+  public function getName() {
+    return $this->name;
+  }
 }
diff --git a/core/lib/Drupal/Core/Config/DrupalConfigVerifiedStorageInterface.php b/core/lib/Drupal/Core/Config/DrupalConfigVerifiedStorageInterface.php
index 2fdce769057..47a5ddb81b2 100644
--- a/core/lib/Drupal/Core/Config/DrupalConfigVerifiedStorageInterface.php
+++ b/core/lib/Drupal/Core/Config/DrupalConfigVerifiedStorageInterface.php
@@ -81,4 +81,9 @@ interface DrupalConfigVerifiedStorageInterface {
    *   @todo
    */
   static function getNamesWithPrefix($prefix);
+
+  /**
+   * Gets the name of this object.
+   */
+  public function getName();
 }
diff --git a/core/modules/config/config.test b/core/modules/config/config.test
index 395a3a99c34..47ef4406f83 100644
--- a/core/modules/config/config.test
+++ b/core/modules/config/config.test
@@ -268,3 +268,31 @@ class ConfigFileContentTestCase extends DrupalWebTestCase {
     // Attempt to delete non-existing configuration.
   }
 }
+
+  /**
+   * Tests configuration overriding from settings.php.
+   */
+class ConfOverrideTestCase extends DrupalWebTestCase {
+  protected $testContent = 'Good morning, Denver!';
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Configuration overrides',
+      'description' => 'Tests configuration overrides through settings.php.',
+      'group' => 'Configuration',
+    );
+  }
+
+  /**
+   * Test configuration override.
+   */
+  function testConfigurationOverride() {
+    global $conf;
+    $config = config('system.performance');
+    $this->assertNotEqual($config->get('cache'), $this->testContent);
+
+    $conf['system.performance']['cache'] = $this->testContent;
+    $config = config('system.performance');
+    $this->assertEqual($config->get('cache'), $conf['system.performance']['cache']);
+  }
+}