Add copy() instead of cAdd() and cRemove().
authorJan Schneider <jan@horde.org>
Tue, 8 Dec 2009 22:26:36 +0000 (23:26 +0100)
committerJan Schneider <jan@horde.org>
Tue, 8 Dec 2009 22:35:10 +0000 (23:35 +0100)
Fix BC for some edge cases.

framework/Url/lib/Horde/Url.php
framework/Util/lib/Horde/Util.php

index 7b3e3b0..db36bd8 100644 (file)
@@ -102,6 +102,17 @@ class Horde_Url
     }
 
     /**
+     * Returns a clone of this object. Useful for chaining.
+     *
+     * @return Horde_Url  A clone of this object.
+     */
+    public function copy()
+    {
+        $url = clone $this;
+        return $url;
+    }
+
+    /**
      * Adds one or more query parameters.
      *
      * @param mixed $parameters  Either the name value or an array of
@@ -133,22 +144,6 @@ class Horde_Url
     }
 
     /**
-     * Identical to add(), except the return value is a cloned object.
-     *
-     * @param mixed $parameters  Either the name value or an array of
-     *                           name/value pairs.
-     * @param string $value      If specified, the value part ($parameters is
-     *                           then assumed to just be the parameter name).
-     *
-     * @return Horde_Url  Cloned object, to allow chaining.
-     */
-    public function cAdd($parameters, $value = null)
-    {
-        $url = clone $this;
-        return $url->add($parameters, $value);
-    }
-
-    /**
      * Removes one ore more parameters.
      *
      * @param mixed $remove  Either a single parameter to remove or an array
@@ -170,20 +165,6 @@ class Horde_Url
     }
 
     /**
-     * Identical to remove(), except the return value is a cloned object.
-     *
-     * @param mixed $remove  Either a single parameter to remove or an array
-     *                       of parameters to remove.
-     *
-     * @return Horde_Url  Cloned object, to allow chaining.
-     */
-    public function cRemove($parameters)
-    {
-        $url = clone $this;
-        return $url->remove($parameters);
-    }
-
-    /**
      * Sets the $raw value.  This call can be chained.
      *
      * @param boolean $raw  Whether to output the URL in the raw URL format or
index 607c7ec..742a6ac 100644 (file)
@@ -235,11 +235,18 @@ class Horde_Util
         }
 
         if ($url instanceof Horde_Url) {
-            return $url->cAdd($parameter, $value)->setRaw(!$encode);
+            $url = $url->copy()->add($parameter, $value);
+            if (is_null($url->raw)) {
+                $url->setRaw(!$encode);
+            }
+            return $url;
         }
 
-        $horde_url = new Horde_Url($url, !$encode);
-        return $horde_url->add($parameter, $value);
+        $url = new Horde_Url($url);
+        if (is_null($url->raw) && count($url->parameters)) {
+            $url->setRaw(!$encode);
+        }
+        return $url->add($parameter, $value);
     }
 
     /**
@@ -254,7 +261,7 @@ class Horde_Util
     static public function removeParameter($url, $remove)
     {
         if ($url instanceof Horde_Url) {
-            return $url->cRemove($remove);
+            return $url->copy()->remove($remove);
         }
 
         $horde_url = new Horde_Url($url);