Author: as
Date: Thu Aug 2 11:11:58 2007
New Revision: 5803
Log:
- Implemented feature request #11000: Added ability to include script name
when building an URL through a buildUrl() parameter.
Modified:
trunk/Url/ChangeLog
trunk/Url/docs/tutorial.txt
trunk/Url/docs/tutorial/tutorial_get_params.php
trunk/Url/src/url.php
trunk/Url/tests/url_test.php
Modified: trunk/Url/ChangeLog
==============================================================================
--- trunk/Url/ChangeLog [iso-8859-1] (original)
+++ trunk/Url/ChangeLog [iso-8859-1] Thu Aug 2 11:11:58 2007
@@ -1,3 +1,10 @@
+1.2alpha1 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Implemented feature request #11000: Added ability to include script name
+ when building an URL through a buildUrl() parameter.
+
+
1.1 - Monday 02 July 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Modified: trunk/Url/docs/tutorial.txt
==============================================================================
--- trunk/Url/docs/tutorial.txt [iso-8859-1] (original)
+++ trunk/Url/docs/tutorial.txt [iso-8859-1] Thu Aug 2 11:11:58 2007
@@ -42,9 +42,10 @@
By using the ezcUrlConfiguration class, you can specify a custom configuration
that can be used to parse urls. The properties you can set in objects of this
-class are the default base directory, default script name (which will be
-hidden when building the url), delimiters for unordered parameter names
-and names for accepted parameters.
+class are the default base directory, default script name (eg. index.php)
+(which will be hidden when building the url by default, but can be displayed
+by calling buildUrl( true )), delimiters for unordered parameter names and
+names for accepted parameters.
Working with the query part
===========================
@@ -198,6 +199,8 @@
}
string(72) "http://www.example.com/mydir/groups/Games/Adventure/Adult/
(game)/Larry/7"
+ string(82) "http://www.example.com/mydir/index.php/groups/Games/Adventure/
+ Adult/(game)/Larry/7"
Setting parameters using a url configuration
--------------------------------------------
Modified: trunk/Url/docs/tutorial/tutorial_get_params.php
==============================================================================
--- trunk/Url/docs/tutorial/tutorial_get_params.php [iso-8859-1] (original)
+++ trunk/Url/docs/tutorial/tutorial_get_params.php [iso-8859-1] Thu Aug 2
11:11:58 2007
@@ -33,4 +33,6 @@
// output the url (index.php will not be there)
var_dump( $url->buildUrl() );
+// output the url (with index.php included)
+var_dump( $url->buildUrl( true ) );
?>
Modified: trunk/Url/src/url.php
==============================================================================
--- trunk/Url/src/url.php [iso-8859-1] (original)
+++ trunk/Url/src/url.php [iso-8859-1] Thu Aug 2 11:11:58 2007
@@ -367,9 +367,13 @@
* The query part of the URL is build with http_build_query() which
* encodes the query in a similar way to urlencode().
*
+ * If $includeScriptName is true, then the script name (eg. 'index.php')
+ * will be included in the result. By default the script name is hidden.
+ *
+ * @param bool $includeScriptName
* @return string
*/
- public function buildUrl()
+ public function buildUrl( $includeScriptName = false )
{
$url = '';
@@ -404,6 +408,14 @@
if ( !( count( $this->basedir ) == 0 || trim(
$this->basedir[0] ) === "" ) )
{
$url .= '/' . implode( '/', $this->basedir );
+ }
+ }
+
+ if ( $includeScriptName && $this->script )
+ {
+ if ( !( count( $this->script ) == 0 || trim( $this->script[0]
) === "" ) )
+ {
+ $url .= '/' . implode( '/', $this->script );
}
}
Modified: trunk/Url/tests/url_test.php
==============================================================================
--- trunk/Url/tests/url_test.php [iso-8859-1] (original)
+++ trunk/Url/tests/url_test.php [iso-8859-1] Thu Aug 2 11:11:58 2007
@@ -543,6 +543,49 @@
$this->assertEquals( 'components', $url->getParam( 'module' ) );
$this->assertEquals( 'view', $url->getParam( 'view' ) );
$this->assertEquals( 'trunk', $url->getParam( 'branch' ) );
+ }
+
+ public function testBuildUrlWithScriptName()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+ $urlCfg->basedir = '/mydir/shop';
+ $urlCfg->script = 'index.php';
+ $urlCfg->addOrderedParameter( 'section' );
+ $urlCfg->addOrderedParameter( 'module' );
+ $urlCfg->addOrderedParameter( 'view' );
+ $urlCfg->addOrderedParameter( 'content' );
+
+ $url = new ezcUrl(
'http://www.example.com/mydir/shop/index.php/doc/components/view/trunk',
$urlCfg );
+ $expected =
'http://www.example.com/mydir/shop/index.php/doc/components/view/trunk';
+ $this->assertEquals( $expected, $url->buildUrl( true ) );
+ }
+
+ public function testBuildUrlWithScriptNameWithoutBasedir()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+ $urlCfg->script = 'index.php';
+ $urlCfg->addOrderedParameter( 'section' );
+ $urlCfg->addOrderedParameter( 'module' );
+ $urlCfg->addOrderedParameter( 'view' );
+ $urlCfg->addOrderedParameter( 'content' );
+
+ $url = new ezcUrl(
'http://www.example.com/index.php/doc/components/view/trunk', $urlCfg );
+ $expected =
'http://www.example.com/index.php/doc/components/view/trunk';
+ $this->assertEquals( $expected, $url->buildUrl( true ) );
+ }
+
+ public function testBuildUrlWithScriptNameMissingScript()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+ $urlCfg->basedir = '/mydir/shop';
+ $urlCfg->addOrderedParameter( 'section' );
+ $urlCfg->addOrderedParameter( 'module' );
+ $urlCfg->addOrderedParameter( 'view' );
+ $urlCfg->addOrderedParameter( 'content' );
+
+ $url = new ezcUrl(
'http://www.example.com/mydir/shop/doc/components/view/trunk', $urlCfg );
+ $expected =
'http://www.example.com/mydir/shop/doc/components/view/trunk';
+ $this->assertEquals( $expected, $url->buildUrl( true ) );
}
public function testIsSet()
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components