application configurati
file and before any services.
+Info:
+The
TUrlMapping must be configured before the
+
Request module resolves the request.
+This usually means delcaring the
TUrlMapping module before any
+
<services> tag in the
application configuration.
+Specifying the mappings in the per directory
config.xml is not supported.
+
+
The mapping format is as follows.
-
+
The ServiceParameter and ServiceID
- (the default ID is 'page') set the service parameter and service ID respectively.
+ (the default ID is 'page') set the service parameter and service ID, respectively, of
+ the Request module.
The service parameter for the TPageService service is the
Page class name, e.g., for an URL "index.php?page=Home", "page" is the service ID and the service
parameter is "Home". Other services may use the service parameter and ID differently.
@@ -42,15 +51,15 @@ and a right brace '}'. The pattens for each parameter can be set
using Parametersattribute collection.
For example,
-
-The example is equivalent, using regular expression only, to
+The example is equivalent to the following regular expression (it uses the "named group" feature in regular expressions available in PHP):
-
+
\d{4})/(?P\d{2})/(?P\d+)
+ /articles\/(?P\d{4})\/(?P\d{2})\/(?P\d+)/u
]]>
@@ -59,19 +68,27 @@ In the above example, the pattern contains 3 parameters named "year",
"month" and "day". The pattern for these parameters are,
respectively, "\d{4}" (4 digits), "\d{2}" (2 digits)
and "\d+" (1 or more digits).
+Essentially, the Parameters attribute name and values are used
+ as substrings in replacing the placeholders in the Pattern string
+to form a complete regular expression string.
-For example, an URL "http://example.com/index.php/articles/2006/07/21" will be matched
+
Note: If you intended to use the RegularExpression
+property you need to escape the slash in regular expressions.
+
+
+Following from the above pattern example,
+an URL "http://example.com/index.php/articles/2006/07/21" will be matched
and valid. However, "http://example.com/index.php/articles/2006/07/hello" is not
valid since the "day" parameter pattern is not satisfied.
In the default TUrlMappingPattern class, the pattern is matched against the
path property of the URL only. For example, only the
-"/index.php/articles/2006/07/21" portion of the URL is considered and the rest
-is ignored.
+"/index.php/articles/2006/07/21" portion of the URL is considered.
-
-The parameter values are available through the standard Request
+
+The mapped request URL is equivalent to index.php?page=ArticleView&year=2006&month=07&day=21.
+The request parameter values are available through the standard Request
object. For example, $this->Request['year'].
diff --git a/demos/quickstart/protected/pages/Controls/Validation.page b/demos/quickstart/protected/pages/Controls/Validation.page
index 119749db..2405fb45 100644
--- a/demos/quickstart/protected/pages/Controls/Validation.page
+++ b/demos/quickstart/protected/pages/Controls/Validation.page
@@ -151,7 +151,7 @@ The summary can be displayed as a list, a bulleted list, or a single paragraph b
-Client and Server Side Conditional Validation
+Client and Server Side Conditional Validation
All validators contains the following events.
@@ -180,7 +180,7 @@ function onErrorHandler(sender, parameter)
Where sender is the current client-side validator and parameter
is the control that invoked the validator.
-Conditional Validation Example
+Conditional Validation Example
The following example show the use of client-side and server side validator events. The example
demonstrates conditional validation.
diff --git a/demos/quickstart/protected/pages/GettingStarted/CommandLine.page b/demos/quickstart/protected/pages/GettingStarted/CommandLine.page
index c2050246..cf204a40 100644
--- a/demos/quickstart/protected/pages/GettingStarted/CommandLine.page
+++ b/demos/quickstart/protected/pages/GettingStarted/CommandLine.page
@@ -1,18 +1,18 @@
-Command Line Tool
+Command Line Tool
The optional prado-cli.php PHP script file in the framework
directory provides command line tools to perform various tendious taks in Prado.
The prado-cli.php can be used to create Prado project skeletons, create
initial test fixtures, and access to an interactive PHP shell.
-Requirements
+Requirements
To use the command line tool, you need to use your command prompt, command console
or terminal. In addition, PHP must be able to execute PHP scripts from
the command line.
-Usage
+Usage
If you type php path/to/framework/prado-cli.php, you should see
the following information. Alternatively, if you are not on Windows,
@@ -38,7 +38,7 @@ actions:
The <parameter> are required parameters and [optional]
are optional parameters.
-Creating a new Prado project skeleton
+Creating a new Prado project skeleton
To create a Prado project skeleton, do the following:
@@ -49,7 +49,7 @@ are optional parameters.
the test fixtures for the helloworld project.
-Interactive Shell
+Interactive Shell
The interactive shell allows you to evaluate PHP statements from te command line.
The prado-cli.php script can be used to start the shell and load an existing
diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php
index aa690540..90007fa2 100644
--- a/framework/Web/THttpRequest.php
+++ b/framework/Web/THttpRequest.php
@@ -596,7 +596,10 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar
}
}
- protected function getRequestResolved()
+ /**
+ * @return boolean true if request is already resolved, false otherwise.
+ */
+ public function getRequestResolved()
{
return $this->_requestResolved;
}
@@ -631,7 +634,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar
* Sets the requested service ID.
* @param string requested service ID
*/
- protected function setServiceID($value)
+ public function setServiceID($value)
{
$this->_serviceID=$value;
}
@@ -650,7 +653,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar
* Sets the requested service parameter.
* @param string requested service parameter
*/
- protected function setServiceParameter($value)
+ public function setServiceParameter($value)
{
$this->_serviceParam=$value;
}
diff --git a/framework/Web/TUrlMapping.php b/framework/Web/TUrlMapping.php
index 90acfd13..6df08c3f 100644
--- a/framework/Web/TUrlMapping.php
+++ b/framework/Web/TUrlMapping.php
@@ -43,7 +43,7 @@
* @package System.Web
* @since 3.0.5
*/
-class TUrlMapping extends THttpRequest
+class TUrlMapping extends TModule
{
/**
* @var string default pattern class.
@@ -201,9 +201,9 @@ class TUrlMapping extends THttpRequest
*
* Describes an URL mapping pattern, if a given URL matches the pattern, the
* TUrlMapping class will alter the THttpRequest parameters. The
- * url matching is done using regular expressions.
+ * url matching is done using patterns and regular expressions.
*
- * The {@link setPattern Pattern} property takes a regular expression with
+ * The {@link setPattern Pattern} property takes an string expression with
* parameter names enclosed between a left brace '{' and a right brace '}'.
* The pattens for each parameter can be set using {@link getParameters Parameters}
* attribute collection. For example
@@ -215,6 +215,17 @@ class TUrlMapping extends THttpRequest
* In the above example, the pattern contains 3 parameters named "year",
* "month" and "day". The pattern for these parameters are, respectively,
* "\d{4}" (4 digits), "\d{2}" (2 digits) and "\d+" (1 or more digits).
+ * Essentially, the Parameters attribute name and values are used
+ * as substrings in replacing the placeholders in the Pattern string
+ * to form a complete regular expression string. A full regular expression
+ * may be expressed using the RegularExpression attribute or
+ * as the body content of the <module> tag. The above pattern is equivalent
+ * to the following regular expression pattern.
+ *
+ * /articles\/(?P\d{4})\/(?P\d{2})\/(?P\d+)/u
+ *
+ * The above regular expression used the "named group" feature available in PHP.
+ * Notice that you need to escape the slash in regular expressions.
*
* In the TUrlMappingPattern class, the pattern is matched against the
* path property of the url only.
@@ -281,20 +292,20 @@ class TUrlMappingPattern extends TComponent
{
$body = trim($config->getValue());
if(strlen($body)>0)
- $this->setPattern($body);
+ $this->setRegularExpression($body);
if(is_null($this->_serviceParameter))
{
throw new TConfigurationException(
'dispatcher_url_service_parameter_missing', $this->getPattern());
}
- $this->initializePattern();
}
/**
* Subsitutue the parameter key value pairs as named groupings
* in the regular expression matching pattern.
+ * @return string regular expression pattern with parameter subsitution
*/
- protected function initializePattern()
+ protected function getParameterizedPattern()
{
$params= array();
$values = array();
@@ -303,17 +314,29 @@ class TUrlMappingPattern extends TComponent
$params[] = '{'.$key.'}';
$values[] = '(?P<'.$key.'>'.$value.')';
}
- $this->_regexp = str_replace($params,$values,$this->getPattern());
+ $params[] = '/';
+ $values[] = '\\/';
+ $regexp = str_replace($params,$values,$this->getPattern());
+ $modifiers = $this->getModifiers();
+ return '/'.$regexp.'/'.$modifiers;
}
/**
- * @return string mapping pattern
+ * @return string full regular expression mapping pattern
*/
- protected function getRegExpPattern()
+ public function getRegularExpression()
{
return $this->_regexp;
}
+ /**
+ * @param string full regular expression mapping patern.
+ */
+ public function setRegularExpression($value)
+ {
+ $this->_regexp;
+ }
+
/**
* @param string service parameter, such as page class name.
*/
@@ -395,7 +418,8 @@ class TUrlMappingPattern extends TComponent
}
/**
- * Use regular expression to match the given url path.
+ * Uses URL pattern (or full regular expression if available) to
+ * match the given url path.
* @param TUri url to match against
* @return array matched parameters, empty if no matches.
*/
@@ -403,9 +427,10 @@ class TUrlMappingPattern extends TComponent
{
$path = $url->getPath();
$matches=array();
- $pattern = str_replace('/', '\\/', $this->getRegExpPattern());
- $modifiers = $this->getModifiers();
- preg_match('/'.$pattern.'/'.$modifiers, $path, $matches);
+ $pattern = $this->getRegularExpression();
+ if($pattern === null)
+ $pattern = $this->getParameterizedPattern();
+ preg_match($pattern, $path, $matches);
return $matches;
}
--
cgit v1.2.3