mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 19:49:20 +03:00
Predis to v2.2.2
This commit is contained in:
parent
f6b440adef
commit
84ffe1e552
259 changed files with 2407 additions and 9937 deletions
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Configuration;
|
||||
|
||||
use Predis\Connection\Aggregate\ClusterInterface;
|
||||
use Predis\Connection\Aggregate\PredisCluster;
|
||||
use Predis\Connection\Aggregate\RedisCluster;
|
||||
|
||||
/**
|
||||
* Configures an aggregate connection used for clustering
|
||||
* multiple Redis nodes using various implementations with
|
||||
* different algorithms or strategies.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class ClusterOption implements OptionInterface
|
||||
{
|
||||
/**
|
||||
* Creates a new cluster connection from on a known descriptive name.
|
||||
*
|
||||
* @param OptionsInterface $options Instance of the client options.
|
||||
* @param string $id Descriptive identifier of the cluster type (`predis`, `redis-cluster`)
|
||||
*
|
||||
* @return ClusterInterface|null
|
||||
*/
|
||||
protected function createByDescription(OptionsInterface $options, $id)
|
||||
{
|
||||
switch ($id) {
|
||||
case 'predis':
|
||||
case 'predis-cluster':
|
||||
return new PredisCluster();
|
||||
|
||||
case 'redis':
|
||||
case 'redis-cluster':
|
||||
return new RedisCluster($options->connections);
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filter(OptionsInterface $options, $value)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = $this->createByDescription($options, $value);
|
||||
}
|
||||
|
||||
if (!$value instanceof ClusterInterface) {
|
||||
throw new \InvalidArgumentException(
|
||||
"An instance of type 'Predis\Connection\Aggregate\ClusterInterface' was expected."
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefault(OptionsInterface $options)
|
||||
{
|
||||
return new PredisCluster();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Configuration;
|
||||
|
||||
use Predis\Connection\Factory;
|
||||
use Predis\Connection\FactoryInterface;
|
||||
|
||||
/**
|
||||
* Configures a connection factory used by the client to create new connection
|
||||
* instances for single Redis nodes.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class ConnectionFactoryOption implements OptionInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filter(OptionsInterface $options, $value)
|
||||
{
|
||||
if ($value instanceof FactoryInterface) {
|
||||
return $value;
|
||||
} elseif (is_array($value)) {
|
||||
$factory = $this->getDefault($options);
|
||||
|
||||
foreach ($value as $scheme => $initializer) {
|
||||
$factory->define($scheme, $initializer);
|
||||
}
|
||||
|
||||
return $factory;
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
'Invalid value provided for the connections option.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefault(OptionsInterface $options)
|
||||
{
|
||||
return new Factory();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Configuration;
|
||||
|
||||
/**
|
||||
* Configures whether consumers (such as the client) should throw exceptions on
|
||||
* Redis errors (-ERR responses) or just return instances of error responses.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class ExceptionsOption implements OptionInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filter(OptionsInterface $options, $value)
|
||||
{
|
||||
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefault(OptionsInterface $options)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
||||
|
|
@ -14,8 +15,6 @@ namespace Predis\Configuration;
|
|||
/**
|
||||
* Defines an handler used by Predis\Configuration\Options to filter, validate
|
||||
* or return default values for a given option.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
interface OptionInterface
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -11,25 +12,23 @@
|
|||
|
||||
namespace Predis\Configuration;
|
||||
|
||||
use Predis\Command\Processor\ProcessorInterface;
|
||||
|
||||
/**
|
||||
* Interface defining a container for client options.
|
||||
*
|
||||
* @property-read mixed aggregate Custom connection aggregator.
|
||||
* @property-read mixed cluster Aggregate connection for clustering.
|
||||
* @property-read mixed connections Connection factory.
|
||||
* @property-read mixed exceptions Toggles exceptions in client for -ERR responses.
|
||||
* @property-read mixed prefix Key prefixing strategy using the given prefix.
|
||||
* @property-read mixed profile Server profile.
|
||||
* @property-read mixed replication Aggregate connection for replication.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
* @property callable $aggregate Custom aggregate connection initializer
|
||||
* @property callable $cluster Aggregate connection initializer for clustering
|
||||
* @property \Predis\Connection\FactoryInterface $connections Connection factory for creating new connections
|
||||
* @property bool $exceptions Toggles exceptions in client for -ERR responses
|
||||
* @property ProcessorInterface $prefix Key prefixing strategy using the supplied string as prefix
|
||||
* @property \Predis\Command\FactoryInterface $commands Command factory for creating Redis commands
|
||||
* @property callable $replication Aggregate connection initializer for replication
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
|
@ -38,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
|
||||
*/
|
||||
|
|
@ -47,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
|
||||
*/
|
||||
|
|
@ -56,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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Configuration;
|
||||
|
||||
use Predis\Command\Processor\KeyPrefixProcessor;
|
||||
use Predis\Command\Processor\ProcessorInterface;
|
||||
|
||||
/**
|
||||
* Configures a command processor that apply the specified prefix string to a
|
||||
* series of Redis commands considered prefixable.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class PrefixOption implements OptionInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filter(OptionsInterface $options, $value)
|
||||
{
|
||||
if ($value instanceof ProcessorInterface) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return new KeyPrefixProcessor($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefault(OptionsInterface $options)
|
||||
{
|
||||
// NOOP
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Configuration;
|
||||
|
||||
use Predis\Profile\Factory;
|
||||
use Predis\Profile\ProfileInterface;
|
||||
use Predis\Profile\RedisProfile;
|
||||
|
||||
/**
|
||||
* Configures the server profile to be used by the client to create command
|
||||
* instances depending on the specified version of the Redis server.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class ProfileOption implements OptionInterface
|
||||
{
|
||||
/**
|
||||
* Sets the commands processors that need to be applied to the profile.
|
||||
*
|
||||
* @param OptionsInterface $options Client options.
|
||||
* @param ProfileInterface $profile Server profile.
|
||||
*/
|
||||
protected function setProcessors(OptionsInterface $options, ProfileInterface $profile)
|
||||
{
|
||||
if (isset($options->prefix) && $profile instanceof RedisProfile) {
|
||||
// NOTE: directly using __get('prefix') is actually a workaround for
|
||||
// HHVM 2.3.0. It's correct and respects the options interface, it's
|
||||
// just ugly. We will remove this hack when HHVM will fix re-entrant
|
||||
// calls to __get() once and for all.
|
||||
|
||||
$profile->setProcessor($options->__get('prefix'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filter(OptionsInterface $options, $value)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = Factory::get($value);
|
||||
$this->setProcessors($options, $value);
|
||||
} elseif (!$value instanceof ProfileInterface) {
|
||||
throw new \InvalidArgumentException('Invalid value for the profile option.');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefault(OptionsInterface $options)
|
||||
{
|
||||
$profile = Factory::getDefault();
|
||||
$this->setProcessors($options, $profile);
|
||||
|
||||
return $profile;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Configuration;
|
||||
|
||||
use Predis\Connection\Aggregate\MasterSlaveReplication;
|
||||
use Predis\Connection\Aggregate\ReplicationInterface;
|
||||
|
||||
/**
|
||||
* Configures an aggregate connection used for master/slave replication among
|
||||
* multiple Redis nodes.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class ReplicationOption implements OptionInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @todo There's more code than needed due to a bug in filter_var() as
|
||||
* discussed here https://bugs.php.net/bug.php?id=49510 and different
|
||||
* behaviours when encountering NULL values on PHP 5.3.
|
||||
*/
|
||||
public function filter(OptionsInterface $options, $value)
|
||||
{
|
||||
if ($value instanceof ReplicationInterface) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_bool($value) || $value === null) {
|
||||
return $value ? $this->getDefault($options) : null;
|
||||
}
|
||||
|
||||
if (
|
||||
!is_object($value) &&
|
||||
null !== $asbool = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)
|
||||
) {
|
||||
return $asbool ? $this->getDefault($options) : null;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(
|
||||
"An instance of type 'Predis\Connection\Aggregate\ReplicationInterface' was expected."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefault(OptionsInterface $options)
|
||||
{
|
||||
return new MasterSlaveReplication();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue