From 3355d049cb0b43921b690d8e73ffe1595f2c9ae6 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 8 Dec 2009 23:26:36 +0100 Subject: [PATCH] Add copy() instead of cAdd() and cRemove(). Fix BC for some edge cases. --- framework/Url/lib/Horde/Url.php | 41 +++++++++++---------------------------- framework/Util/lib/Horde/Util.php | 15 ++++++++++---- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/framework/Url/lib/Horde/Url.php b/framework/Url/lib/Horde/Url.php index 7b3e3b01e..db36bd8d3 100644 --- a/framework/Url/lib/Horde/Url.php +++ b/framework/Url/lib/Horde/Url.php @@ -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 diff --git a/framework/Util/lib/Horde/Util.php b/framework/Util/lib/Horde/Util.php index 607c7ec1d..742a6ac84 100644 --- a/framework/Util/lib/Horde/Util.php +++ b/framework/Util/lib/Horde/Util.php @@ -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); -- 2.11.0