Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
4a3ee315
Commit
4a3ee315
authored
Oct 15, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2085867
by damiankloip: Add a default parameter to keyvalue get() method.
parent
2977e2ab
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
7 deletions
+12
-7
core/lib/Drupal/Core/KeyValueStore/KeyValueStoreInterface.php
.../lib/Drupal/Core/KeyValueStore/KeyValueStoreInterface.php
+4
-2
core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php
core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php
+2
-2
core/lib/Drupal/Core/KeyValueStore/NullStorageExpirable.php
core/lib/Drupal/Core/KeyValueStore/NullStorageExpirable.php
+1
-1
core/lib/Drupal/Core/KeyValueStore/StorageBase.php
core/lib/Drupal/Core/KeyValueStore/StorageBase.php
+2
-2
core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php
...lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php
+3
-0
No files found.
core/lib/Drupal/Core/KeyValueStore/KeyValueStoreInterface.php
View file @
4a3ee315
...
@@ -25,11 +25,13 @@ public function getCollectionName();
...
@@ -25,11 +25,13 @@ public function getCollectionName();
*
*
* @param string $key
* @param string $key
* The key of the data to retrieve.
* The key of the data to retrieve.
* @param mixed $default
* The default value to use if the key is not found.
*
*
* @return mixed
* @return mixed
* The stored value, or
NULL
if no value exists.
* The stored value, or
the default value
if no value exists.
*/
*/
public
function
get
(
$key
);
public
function
get
(
$key
,
$default
=
NULL
);
/**
/**
* Returns the stored key/value pairs for a given set of keys.
* Returns the stored key/value pairs for a given set of keys.
...
...
core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php
View file @
4a3ee315
...
@@ -22,8 +22,8 @@ class MemoryStorage extends StorageBase {
...
@@ -22,8 +22,8 @@ class MemoryStorage extends StorageBase {
/**
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get().
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get().
*/
*/
public
function
get
(
$key
)
{
public
function
get
(
$key
,
$default
=
NULL
)
{
return
array_key_exists
(
$key
,
$this
->
data
)
?
$this
->
data
[
$key
]
:
NULL
;
return
array_key_exists
(
$key
,
$this
->
data
)
?
$this
->
data
[
$key
]
:
$default
;
}
}
/**
/**
...
...
core/lib/Drupal/Core/KeyValueStore/NullStorageExpirable.php
View file @
4a3ee315
...
@@ -36,7 +36,7 @@ public function __construct($collection) {
...
@@ -36,7 +36,7 @@ public function __construct($collection) {
/**
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get().
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get().
*/
*/
public
function
get
(
$key
)
{
public
function
get
(
$key
,
$default
=
NULL
)
{
return
NULL
;
return
NULL
;
}
}
...
...
core/lib/Drupal/Core/KeyValueStore/StorageBase.php
View file @
4a3ee315
...
@@ -36,9 +36,9 @@ public function getCollectionName() {
...
@@ -36,9 +36,9 @@ public function getCollectionName() {
/**
/**
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get().
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get().
*/
*/
public
function
get
(
$key
)
{
public
function
get
(
$key
,
$default
=
NULL
)
{
$values
=
$this
->
getMultiple
(
array
(
$key
));
$values
=
$this
->
getMultiple
(
array
(
$key
));
return
isset
(
$values
[
$key
])
?
$values
[
$key
]
:
NULL
;
return
isset
(
$values
[
$key
])
?
$values
[
$key
]
:
$default
;
}
}
/**
/**
...
...
core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php
View file @
4a3ee315
...
@@ -157,6 +157,9 @@ public function testNonExistingKeys() {
...
@@ -157,6 +157,9 @@ public function testNonExistingKeys() {
// Verify that a non-existing key returns NULL as value.
// Verify that a non-existing key returns NULL as value.
$this
->
assertNull
(
$stores
[
0
]
->
get
(
'foo'
));
$this
->
assertNull
(
$stores
[
0
]
->
get
(
'foo'
));
// Verify that a non-existing key with a default returns the default.
$this
->
assertIdentical
(
$stores
[
0
]
->
get
(
'foo'
,
'bar'
),
'bar'
);
// Verify that a FALSE value can be stored.
// Verify that a FALSE value can be stored.
$stores
[
0
]
->
set
(
'foo'
,
FALSE
);
$stores
[
0
]
->
set
(
'foo'
,
FALSE
);
$this
->
assertIdentical
(
$stores
[
0
]
->
get
(
'foo'
),
FALSE
);
$this
->
assertIdentical
(
$stores
[
0
]
->
get
(
'foo'
),
FALSE
);
...
...
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