From: Michael M Slusarz Date: Fri, 21 Jan 2011 19:44:37 +0000 (-0700) Subject: Bug #9455: Add ability to return relative URL when converting to string X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5693513dfe4078a26fc91e8a8820a95265b48155;p=horde.git Bug #9455: Add ability to return relative URL when converting to string --- diff --git a/framework/Url/lib/Horde/Url.php b/framework/Url/lib/Horde/Url.php index 578c03ac3..bdfa90214 100644 --- a/framework/Url/lib/Horde/Url.php +++ b/framework/Url/lib/Horde/Url.php @@ -213,12 +213,13 @@ class Horde_Url /** * 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; @@ -243,7 +244,10 @@ class Horde_Url } } - $url = $this->url; + $url = $full + ? $this->url + : parse_url($this->url, PHP_URL_PATH); + if (strlen($this->pathInfo)) { $url = rtrim($url, '/'); $url .= '/' . $this->pathInfo; diff --git a/framework/Url/package.xml b/framework/Url/package.xml index 4b28cb5c6..a4936cc27 100644 --- a/framework/Url/package.xml +++ b/framework/Url/package.xml @@ -28,7 +28,8 @@ LGPL -* 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. @@ -56,6 +57,7 @@ + @@ -86,6 +88,7 @@ + diff --git a/framework/Url/test/Horde/Url/TostringTest.php b/framework/Url/test/Horde/Url/TostringTest.php new file mode 100644 index 000000000..b8944cb70 --- /dev/null +++ b/framework/Url/test/Horde/Url/TostringTest.php @@ -0,0 +1,24 @@ + + * @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) + ); + } +}