diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageSortedSet.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageSortedSet.php index c9b83e3..bbd56bd 100644 --- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageSortedSet.php +++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageSortedSet.php @@ -5,6 +5,12 @@ use Drupal\Component\Serialization\SerializationInterface; use Drupal\Core\Database\Connection; +/** + * Defines the default key/value implementation for sorted sets. + * + * This key/value store implementation uses the database to store key/value + * data in a sorted set. + */ class DatabaseStorageSortedSet implements KeyValueStoreSortedSetInterface { /** @@ -27,6 +33,16 @@ class DatabaseStorageSortedSet implements KeyValueStoreSortedSetInterface { */ protected $table; + /** + * @param string $collection + * The name of the collection holding key and value pairs. + * @param \Drupal\Component\Serialization\SerializationInterface $serializer + * The serialization class to use. + * @param \Drupal\Core\Database\Connection $connection + * The database connection to use. + * @param string $table + * The name of the SQL table to use, defaults to key_value_sorted. + */ public function __construct($collection, SerializationInterface $serializer, Connection $connection, $table = 'key_value_sorted') { $this->collection = $collection; $this->serializer = $serializer; @@ -93,6 +109,9 @@ public function getRange($start, $stop = NULL) { return $values; } + /** + * {@inheritdoc} + */ public function getMaxScore() { $query = $this->connection->select($this->table); $query->condition('collection', $this->collection, '='); @@ -100,6 +119,9 @@ public function getMaxScore() { return $query->execute()->fetchField(); } + /** + * {@inheritdoc} + */ public function getMinScore() { $query = $this->connection->select($this->table); $query->condition('collection', $this->collection, '='); diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseSortedSetFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseSortedSetFactory.php index 583254c..071a45d 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseSortedSetFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseSortedSetFactory.php @@ -5,21 +5,32 @@ use Drupal\Component\Serialization\SerializationInterface; use Drupal\Core\Database\Connection; +/** + * Defines the key/value store factory for the database backend. + */ class KeyValueDatabaseSortedSetFactory implements KeyValueSortedSetFactoryInterface { /** + * The serialization class to use. + * * @var \Drupal\Component\Serialization\SerializationInterface */ protected $serializer; /** + * The database connection. + * * @var \Drupal\Core\Database\Connection */ protected $connection; /** + * Constructs this factory object. + * * @param \Drupal\Component\Serialization\SerializationInterface $serializer + * The serialization class to use. * @param \Drupal\Core\Database\Connection $connection + * The Connection object containing the key-value tables. */ function __construct(SerializationInterface $serializer, Connection $connection) { $this->serializer = $serializer; diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueSortedSetFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueSortedSetFactory.php index adeadd6..70ef0bd 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueSortedSetFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueSortedSetFactory.php @@ -2,6 +2,9 @@ namespace Drupal\Core\KeyValueStore; +/** + * Defines the key/value store factory. + */ class KeyValueSortedSetFactory extends KeyValueFactory implements KeyValueSortedSetFactoryInterface { const DEFAULT_SERVICE = 'keyvalue.sorted_set.database'; diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueSortedSetFactoryInterface.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueSortedSetFactoryInterface.php index 56d4ab3..415b888 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueSortedSetFactoryInterface.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueSortedSetFactoryInterface.php @@ -2,12 +2,19 @@ namespace Drupal\Core\KeyValueStore; +/** + * Defines the sorted set key/value store factory interface. + */ interface KeyValueSortedSetFactoryInterface { /** + * Constructs a new sorted set 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\KeyValueStoreSortedSetInterface + * An sorted set key/value store implementation for the given $collection. */ public function get($collection); diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreSortedSetInterface.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreSortedSetInterface.php index 5529285..b59fe6f 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreSortedSetInterface.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreSortedSetInterface.php @@ -2,39 +2,55 @@ namespace Drupal\Core\KeyValueStore; +/** + * Defines the interface for sorted data in a key/value store. + * + * An example would be an index of items, which have an order, where the last + * item or a range of items may be required. + */ interface KeyValueStoreSortedSetInterface { /** * @param float $score + * The key for the item, for example microtime(), which can be used to + * generate a sequential value. * @param mixed $member + * The value of the item. */ public function add($score, $member); /** * @param array $pairs + * An array of key/value pairs to add. */ public function addMultiple(array $pairs); /** * @return float + * The highest key in the collection. */ public function getMaxScore(); /** * @return float + * The lowest key in the collection. */ public function getMinScore(); /** * @return integer + * The number of items in a collection. */ public function getCount(); /** * @param float $start + * The first key in the range. * @param float $stop + * The last key in the range. * * @return array + * An array of items within the given range. */ public function getRange($start, $stop = NULL);