From f133a3660c4ddce793f3d1bd2d977e50d338f50d Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Thu, 10 Sep 2020 21:23:45 +0200 Subject: [PATCH] Various updates to options class and interface. --- src/Configuration/Options.php | 51 ++++++++++++-------------- src/Configuration/OptionsInterface.php | 29 ++++++--------- 2 files changed, 34 insertions(+), 46 deletions(-) diff --git a/src/Configuration/Options.php b/src/Configuration/Options.php index f7ac4439..6149e23e 100644 --- a/src/Configuration/Options.php +++ b/src/Configuration/Options.php @@ -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 ?? []; } /** diff --git a/src/Configuration/OptionsInterface.php b/src/Configuration/OptionsInterface.php index e0b30a49..33c47cd2 100644 --- a/src/Configuration/OptionsInterface.php +++ b/src/Configuration/OptionsInterface.php @@ -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 */ @@ -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 */