summaryrefslogtreecommitdiff
path: root/framework/Web/TUrlMapping.php
diff options
context:
space:
mode:
authorgodzilla80@gmx.net <>2010-05-18 08:15:21 +0000
committergodzilla80@gmx.net <>2010-05-18 08:15:21 +0000
commita121c33a35e2f729d6f7633515ea78073f381039 (patch)
tree8b40ac56781acc24d3af928c071d3fa139aeb72b /framework/Web/TUrlMapping.php
parenteaf5175de51166bfc8e192ade2cb26548c056e7c (diff)
Add property SecureConnection to TUrlMappingPattern and related enum TUrlMappingPatternSecureConnection to make it possible to to define wether to use http or https on pattern level
Diffstat (limited to 'framework/Web/TUrlMapping.php')
-rw-r--r--framework/Web/TUrlMapping.php138
1 files changed, 122 insertions, 16 deletions
diff --git a/framework/Web/TUrlMapping.php b/framework/Web/TUrlMapping.php
index be3545c7..80cb6be8 100644
--- a/framework/Web/TUrlMapping.php
+++ b/framework/Web/TUrlMapping.php
@@ -1,6 +1,6 @@
<?php
/**
- * TUrlMapping and TUrlMappingPattern class file.
+ * TUrlMapping, TUrlMappingPattern and TUrlMappingPatternSecureConnection class file.
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @link http://www.pradosoft.com/
@@ -254,7 +254,7 @@ class TUrlMapping extends TUrlManager
}
}
}
-
+
private function buildUrlMapping($class, $pattern, $properties, $url)
{
$pattern=Prado::createComponent($class,$this);
@@ -337,7 +337,7 @@ class TUrlMapping extends TUrlManager
if($rule->supportCustomUrl($getItems))
return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems);
}
- }
+ }
elseif(isset($this->_constructRules[$wildCardKey]))
{
foreach($this->_constructRules[$wildCardKey] as $rule)
@@ -409,7 +409,7 @@ class TUrlMapping extends TUrlManager
* (the default ID is 'page') set the service parameter and service id respectively.
*
* Since 3.1.4 you can also use simplyfied wildcard patterns to match multiple
- * ServiceParameters with a single rule. The pattern must contain the placeholder
+ * ServiceParameters with a single rule. The pattern must contain the placeholder
* {*} for the ServiceParameter. For example
*
* <url ServiceParameter="adminpages.*" pattern="admin/{*}" />
@@ -417,24 +417,24 @@ class TUrlMapping extends TUrlManager
* This rule will match an URL like <tt>http://example.com/index.php/admin/edituser</tt>
* and resolve it to the page Application.pages.admin.edituser. The wildcard matching
* is non-recursive. That means you have to add a rule for every subdirectory you
- * want to access pages in:
+ * want to access pages in:
*
* <url ServiceParameter="adminpages.users.*" pattern="useradmin/{*}" />
*
* It is still possible to define an explicit rule for a page in the wildcard path.
* This rule has to preceed the wildcard rule.
*
- * You can also use parameters with wildcard patterns. The parameters are then
+ * You can also use parameters with wildcard patterns. The parameters are then
* available with every matching page:
*
* <url ServiceParameter="adminpages.*" pattern="admin/{*}/{id}" parameters.id="\d+" />
*
- * To enable automatic parameter encoding in a path format fro wildcard patterns you can set
- * {@setUrlFormat UrlFormat} to 'Path':
+ * To enable automatic parameter encoding in a path format fro wildcard patterns you can set
+ * {@setUrlFormat UrlFormat} to 'Path':
*
* <url ServiceParameter="adminpages.*" pattern="admin/{*}" UrlFormat="Path" />
*
- * This will create and parse URLs of the form
+ * This will create and parse URLs of the form
* <tt>.../index.php/admin/listuser/param1/value1/param2/value2</tt>.
*
* Use {@setUrlParamSeparator} to define another separator character between parameter
@@ -485,6 +485,12 @@ class TUrlMappingPattern extends TComponent
private $_separator='/';
/**
+ * @var TUrlMappingPatternSecureConnection
+ * @since 3.2
+ */
+ private $_secureConnection = TUrlMappingPatternSecureConnection::Automatic;
+
+ /**
* Constructor.
* @param TUrlManager the URL manager instance
*/
@@ -513,7 +519,7 @@ class TUrlMappingPattern extends TComponent
{
if($this->_serviceParameter===null)
throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern());
- if(strpos($this->_serviceParameter,'*')!==false)
+ if(strpos($this->_serviceParameter,'*')!==false)
$this->_isWildCardPattern=true;
}
@@ -541,7 +547,7 @@ class TUrlMappingPattern extends TComponent
$regexp=str_replace($params,$values,trim($this->getPattern(),'/').'/');
if ($this->_urlFormat===THttpRequestUrlFormat::Get)
$regexp='/^'.$regexp.'$/u';
- else
+ else
$regexp='/^'.$regexp.'(?P<urlparams>.*)$/u';
if(!$this->getCaseSensitive())
@@ -665,12 +671,12 @@ class TUrlMappingPattern extends TComponent
if (isset($matches['urlparams']))
{
$params=explode('/',$matches['urlparams']);
- if ($this->_separator==='/')
+ if ($this->_separator==='/')
{
while($key=array_shift($params))
$matches2[$key]=($value=array_shift($params)) ? $value : '';
- }
- else
+ }
+ else
{
array_pop($params);
foreach($params as $param)
@@ -724,7 +730,7 @@ class TUrlMappingPattern extends TComponent
* Sets the format of URLs constructed and interpreted by this pattern.
* A Get URL format is like index.php?name1=value1&name2=value2
* while a Path URL format is like index.php/name1/value1/name2/value.
- * The separating character between name and value can be configured with
+ * The separating character between name and value can be configured with
* {@link setUrlParamSeparator} and defaults to '/'.
* Changing the UrlFormat will affect {@link constructUrl} and how GET variables
* are parsed.
@@ -757,6 +763,24 @@ class TUrlMappingPattern extends TComponent
}
/**
+ * @return TUrlMappingPatternSecureConnection the SecureConnection behavior. Defaults to {@link TUrlMappingPatternSecureConnection::Automatic Automatic}
+ * @since 3.2
+ */
+ public function getSecureConnection()
+ {
+ return $this->_secureConnection;
+ }
+
+ /**
+ * @param TUrlMappingPatternSecureConnection the SecureConnection behavior.
+ * @since 3.2
+ */
+ public function setSecureConnection($value)
+ {
+ $this->_secureConnection = TPropertyValue::ensureEnum($value, 'TUrlMappingPatternSecureConnection');
+ }
+
+ /**
* @param array list of GET items to be put in the constructed URL
* @return boolean whether this pattern IS the one for constructing the URL with the specified GET items.
* @since 3.1.1
@@ -836,7 +860,89 @@ class TUrlMappingPattern extends TComponent
}
$url=$url.'?'.substr($url2,strlen($amp));
}
- return $url;
+ return $this -> applySecureConnectionPrefix($url);
+ }
+
+ /**
+ * Apply behavior of {@link SecureConnection} property by conditionaly prefixing
+ * URL with {@link THttpRequest::getBaseUrl()}
+ *
+ * @param string $url
+ * @return string
+ * @since 3.2
+ */
+ protected function applySecureConnectionPrefix($url)
+ {
+ static $request;
+ if($request === null) $request = Prado::getApplication() -> getRequest();
+
+ static $isSecureConnection;
+ if($isSecureConnection === null) $isSecureConnection = $request -> getIsSecureConnection();
+
+ switch($this -> getSecureConnection())
+ {
+ case TUrlMappingPatternSecureConnection::EnableIfNotSecure:
+ if($isSecureConnection) return $url;
+ return $request -> getBaseUrl(true) . $url;
+ break;
+ case TUrlMappingPatternSecureConnection::DisableIfSecure:
+ if(!$isSecureConnection) return $url;
+ return $request -> getBaseUrl(false) . $url;
+ break;
+ case TUrlMappingPatternSecureConnection::Enable:
+ return $request -> getBaseUrl(true) . $url;
+ break;
+ case TUrlMappingPatternSecureConnection::Disable:
+ return $request -> getBaseUrl(false) . $url;
+ break;
+ case TUrlMappingPatternSecureConnection::Automatic:
+ default:
+ return $url;
+ break;
+ }
}
}
+/**
+ * TUrlMappingPatternSecureConnection class
+ *
+ * TUrlMappingPatternSecureConnection defines the enumerable type for the possible SecureConnection
+ * URL prefix behavior that can be used by {@link TUrlMappingPattern::constructUrl()}.
+ *
+ * @author Yves Berkholz <godzilla80[at]gmx[dot]net>
+ * @version $Id$
+ * @package System.Web
+ * @since 3.2
+ */
+class TUrlMappingPatternSecureConnection extends TEnumerable
+{
+ /**
+ * Keep current SecureConnection status
+ * means no prefixing
+ */
+ const Automatic = 'Automatic';
+
+ /**
+ * Force use secured connection
+ * always prefixing with https://example.com/path/to/app
+ */
+ const Enable = 'Enable';
+
+ /**
+ * Force use unsecured connection
+ * always prefixing with http://example.com/path/to/app
+ */
+ const Disable = 'Disable';
+
+ /**
+ * Force use secured connection, if in unsecured mode
+ * prefixing with https://example.com/path/to/app
+ */
+ const EnableIfNotSecure = 'EnableIfNotSecure';
+
+ /**
+ * Force use unsecured connection, if in secured mode
+ * prefixing with https://example.com/path/to/app
+ */
+ const DisableIfSecure = 'DisableIfSecure';
+}