summaryrefslogtreecommitdiff
path: root/app/php/url
diff options
context:
space:
mode:
Diffstat (limited to 'app/php/url')
-rw-r--r--app/php/url/UrlManager.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/php/url/UrlManager.php b/app/php/url/UrlManager.php
new file mode 100644
index 0000000..a33d98e
--- /dev/null
+++ b/app/php/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))
+ );
+ }
+}
+
+?>