public $anchor = '';
/**
+ * A callback function to use when converting to a string.
+ *
+ * @var callback
+ */
+ public $toStringCallback;
+
+ /**
* Constructor.
*
* @param string $url The basic URL, with or without query parameters.
*/
public function toString($raw = false)
{
+ if ($this->toStringCallback) {
+ $callback = $this->toStringCallback;
+ $this->toStringCallback = null;
+ $ret = call_user_func($callback, $this);
+ $this->toStringCallback = $callback;
+ return $ret;
+ }
+
$url_params = array();
foreach ($this->parameters as $parameter => $value) {
if (is_array($value)) {
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Add support for URL anchors.
+ <notes>* Add support for callback function for toString conversion.
+ * Add support for URL anchors.
* Added Horde_Url::uriB64Encode() and Horde_Url::uriB64Decode().
* Initial package.
</notes>
--- /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_CallbackTest extends PHPUnit_Framework_TestCase
+{
+ public function testRemoveRaw()
+ {
+ $url = new Horde_Url('test?bar=2');
+ $url->toStringCallback = array($this, 'callbackToString');
+ $this->assertEquals('FOOtest?bar=2BAR', (string)$url);
+ }
+
+ public function callbackToString($url)
+ {
+ return 'FOO' . (string)$url . 'BAR';
+ }
+
+}