Author: as
Date: Mon Aug 6 14:32:13 2007
New Revision: 5821
Log:
- Implemented feature request #10897: Added the getParams() method in ezcUrl
which fetches the unordered parameters as a flat array, useful for working
with URLs without delimiters for parameter names.
Added:
trunk/Url/docs/tutorial/tutorial_get_params_no_delimiters.php (with props)
Modified:
trunk/Url/ChangeLog
trunk/Url/docs/tutorial.txt
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] Mon Aug 6 14:32:13 2007
@@ -5,6 +5,9 @@
when building an URL through a buildUrl() parameter.
- Implemented feature request #10896: Allow aggregation of unordered parameter
values if the parameter names appear more than once.
+- Implemented feature request #10897: Added the getParams() method in ezcUrl
+ which fetches the unordered parameters as a flat array, useful for working
+ with URLs without delimiters for parameter names.
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] Mon Aug 6 14:32:13 2007
@@ -242,6 +242,48 @@
}
string(46) "http://www.example.com/(param1)/x/(param1)/y/z"
+Getting unordered parameters without name delimiters
+----------------------------------------------------
+
+If the URL doesn't contain delimiters for unordered parameter names, then you
+can use the getParams() method to return the values after the basedir, script
+and ordered parameters as a flat array. This array can be parsed later by your
+application to make it an associative array.
+
+Example:
+
+.. include:: tutorial/tutorial_get_params_no_delimiters.php
+ :literal:
+
+The output will be: ::
+
+ array(8) {
+ [0]=>
+ string(8) "Software"
+ [1]=>
+ string(3) "PHP"
+ [2]=>
+ string(7) "Version"
+ [3]=>
+ string(3) "5.2"
+ [4]=>
+ string(9) "Extension"
+ [5]=>
+ string(6) "XDebug"
+ [6]=>
+ string(9) "Extension"
+ [7]=>
+ string(7) "openssl"
+ }
+
+This array can then be translated by your application to this form (if needed):
+ ::
+
+ array( "Software" => array( "PHP" ),
+ "Version" => array( "5.2" ),
+ "Extension" => array( "XDebug", "openssl" )
+ );
+
Setting parameters using a url configuration
--------------------------------------------
Added: trunk/Url/docs/tutorial/tutorial_get_params_no_delimiters.php
==============================================================================
--- trunk/Url/docs/tutorial/tutorial_get_params_no_delimiters.php (added)
+++ trunk/Url/docs/tutorial/tutorial_get_params_no_delimiters.php [iso-8859-1]
Mon Aug 6 14:32:13 2007
@@ -1,0 +1,15 @@
+<?php
+require_once 'tutorial_autoload.php';
+
+// create an ezcUrlConfiguration object
+$urlCfg = new ezcUrlConfiguration();
+
+$urlCfg->basedir = '/mydir/shop';
+$urlCfg->script = 'index.php';
+$urlCfg->addOrderedParameter( 'module' );
+
+$url = new ezcUrl(
'http://www.example.com/mydir/shop/index.php/order/Software/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+
+// get the unordered parameters as a flat array
+var_dump( $url->getParams() ); // will output array( 'Software', 'PHP',
'Version', '5.2', 'Extension', 'XDebug', 'Extension', 'openssl' )
+?>
Propchange: trunk/Url/docs/tutorial/tutorial_get_params_no_delimiters.php
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/Url/src/url.php
==============================================================================
--- trunk/Url/src/url.php [iso-8859-1] (original)
+++ trunk/Url/src/url.php [iso-8859-1] Mon Aug 6 14:32:13 2007
@@ -52,6 +52,19 @@
* $url = new ezcUrl( 'http://www.example.com/(param1)/x/(param1)/y/z',
$urlCfg );
*
* $param1 = $url->getParam( 'param1' ); // will be array( array( "x" ),
array( "y", "z" ) )
+ * </code>
+ *
+ * Unordered parameters can also be fetched as a flat array (useful if the
+ * URL doesn't have delimiters for the unordered parameter names). Example:
+ * <code>
+ * $urlCfg = new ezcUrlConfiguration();
+ * $urlCfg->basedir = '/mydir/shop';
+ * $urlCfg->script = 'index.php';
+ * $urlCfg->addOrderedParameter( 'module' );
+ *
+ * $url = new ezcUrl(
'http://www.example.com/mydir/shop/index.php/order/Software/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+ *
+ * $params = $url->getParams(); // will be array( 'Software', 'PHP',
'Version', '5.2', 'Extension', 'XDebug', 'Extension', 'openssl' )
* </code>
*
* @property string $host
@@ -739,6 +752,33 @@
}
/**
+ * Returns the unordered parameters from the URL as a flat array.
+ *
+ * It takes into account the basedir, script and ordered parameters.
+ *
+ * It can be used for URLs which don't have delimiters for the unordered
+ * parameters.
+ *
+ * Example:
+ * <code>
+ * $urlCfg = new ezcUrlConfiguration();
+ * $urlCfg->basedir = '/mydir/shop';
+ * $urlCfg->script = 'index.php';
+ * $urlCfg->addOrderedParameter( 'module' );
+ *
+ * $url = new ezcUrl(
'http://www.example.com/mydir/shop/index.php/order/Software/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+ *
+ * $params = $url->getParams(); // will be array( 'Software', 'PHP',
'Version', '5.2', 'Extension', 'XDebug', 'Extension', 'openssl' )
+ * </code>
+ *
+ * @return array(string)
+ */
+ public function getParams()
+ {
+ return array_slice( $this->path, count( $this->basedir ) + count(
$this->script ) + count( $this->params ) );
+ }
+
+ /**
* Returns the query elements as an associative array.
*
* Example:
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] Mon Aug 6 14:32:13 2007
@@ -904,6 +904,80 @@
{
$this->assertEquals( "The value 'a:1:{i:0;s:1:\"x\";}' that you
were trying to assign to setting 'param2' is invalid. Allowed values are:
string.", $e->getMessage() );
}
+ }
+
+ public function testGetUnorderedParametersUnknownNoOrdered()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+
+ $url = new ezcUrl(
'http://www.example.com/Software/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+ $this->assertEquals( array( 'Software', 'PHP', 'Version', '5.2',
'Extension', 'XDebug', 'Extension', 'openssl' ), $url->getParams() );
+ }
+
+ public function testGetUnorderedParametersUnknownBasedir()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+ $urlCfg->basedir = '/mydir/shop';
+
+ $url = new ezcUrl(
'http://www.example.com/mydir/shop/Software/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+ $this->assertEquals( array( 'Software', 'PHP', 'Version', '5.2',
'Extension', 'XDebug', 'Extension', 'openssl' ), $url->getParams() );
+ }
+
+ public function testGetUnorderedParametersUnknownScript()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+ $urlCfg->script = 'index.php';
+
+ $url = new ezcUrl(
'http://www.example.com/index.php/Software/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+ $this->assertEquals( array( 'Software', 'PHP', 'Version', '5.2',
'Extension', 'XDebug', 'Extension', 'openssl' ), $url->getParams() );
+ }
+
+ public function testGetUnorderedParametersUnknownBasedirScript()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+ $urlCfg->basedir = '/mydir/shop';
+ $urlCfg->script = 'index.php';
+
+ $url = new ezcUrl(
'http://www.example.com/mydir/shop/index.php/Software/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+ $this->assertEquals( array( 'Software', 'PHP', 'Version', '5.2',
'Extension', 'XDebug', 'Extension', 'openssl' ), $url->getParams() );
+ }
+
+ public function testGetUnorderedParametersUnknownOrdered()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+ $urlCfg->addOrderedParameter( 'module' );
+
+ $url = new ezcUrl(
'http://www.example.com/order/Software/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+ $this->assertEquals( array( 'Software', 'PHP', 'Version', '5.2',
'Extension', 'XDebug', 'Extension', 'openssl' ), $url->getParams() );
+ }
+
+ public function testGetUnorderedParametersUnknownBasedirScriptOrdered()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+ $urlCfg->basedir = '/mydir/shop';
+ $urlCfg->script = 'index.php';
+ $urlCfg->addOrderedParameter( 'module' );
+
+ $url = new ezcUrl(
'http://www.example.com/mydir/shop/index.php/order/Software/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+ $this->assertEquals( 'order', $url->getParam( 'module' ) );
+ $this->assertEquals( array( 'Software', 'PHP', 'Version', '5.2',
'Extension', 'XDebug', 'Extension', 'openssl' ), $url->getParams() );
+ $this->assertEquals( 'order', $url->getParam( 'module' ) );
+ }
+
+ public function
testGetUnorderedParametersUnknownBasedirScriptOrderedUnordered()
+ {
+ $urlCfg = new ezcUrlConfiguration();
+ $urlCfg->basedir = '/mydir/shop';
+ $urlCfg->script = 'index.php';
+ $urlCfg->addOrderedParameter( 'module' );
+ $urlCfg->addUnorderedParameter( 'Software' );
+
+ $url = new ezcUrl(
'http://www.example.com/mydir/shop/index.php/order/(Software)/PHP/Version/5.2/Extension/XDebug/Extension/openssl',
$urlCfg );
+ $this->assertEquals( 'order', $url->getParam( 'module' ) );
+ $this->assertEquals( 'PHP', $url->getParam( 'Software' ) );
+ $this->assertEquals( array( '(Software)', 'PHP', 'Version', '5.2',
'Extension', 'XDebug', 'Extension', 'openssl' ), $url->getParams() );
+ $this->assertEquals( 'PHP', $url->getParam( 'Software' ) );
+ $this->assertEquals( 'order', $url->getParam( 'module' ) );
}
public function testIsSet()
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components