Jelajahi Sumber

\Predis\Client::setProfile now accepts also a string value to specify the target server profile.

Daniele Alessandri 15 tahun lalu
induk
melakukan
1b5e148d96
1 mengubah file dengan 10 tambahan dan 2 penghapusan
  1. 10 2
      lib/Predis.php

+ 10 - 2
lib/Predis.php

@@ -78,8 +78,16 @@ class Client {
         $this->_connection = $connection;
         $this->_connection = $connection;
     }
     }
 
 
-    public function setProfile(RedisServerProfile $serverProfile) {
-        $this->_serverProfile = $serverProfile;
+    public function setProfile($serverProfile) {
+        if (!($serverProfile instanceof RedisServerProfile || is_string($serverProfile))) {
+            throw new \InvalidArgumentException(
+                "Invalid type for server profile, \Predis\RedisServerProfile or string expected"
+            );
+        }
+        $this->_serverProfile = (is_string($serverProfile) 
+            ? RedisServerProfile::get($serverProfile)
+            : $serverProfile
+        );
     }
     }
 
 
     public function getProfile() {
     public function getProfile() {