Predis to v2.2.2

This commit is contained in:
the-djmaze 2024-04-02 20:15:23 +02:00
parent f6b440adef
commit 84ffe1e552
259 changed files with 2407 additions and 9937 deletions

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -12,44 +13,39 @@
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}
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
class Options implements OptionsInterface
{
/** @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 $options;
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(
'cluster' => 'Predis\Configuration\ClusterOption',
'connections' => 'Predis\Configuration\ConnectionFactoryOption',
'exceptions' => 'Predis\Configuration\ExceptionsOption',
'prefix' => 'Predis\Configuration\PrefixOption',
'profile' => 'Predis\Configuration\ProfileOption',
'replication' => 'Predis\Configuration\ReplicationOption',
);
$this->input = $options ?? [];
}
/**
@ -70,10 +66,10 @@ class Options implements OptionsInterface
*/
public function defined($option)
{
return (
array_key_exists($option, $this->options) ||
array_key_exists($option, $this->input)
);
return
array_key_exists($option, $this->options)
|| array_key_exists($option, $this->input)
;
}
/**
@ -82,8 +78,8 @@ class Options implements OptionsInterface
public function __isset($option)
{
return (
array_key_exists($option, $this->options) ||
array_key_exists($option, $this->input)
array_key_exists($option, $this->options)
|| array_key_exists($option, $this->input)
) && $this->__get($option) !== null;
}
@ -100,14 +96,12 @@ class Options implements OptionsInterface
$value = $this->input[$option];
unset($this->input[$option]);
if (is_object($value) && method_exists($value, '__invoke')) {
$value = $value($this, $option);
}
if (isset($this->handlers[$option])) {
$handler = $this->handlers[$option];
$handler = new $handler();
$value = $handler->filter($this, $value);
} elseif (is_object($value) && method_exists($value, '__invoke')) {
$value = $value($this);
}
return $this->options[$option] = $value;