Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Request
- {
- var $path = '';
- var $queryString = '';
- var $params = array('module' => '', 'p' => '', 'page' => '');
- public function __construct()
- {
- $request_uri = $this->getUrl();
- $__tmpUri = parse_url($request_uri);
- $this->path = isset($__tmpUri['path']) ? $__tmpUri['path'] : '';
- $this->queryString = isset($__tmpUri['query']) ? $__tmpUri['query'] : '';
- }
- public function getParams()
- {
- if(!empty($this->queryString))
- {
- parse_str($this->queryString, $array2String);
- foreach ($array2String as $k=>$v)
- {
- $this->params[$k] = $v;
- }
- }
- if(!empty($this->path))
- {
- $request_params = explode("/", $this->path);
- }
- else
- {
- $request_params = array();
- }
- $cnt = 1;
- if(count($request_params))
- {
- foreach ($request_params as $k => $v)
- {
- if(!empty($v))
- {
- if(empty($this->params['module']))
- {
- if(is_numeric($v))
- {
- $this->params['page'] = $v;
- }
- else
- {
- $this->params['module'] = $v;
- }
- $cnt++;
- continue;
- }
- if(empty($this->params['p']))
- {
- if(is_numeric($v))
- {
- $this->params['page'] = $v;
- }
- else
- {
- $this->params['p'] = $v;
- }
- $cnt++;
- continue;
- }
- if($k == $cnt)
- {
- $this->params[$v] = $request_params[$k + 1];
- $cnt+=2;
- continue;
- }
- }
- }
- }
- return $this->params;
- }
- public function getParam($param, $defaultValue = null)
- {
- $this->getParams();
- if(isset($this->params[$param]))
- {
- return $this->params[$param];
- }
- else
- {
- return $defaultValue;
- }
- }
- protected function getUrl()
- {
- $request_uri = $_SERVER['REQUEST_URI'];
- if($request_uri{0} != '/')
- {
- $request_uri = "/".$request_uri;
- }
- return $request_uri;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment