Эх сурвалжийг харах

Move the logic of the connection factory option to a dedicated class.

Daniele Alessandri 14 жил өмнө
parent
commit
cbc7929f6e

+ 2 - 14
lib/Predis/ClientOptions.php

@@ -3,9 +3,9 @@
 namespace Predis;
 
 use Predis\Options\IOption;
-use Predis\Options\CustomOption;
 use Predis\Options\ClientProfile;
 use Predis\Options\ClientKeyDistribution;
+use Predis\Options\ClientConnectionFactory;
 
 class ClientOptions {
     private $_handlers, $_options;
@@ -22,19 +22,7 @@ class ClientOptions {
         self::$_sharedOptions = array(
             'profile' => new ClientProfile(),
             'key_distribution' => new ClientKeyDistribution(),
-            'connections' => new CustomOption(array(
-                'default'  => function() {
-                    return new ConnectionFactory();
-                },
-                'validate' => function($value) {
-                    if ($value instanceof IConnectionFactory) {
-                        return $value;
-                    }
-                    if (is_array($value)) {
-                        return new ConnectionFactory($value);
-                    }
-                },
-            )),
+            'connections' => new ClientConnectionFactory(),
         );
         return self::$_sharedOptions;
     }

+ 21 - 0
lib/Predis/Options/ClientConnectionFactory.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace Predis\Options;
+
+use Predis\IConnectionFactory;
+use Predis\ConnectionFactory;
+
+class ClientConnectionFactory extends Option {
+    public function validate($value) {
+        if ($value instanceof IConnectionFactory) {
+            return $value;
+        }
+        if (is_array($value)) {
+            return new ConnectionFactory($value);
+        }
+    }
+
+    public function getDefault() {
+        return new ConnectionFactory();
+    }
+}