Various updates to options class and interface.

This commit is contained in:
Daniele Alessandri
2020-09-10 21:23:45 +02:00
parent fa44ff0846
commit f133a3660c
2 changed files with 34 additions and 46 deletions
+23 -28
View File
@@ -12,8 +12,10 @@
namespace Predis\Configuration;
/**
* Manages Predis options with filtering, conversion and lazy initialization of
* values using a mini-DI container approach.
* Default client options container for Predis\Client.
*
* Pre-defined options have their specialized handlers that can filter, convert
* an lazily initialize values in a mini-DI container approach.
*
* {@inheritdoc}
*
@@ -21,37 +23,30 @@ namespace Predis\Configuration;
*/
class Options implements OptionsInterface
{
protected $options = array();
/** @var array */
protected $handlers = [
'aggregate' => Option\Aggregate::class,
'cluster' => Option\Cluster::class,
'replication' => Option\Replication::class,
'connections' => Option\Connections::class,
'commands' => Option\Commands::class,
'exceptions' => Option\Exceptions::class,
'prefix' => Option\Prefix::class,
'crc16' => Option\CRC16::class,
];
/** @var array */
protected $options = [];
/** @var array */
protected $input;
protected $handlers;
/**
* @param array $options Array of options with their values
* @param array $options Named array of client options
*/
public function __construct(array $options = array())
public function __construct(array $options = null)
{
$this->input = $options;
$this->options = array();
$this->handlers = $this->getHandlers();
}
/**
* Ensures that the default options are initialized.
*
* @return array
*/
protected function getHandlers()
{
return array(
'aggregate' => 'Predis\Configuration\Option\Aggregate',
'cluster' => 'Predis\Configuration\Option\Cluster',
'replication' => 'Predis\Configuration\Option\Replication',
'connections' => 'Predis\Configuration\Option\Connections',
'commands' => 'Predis\Configuration\Option\Commands',
'exceptions' => 'Predis\Configuration\Option\Exceptions',
'prefix' => 'Predis\Configuration\Option\Prefix',
'crc16' => 'Predis\Configuration\Option\CRC16',
);
$this->input = $options ?? [];
}
/**
+11 -18
View File
@@ -12,21 +12,14 @@
namespace Predis\Configuration;
use Predis\Command\Processor\ProcessorInterface;
use Predis\Connection\Aggregate\ClusterInterface;
use Predis\Connection\Aggregate\ReplicationInterface;
use Predis\Connection\FactoryInterface;
use Predis\Profile\ProfileInterface;
/**
* Interface defining a container for client options.
*
* @property-read callable $aggregate Custom connection aggregator.
* @property-read ClusterInterface $cluster Aggregate connection for clustering.
* @property-read FactoryInterface $connections Connection factory.
* @property-read bool $exceptions Toggles exceptions in client for -ERR responses.
* @property-read ProcessorInterface $prefix Key prefixing strategy using the given prefix.
* @property-read ProfileInterface $profile Server profile.
* @property-read ReplicationInterface $replication Aggregate connection for replication.
* @property-read callable $aggregate Custom aggregate connection initializer
* @property-read callable $cluster Aggregate connection initializer for clustering
* @property-read Connection\FactoryInterface $connections Connection factory for creating new connections
* @property-read bool $exceptions Toggles exceptions in client for -ERR responses
* @property-read ProcessorInterface $prefix Key prefixing strategy using the supplied string as prefix
* @property-read Command\FactoryInterface $commands Command factory for creating Redis commands
* @property-read callable $replication Aggregate connection initializer for replication
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
@@ -35,7 +28,7 @@ interface OptionsInterface
/**
* Returns the default value for the given option.
*
* @param string $option Name of the option.
* @param string $option Name of the option
*
* @return mixed|null
*/
@@ -44,7 +37,7 @@ interface OptionsInterface
/**
* Checks if the given option has been set by the user upon initialization.
*
* @param string $option Name of the option.
* @param string $option Name of the option
*
* @return bool
*/
@@ -53,7 +46,7 @@ interface OptionsInterface
/**
* Checks if the given option has been set and does not evaluate to NULL.
*
* @param string $option Name of the option.
* @param string $option Name of the option
*
* @return bool
*/
@@ -62,7 +55,7 @@ interface OptionsInterface
/**
* Returns the value of the given option.
*
* @param string $option Name of the option.
* @param string $option Name of the option
*
* @return mixed|null
*/