1: <?php
2:
3: /**
4: * Picon Framework
5: * http://code.google.com/p/picon-framework/
6: *
7: * Copyright (C) 2011-2012 Martin Cassidy <martin.cassidy@webquub.com>
8:
9: * Picon Framework is free software: you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation, either version 3 of the License, or
12: * (at your option) any later version.
13:
14: * Picon Framework is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: * General Public License for more details.
18:
19: * You should have received a copy of the GNU General Public License
20: * along with Picon Framework. If not, see <http://www.gnu.org/licenses/>.
21: * */
22:
23: namespace picon;
24:
25: /**
26: * Basic implementation of request
27: *
28: * @author Martin Cassidy
29: * @package web/request
30: */
31: class WebRequest implements Request
32: {
33: private $post;
34: private $get;
35:
36: public function __construct()
37: {
38: $this->post = isset($_POST)?$_POST:false;
39: $this->get = isset($_GET)?$_GET:false;
40: }
41:
42: public function getQueryString()
43: {
44: return $_SERVER['QUERY_STRING'];
45: }
46:
47: public function getPath()
48: {
49: return str_replace('?'.$this->getQueryString(), '', $_SERVER['REQUEST_URI']);
50: }
51:
52: public function isAjax()
53: {
54: return isset($_GET['ajax']);
55: }
56:
57: public function isResourceRequest()
58: {
59: return isset($_GET['picon-resource']);
60: }
61:
62: public function getRootPath()
63: {
64: $root = preg_replace("/\/{1}\w*\.php$/", "", $_SERVER['PHP_SELF']);
65: return $root;
66: }
67:
68: public function isPost()
69: {
70: return $_SERVER['REQUEST_METHOD']=='POST';
71: }
72:
73: public function isGet()
74: {
75: return $_SERVER['REQUEST_METHOD']=='GET';
76: }
77:
78: /**
79: * Get a POST parameter
80: * @param type $name
81: * @return type
82: */
83: public function getPostedParameter($name)
84: {
85: if($this->post==false)
86: {
87: return null;
88: }
89: if(array_key_exists($name, $this->post))
90: {
91: return $this->post[$name];
92: }
93: return null;
94: }
95:
96: /**
97: * Get a GET paramater
98: * @param type $name
99: * @return type
100: */
101: public function getParameter($name)
102: {
103: if($this->get==false)
104: {
105: return null;
106: }
107: if(array_key_exists($name, $this->get))
108: {
109: return $this->get[$name];
110: }
111: return null;
112: }
113:
114: public function getParameters()
115: {
116: return $this->get;
117: }
118:
119: public function getPostParameters()
120: {
121: return $this->post;
122: }
123: }
124:
125: ?>
126: