Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
714f9e3e
Commit
714f9e3e
authored
Oct 01, 2013
by
alexpott
Browse files
Issue
#2098111
by chx: Fixed Change KeyValueFactory to use Settings instead of $conf.
parent
085ad457
Changes
9
Hide whitespace changes
Inline
Side-by-side
core/core.services.yml
View file @
714f9e3e
...
...
@@ -108,13 +108,13 @@ services:
arguments
:
[
default
]
keyvalue
:
class
:
Drupal\Core\KeyValueStore\KeyValueFactory
arguments
:
[
'
@service_container'
]
arguments
:
[
'
@service_container'
,
'
@settings'
]
keyvalue.database
:
class
:
Drupal\Core\KeyValueStore\KeyValueDatabaseFactory
arguments
:
[
'
@database'
]
keyvalue.expirable
:
class
:
Drupal\Core\KeyValueStore\KeyValueExpirableFactory
arguments
:
[
'
@service_container'
]
arguments
:
[
'
@service_container'
,
'
@settings'
]
keyvalue.expirable.database
:
class
:
Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory
tags
:
...
...
core/includes/install.core.inc
View file @
714f9e3e
...
...
@@ -2,6 +2,7 @@
use
Drupal\Component\Utility\Crypt
;
use
Drupal\Component\Utility\Settings
;
use
Drupal\Core\Config\FileStorage
;
use
Drupal\Core\DrupalKernel
;
use
Drupal\Core\CoreServiceProvider
;
...
...
@@ -291,9 +292,6 @@ function install_begin_request(&$install_state) {
// A request object from the HTTPFoundation to tell us about the request.
$request
=
Request
::
createFromGlobals
();
// This must go after drupal_bootstrap(), which unsets globals!
global
$conf
;
// If we have a language selected and it is not yet saved in the system
// (eg. pre-database data screens we are unable to persistently store
// the default language), we should set language_default so the proper
...
...
@@ -423,20 +421,27 @@ function install_begin_request(&$install_state) {
))
->
addMethodCall
(
'setUserAgent'
,
array
(
'Drupal (+http://drupal.org/)'
));
$container
->
register
(
'settings'
,
'Drupal\Component\Utility\Settings'
)
->
setFactoryClass
(
'Drupal\Component\Utility\Settings'
)
->
setFactoryMethod
(
'getSingleton'
);
$container
->
register
(
'keyvalue'
,
'Drupal\Core\KeyValueStore\KeyValueFactory'
)
->
addArgument
(
new
Reference
(
'service_container'
));
$container
->
register
(
'keyvalue.memory'
,
'Drupal\Core\KeyValueStore\KeyValueMemoryFactory'
);
// Override the default keyvalue storage to use memory as the database is
// not available.
$conf
[
'keyvalue_default'
]
=
'keyvalue.memory'
;
->
addArgument
(
new
Reference
(
'service_container'
))
->
addArgument
(
new
Reference
(
'settings'
));
// Register the expirable key value store used by form cache.
$container
->
register
(
'keyvalue.expirable'
,
'Drupal\Core\KeyValueStore\KeyValueExpirableFactory'
)
->
addArgument
(
new
Reference
(
'service_container'
));
->
addArgument
(
new
Reference
(
'service_container'
))
->
addArgument
(
new
Reference
(
'settings'
));
$container
->
register
(
'keyvalue.memory'
,
'Drupal\Core\KeyValueStore\KeyValueMemoryFactory'
);
$container
->
register
(
'keyvalue.expirable.null'
,
'Drupal\Core\KeyValueStore\KeyValueNullExpirableFactory'
);
$conf
[
'keyvalue_expirable_default'
]
=
'keyvalue.expirable.null'
;
$settings
=
Settings
::
getSingleton
()
->
getAll
();
$settings
[
'settings_old'
]
=
$settings
;
$settings
[
'keyvalue_expirable_default'
]
=
'keyvalue.expirable.null'
;
// Override the default keyvalue storage to use memory as the database is
// not available.
$settings
[
'keyvalue_default'
]
=
'keyvalue.memory'
;
new
Settings
(
$settings
);
$container
->
register
(
'state'
,
'Drupal\Core\KeyValueStore\KeyValueStoreInterface'
)
->
setFactoryService
(
new
Reference
(
'keyvalue'
))
...
...
@@ -1267,7 +1272,8 @@ function install_settings_form_submit($form, &$form_state) {
// The container is about to be rebuilt so we need to unset the keyvalue
// storage override that the installer is using.
unset
(
$conf
[
'keyvalue_default'
]);
$settings
=
Settings
::
getSingleton
()
->
getAll
();
new
Settings
(
$settings
[
'settings_old'
]);
// Indicate that the settings file has been verified, and check the database
// for the last completed task, now that we have a valid connection. This
...
...
core/lib/Drupal/Core/KeyValueStore/KeyValueExpirableFactory.php
View file @
714f9e3e
...
...
@@ -14,30 +14,11 @@
*/
class
KeyValueExpirableFactory
extends
KeyValueFactory
{
/**
* Constructs a new expirable key/value store for a given collection name.
*
* @param string $collection
* The name of the collection holding key and value pairs.
*
* @return \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
* An expirable key/value store implementation for the given $collection.
*/
public
function
get
(
$collection
)
{
global
$conf
;
if
(
!
isset
(
$this
->
stores
[
$collection
]))
{
if
(
isset
(
$conf
[
'keyvalue_expirable_service_'
.
$collection
]))
{
$service_name
=
$conf
[
'keyvalue_expirable_service_'
.
$collection
];
}
elseif
(
isset
(
$conf
[
'keyvalue_expirable_default'
]))
{
$service_name
=
$conf
[
'keyvalue_expirable_default'
];
}
else
{
$service_name
=
'keyvalue.expirable.database'
;
}
$this
->
stores
[
$collection
]
=
$this
->
container
->
get
(
$service_name
)
->
get
(
$collection
);
}
return
$this
->
stores
[
$collection
];
}
const
DEFAULT_SERVICE
=
'keyvalue.expirable.database'
;
const
SPECIFIC_PREFIX
=
'keyvalue_expirable_service_'
;
const
DEFAULT_SETTING
=
'keyvalue_expirable_default'
;
}
core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php
View file @
714f9e3e
...
...
@@ -6,6 +6,7 @@
*/
namespace
Drupal\Core\KeyValueStore
;
use
Drupal\Component\Utility\Settings
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
...
...
@@ -13,6 +14,29 @@
*/
class
KeyValueFactory
{
/**
* The specific setting name prefix.
*
* The collection name will be prefixed with this constant and used as a
* setting name. The setting value will be the id of a service.
*/
const
SPECIFIC_PREFIX
=
'keyvalue_service_'
;
/**
* The default setting name.
*
* This is a setting name that will be used if the specific setting does not
* exist. The setting value will be the id of a service.
*/
const
DEFAULT_SETTING
=
'keyvalue_default'
;
/**
* The default service id.
*
* If the default setting does not exist, this is the default service id.
*/
const
DEFAULT_SERVICE
=
'keyvalue.database'
;
/**
* Instantiated stores, keyed by collection name.
*
...
...
@@ -25,12 +49,22 @@ class KeyValueFactory {
*/
protected
$container
;
/**
* The read-only settings container.
*
* @var \Drupal\Component\Utility\Settings
*/
protected
$settings
;
/**
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container.
* @param \Drupal\Component\Utility\Settings $settings
* The read-only settings container.
*/
function
__construct
(
ContainerInterface
$container
)
{
function
__construct
(
ContainerInterface
$container
,
Settings
$settings
)
{
$this
->
container
=
$container
;
$this
->
settings
=
$settings
;
}
/**
...
...
@@ -43,20 +77,18 @@ function __construct(ContainerInterface $container) {
* A key/value store implementation for the given $collection.
*/
public
function
get
(
$collection
)
{
global
$conf
;
if
(
!
isset
(
$this
->
stores
[
$collection
]))
{
if
(
isset
(
$conf
[
'keyvalue_service_'
.
$collection
]))
{
$service_name
=
$conf
[
'keyvalue_service_'
.
$collection
];
if
(
$service_name
=
$this
->
settings
->
get
(
static
::
SPECIFIC_PREFIX
.
$collection
))
{
}
elseif
(
isset
(
$conf
[
'keyvalue_default'
]))
{
$service_name
=
$conf
[
'keyvalue_default'
];
elseif
(
$service_name
=
$this
->
settings
->
get
(
static
::
DEFAULT_SETTING
))
{
}
else
{
$service_name
=
'keyvalue.database'
;
$service_name
=
static
::
DEFAULT_SERVICE
;
}
$this
->
stores
[
$collection
]
=
$this
->
container
->
get
(
$service_name
)
->
get
(
$collection
);
}
return
$this
->
stores
[
$collection
];
}
}
core/lib/Drupal/Core/Path/AliasWhitelist.php
View file @
714f9e3e
...
...
@@ -11,7 +11,6 @@
use
Drupal\Core\Cache\CacheCollector
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\DestructableInterface
;
use
Drupal\Core\KeyValueStore\KeyValueFactory
;
use
Drupal\Core\KeyValueStore\KeyValueStoreInterface
;
use
Drupal\Core\Lock\LockBackendInterface
;
use
Drupal\Core\Utility\CacheArray
;
...
...
core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
View file @
714f9e3e
...
...
@@ -152,7 +152,7 @@ public function containerBuild(ContainerBuilder $container) {
->
register
(
'config.storage'
,
'Drupal\Core\Config\FileStorage'
)
->
addArgument
(
$this
->
configDirectories
[
CONFIG_ACTIVE_DIRECTORY
]);
$
conf
[
'keyvalue_default'
]
=
'keyvalue.memory'
;
$
this
->
settingsSet
(
'keyvalue_default'
,
'keyvalue.memory'
)
;
$container
->
set
(
'keyvalue.memory'
,
$this
->
keyValueFactory
);
if
(
!
$container
->
has
(
'keyvalue'
))
{
// TestBase::setUp puts a completely empty container in
...
...
@@ -165,9 +165,14 @@ public function containerBuild(ContainerBuilder $container) {
// together here, it still might a keyvalue storage for anything using
// \Drupal::state() -- that's why a memory service was added in the first
// place.
$container
->
register
(
'settings'
,
'Drupal\Component\Utility\Settings'
)
->
setFactoryClass
(
'Drupal\Component\Utility\Settings'
)
->
setFactoryMethod
(
'getSingleton'
);
$container
->
register
(
'keyvalue'
,
'Drupal\Core\KeyValueStore\KeyValueFactory'
)
->
addArgument
(
new
Reference
(
'service_container'
));
->
addArgument
(
new
Reference
(
'service_container'
))
->
addArgument
(
new
Reference
(
'settings'
));
$container
->
register
(
'state'
,
'Drupal\Core\KeyValueStore\KeyValueStoreInterface'
)
->
setFactoryService
(
new
Reference
(
'keyvalue'
))
...
...
core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php
View file @
714f9e3e
...
...
@@ -36,8 +36,7 @@ protected function setUp() {
$this
->
container
->
register
(
'keyvalue.expirable.database'
,
'Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory'
)
->
addArgument
(
new
Reference
(
'database'
));
global
$conf
;
$conf
[
'keyvalue_expirable_default'
]
=
'keyvalue.expirable.database'
;
$this
->
settingsSet
(
'keyvalue_expirable_default'
,
'keyvalue.expirable.database'
);
}
protected
function
tearDown
()
{
...
...
core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageTest.php
View file @
714f9e3e
...
...
@@ -31,22 +31,10 @@ protected function setUp() {
parent
::
setUp
();
$this
->
container
->
register
(
'keyvalue.memory'
,
'Drupal\Core\KeyValueStore\KeyValueMemoryFactory'
);
global
$conf
;
if
(
isset
(
$conf
[
'keyvalue_default'
]))
{
$this
->
originalKeyValue
=
$conf
[
'keyvalue_default'
];
}
$conf
[
'keyvalue_default'
]
=
'keyvalue.memory'
;
}
protected
function
tearDown
()
{
global
$conf
;
if
(
isset
(
$this
->
originalKeyValue
))
{
$conf
[
'keyvalue_default'
]
=
$this
->
originalKeyValue
;
}
else
{
unset
(
$conf
[
'keyvalue_default'
]);
}
parent
::
tearDown
();
$this
->
settingsSet
(
'keyvalue_default'
,
'keyvalue.memory'
);
}
}
core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php
View file @
714f9e3e
...
...
@@ -52,12 +52,17 @@ protected function setUp() {
->
register
(
'service_container'
,
'Symfony\Component\DependencyInjection\ContainerBuilder'
)
->
setSynthetic
(
TRUE
);
$this
->
container
->
set
(
'service_container'
,
$this
->
container
);
$this
->
container
->
register
(
'settings'
,
'Drupal\Component\Utility\Settings'
)
->
setFactoryClass
(
'Drupal\Component\Utility\Settings'
)
->
setFactoryMethod
(
'getSingleton'
);
$this
->
container
->
register
(
'keyvalue'
,
'Drupal\Core\KeyValueStore\KeyValueFactory'
)
->
addArgument
(
new
Reference
(
'service_container'
));
->
addArgument
(
new
Reference
(
'service_container'
))
->
addArgument
(
new
Reference
(
'settings'
));
$this
->
container
->
register
(
'keyvalue.expirable'
,
'Drupal\Core\KeyValueStore\KeyValueExpirableFactory'
)
->
addArgument
(
new
Reference
(
'service_container'
));
->
addArgument
(
new
Reference
(
'service_container'
))
->
addArgument
(
new
Reference
(
'settings'
));
// Define two data collections,
$this
->
collections
=
array
(
0
=>
'zero'
,
1
=>
'one'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment