ソースを参照

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).
Daniele Alessandri 9 年 前
コミット
7fa3c55f51

+ 2 - 15
src/Connection/AbstractConnection.php

@@ -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
src/Connection/PhpiredisSocketConnection.php

@@ -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(

+ 18 - 0
src/Connection/PhpiredisStreamConnection.php

@@ -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 - 0
src/Connection/StreamConnection.php

@@ -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}
      */