/**
* Creates the full URL string.
*
- * @param boolean $raw Whether to output the URL in the raw URL format or
- * HTML-encoded.
+ * @param boolean $raw Whether to output the URL in the raw URL format
+ * or HTML-encoded.
+ * @param boolean $full Output the full URL?
*
* @return string The string representation of this object.
*/
- public function toString($raw = false)
+ public function toString($raw = false, $full = true)
{
if ($this->toStringCallback) {
$callback = $this->toStringCallback;
}
}
- $url = $this->url;
+ $url = $full
+ ? $this->url
+ : parse_url($this->url, PHP_URL_PATH);
+
if (strlen($this->pathInfo)) {
$url = rtrim($url, '/');
$url .= '/' . $this->pathInfo;
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
<notes>
-* Add Horde_Url_Exception::.
+ * Add ability to return relative URL when converting to string.
+ * Add Horde_Url_Exception::.
* Add Horde_Url::redirect().
* Add Horde_Url::unique().
* Add support for callback function for toString conversion.
<file name="RawTest.php" role="test" />
<file name="RedirectTest.php" role="test" />
<file name="RemoveTest.php" role="test" />
+ <file name="TostringTest.php" role="test" />
</dir> <!-- /test/Horde/Url -->
</dir> <!-- /test/Horde -->
</dir> <!-- /test -->
<install as="Horde/Url/RawTest.php" name="test/Horde/Url/RawTest.php" />
<install as="Horde/Url/RedirectTest.php" name="test/Horde/Url/RedirectTest.php" />
<install as="Horde/Url/RemoveTest.php" name="test/Horde/Url/RemoveTest.php" />
+ <install as="Horde/Url/TostringTest.php" name="test/Horde/Url/TostringTest.php" />
</filelist>
</phprelease>
<changelog>
--- /dev/null
+<?php
+/**
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @category Horde
+ * @package Url
+ * @subpackage UnitTests
+ */
+
+class Horde_Url_TostringTest extends PHPUnit_Framework_TestCase
+{
+ public function testFullUrl()
+ {
+ $url = new Horde_Url('http://example.com/test?foo=1&bar=2');
+ $this->assertEquals(
+ '/test?foo=1&bar=2',
+ $url->toString(true, false)
+ );
+ $this->assertEquals(
+ 'http://example.com/test?foo=1&bar=2',
+ $url->toString(true, true)
+ );
+ }
+}