Move assertion for connection parameters out of abstract connection class.

Each connection class should implement its own checks for connection parameters,
even at the cost of some code duplication (inheritance is not just about code
reuse after all).
This commit is contained in:
Daniele Alessandri
2015-07-25 10:44:45 +02:00
parent 73c9b9d5be
commit 7fa3c55f51
4 changed files with 47 additions and 16 deletions
+2 -15
View File
@@ -52,23 +52,10 @@ abstract class AbstractConnection implements NodeConnectionInterface
* @param ParametersInterface $parameters Initialization parameters for the connection.
*
* @throws \InvalidArgumentException
* @return ParametersInterface
*
* @return ParametersInterface
*/
protected function assertParameters(ParametersInterface $parameters)
{
switch ($parameters->scheme) {
case 'tcp':
case 'redis':
case 'unix':
break;
default:
throw new \InvalidArgumentException("Invalid scheme: '$parameters->scheme'.");
}
return $parameters;
}
abstract protected function assertParameters(ParametersInterface $parameters);
/**
* Creates the underlying resource used to communicate with Redis.
+9 -1
View File
@@ -93,7 +93,15 @@ class PhpiredisSocketConnection extends AbstractConnection
*/
protected function assertParameters(ParametersInterface $parameters)
{
parent::assertParameters($parameters);
switch ($parameters->scheme) {
case 'tcp':
case 'redis':
case 'unix':
break;
default:
throw new \InvalidArgumentException("Invalid scheme: '$parameters->scheme'.");
}
if (isset($parameters->persistent)) {
throw new NotSupportedException(
@@ -84,6 +84,24 @@ class PhpiredisStreamConnection extends StreamConnection
}
}
/**
* {@inheritdoc}
*/
protected function assertParameters(ParametersInterface $parameters)
{
switch ($parameters->scheme) {
case 'tcp':
case 'redis':
case 'unix':
break;
default:
throw new \InvalidArgumentException("Invalid scheme: '$parameters->scheme'.");
}
return $parameters;
}
/**
* {@inheritdoc}
*/
+18
View File
@@ -47,6 +47,24 @@ class StreamConnection extends AbstractConnection
$this->disconnect();
}
/**
* {@inheritdoc}
*/
protected function assertParameters(ParametersInterface $parameters)
{
switch ($parameters->scheme) {
case 'tcp':
case 'redis':
case 'unix':
break;
default:
throw new \InvalidArgumentException("Invalid scheme: '$parameters->scheme'.");
}
return $parameters;
}
/**
* {@inheritdoc}
*/