Add explicit toString() method that accepts a $raw parameter to override, but
authorJan Schneider <jan@horde.org>
Tue, 8 Dec 2009 00:40:56 +0000 (01:40 +0100)
committerJan Schneider <jan@horde.org>
Tue, 8 Dec 2009 00:40:56 +0000 (01:40 +0100)
not overwrite the local $raw property.
Michael, can we remove setRaw() with this new feature?

framework/Url/lib/Horde/Url.php

index be1fabe..7b3e3b0 100644 (file)
@@ -186,7 +186,8 @@ class Horde_Url
     /**
      * Sets the $raw value.  This call can be chained.
      *
-     * @param boolean  The value to set for $raw.
+     * @param boolean $raw  Whether to output the URL in the raw URL format or
+     *                      HTML-encoded.
      *
      * @return Horde_Url  This object, to allow chaining.
      */
@@ -199,9 +200,12 @@ class Horde_Url
     /**
      * Creates the full URL string.
      *
+     * @param boolean $raw  Whether to output the URL in the raw URL format or
+     *                      HTML-encoded.
+     *
      * @return string  The string representation of this object.
      */
-    public function __toString()
+    public function toString($raw = false)
     {
         $url_params = array();
         foreach ($this->parameters as $parameter => $value) {
@@ -223,13 +227,23 @@ class Horde_Url
             $url .= '/' . $this->pathInfo;
         }
         if (count($url_params)) {
-            $url .= '?' . implode($this->raw ? '&' : '&amp;', $url_params);
+            $url .= '?' . implode($raw ? '&' : '&amp;', $url_params);
         }
 
         return $url;
     }
 
     /**
+     * Creates the full URL string.
+     *
+     * @return string  The string representation of this object.
+     */
+    public function __toString()
+    {
+        return $this->toString($this->raw);
+    }
+
+    /**
      * Generates a HTML link tag out of this URL.
      *
      * @param array $attributes A hash with any additional attributes to be