diff options
author | emkael <emkael@tlen.pl> | 2016-06-07 15:17:49 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-06-10 11:46:41 +0200 |
commit | 823d71ced9b4947b1a5a5ade7245d521ed490061 (patch) | |
tree | a9a6c7cb0de74ff705e8320c284de423a698f5b5 /app/frontend/url | |
parent | df401552aac363655ab8f056a6c910a7611954d6 (diff) |
* renaming php directory
Diffstat (limited to 'app/frontend/url')
-rw-r--r-- | app/frontend/url/UrlManager.php | 57 | ||||
-rw-r--r-- | app/frontend/url/config.xml | 44 |
2 files changed, 101 insertions, 0 deletions
diff --git a/app/frontend/url/UrlManager.php b/app/frontend/url/UrlManager.php new file mode 100644 index 0000000..a33d98e --- /dev/null +++ b/app/frontend/url/UrlManager.php @@ -0,0 +1,57 @@ +<?php + +Prado::using('System.Web.TUrlMapping'); + +class UrlManager extends TUrlMapping { + + public function constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems) { + $url = parent::constructUrl( + $serviceID, + $serviceParam, + $getItems, + $encodeAmpersand, + $encodeGetItems + ); + return rtrim( + preg_replace( + '#^/' . $serviceParam . '#', + '/' . $this->_convertServiceParam($serviceParam), + preg_replace('#^/' . $serviceID . '#', '', $url) + ), + '/' + ) . '/'; + } + + public function parseUrl() { + $params = parent::parseUrl(); + if ($this->MatchingPattern) { + $serviceID = $this->MatchingPattern->ServiceID; + if (isset($params[$serviceID])) { + $params[$serviceID] = $this->_parseServiceParam($params[$serviceID]); + } + } + return $params; + } + + /** + * Convert service param from camelCase to hyphenated-form. + **/ + private function _convertServiceParam($param) { + return implode( + '-', + array_map('mb_strtolower', array_filter(preg_split('/(?=[A-Z])/', $param))) + ); + } + + /** + * Convert service param from hyphenated-form to camelCase. + **/ + private function _parseServiceParam($param) { + return implode( + '', + array_map('ucfirst', explode('-', $param)) + ); + } +} + +?> diff --git a/app/frontend/url/config.xml b/app/frontend/url/config.xml new file mode 100644 index 0000000..b072b2d --- /dev/null +++ b/app/frontend/url/config.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <modules> + <module id="url" + class="Application.url.UrlManager" + UrlPrefix="/" + EnableCustomUrl="True"> + + <url ServiceParameter="Home" + UrlFormat="HiddenPath" + pattern="{month}/{year}/" + parameters.month="\d{2}" + parameters.year="\d{4}" /> + <url ServiceParameter="Home" + UrlFormat="HiddenPath" + pattern="{month}/" + parameters.month="\d{2}" /> + <url ServiceParameter="Home" + UrlFormat="HiddenPath" + EnableCustomUrl="false" + pattern="" /> + + <url ServiceParameter="Calendar" + UrlFormat="HiddenPath" + pattern="calendar/{calendar}/" + parameters.calendar=".*" /> + + <url ServiceParameter="*" + UrlFormat="HiddenPath" + EnableCustomUrl="false" + pattern="{*}" /> + </module> + + <module id="request" + class="THttpRequest" + UrlFormat="HiddenPath" + UrlParamSeparator="/" + UrlManager="url" /> + <module id="response" + class="THttpResponse" + CacheControl="public" + CacheExpire="10" /> + </modules> +</configuration> |