Sfoglia il codice sorgente

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

Daniele Alessandri 15 anni fa
parent
commit
1b5e148d96
1 ha cambiato i file con 10 aggiunte e 2 eliminazioni
  1. 10 2
      lib/Predis.php

+ 10 - 2
lib/Predis.php

@@ -78,8 +78,16 @@ class Client {
         $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() {