mirror of
https://github.com/predis/predis.git
synced 2026-08-31 04:35:05 +00:00
Change how the key prefix processor is initialized.
When the argument of 'profile' is an instance of Predis\Profiles\IServerProfile the value of the 'prefix' option is ignored, which means that it is up to the user to initialize the appropriate prefix processor.
This commit is contained in:
+2
-10
@@ -46,13 +46,8 @@ class Client
|
||||
{
|
||||
$options = $this->filterOptions($options);
|
||||
|
||||
$profile = $options->profile;
|
||||
if (isset($options->prefix)) {
|
||||
$profile->setProcessor($options->prefix);
|
||||
}
|
||||
|
||||
$this->options = $options;
|
||||
$this->profile = $profile;
|
||||
$this->profile = $options->profile;
|
||||
$this->connections = $options->connections;
|
||||
|
||||
$this->connection = $this->initializeConnection($parameters);
|
||||
@@ -77,12 +72,9 @@ class Client
|
||||
if ($options instanceof IClientOptions) {
|
||||
return $options;
|
||||
}
|
||||
if ($options instanceof IServerProfile) {
|
||||
if ($options instanceof IServerProfile || is_string($options)) {
|
||||
return new ClientOptions(array('profile' => $options));
|
||||
}
|
||||
if (is_string($options)) {
|
||||
return new ClientOptions(array('profile' => ServerProfile::get($options)));
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("Invalid type for client options");
|
||||
}
|
||||
|
||||
@@ -26,17 +26,18 @@ class ClientProfile extends Option
|
||||
*/
|
||||
public function validate(IClientOptions $options, $value)
|
||||
{
|
||||
if ($value instanceof IServerProfile) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
return ServerProfile::get($value);
|
||||
$value = ServerProfile::get($value);
|
||||
if (isset($options->prefix)) {
|
||||
$value->setProcessor($options->prefix);
|
||||
}
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(
|
||||
"Invalid value for the profile option"
|
||||
);
|
||||
if (!$value instanceof IServerProfile) {
|
||||
throw new \InvalidArgumentException('Invalid value for the profile option');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,6 +45,11 @@ class ClientProfile extends Option
|
||||
*/
|
||||
public function getDefault(IClientOptions $options)
|
||||
{
|
||||
return ServerProfile::getDefault();
|
||||
$profile = ServerProfile::getDefault();
|
||||
if (isset($options->prefix)) {
|
||||
$profile->setProcessor($options->prefix);
|
||||
}
|
||||
|
||||
return $profile;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user