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:
Daniele Alessandri
2011-12-01 14:42:58 +01:00
parent a5bf0eb41a
commit 4a8c678561
2 changed files with 17 additions and 19 deletions
+2 -10
View File
@@ -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");
}
+15 -9
View File
@@ -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;
}
}