From d327af5f481454d8738ab413e2c16ad829bbf800 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 26 Feb 2016 17:13:13 +0100 Subject: * friendly URL support --- app/php/application.xml | 34 +++++++++++++++++++++++---- app/php/url/UrlManager.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 app/php/url/UrlManager.php (limited to 'app/php') diff --git a/app/php/application.xml b/app/php/application.xml index 4aa2f30..13a86e1 100644 --- a/app/php/application.xml +++ b/app/php/application.xml @@ -1,6 +1,7 @@ + @@ -9,9 +10,34 @@ EnableCache="true" /> - + + + + + + + + - + 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 @@ +_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)) + ); + } +} + +?> -- cgit v1.2.3