1 |
joko |
1.1 |
<? |
2 |
joko |
1.3 |
/** |
3 |
|
|
* This file contains the Application::AbstractRequest class. |
4 |
|
|
* |
5 |
|
|
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
|
|
* @package org.netfrag.glib |
7 |
|
|
* @name Application::AbstractRequest |
8 |
|
|
* |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
|
12 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
13 |
joko |
1.3 |
// $Id: AbstractRequest.php,v 1.2 2003/02/09 17:02:30 joko Exp $ |
14 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
15 |
joko |
1.2 |
// $Log: AbstractRequest.php,v $ |
16 |
joko |
1.3 |
// Revision 1.2 2003/02/09 17:02:30 joko |
17 |
|
|
// + minor update related to new log level constants |
18 |
|
|
// |
19 |
joko |
1.2 |
// Revision 1.1 2003/02/04 08:24:37 joko |
20 |
|
|
// + initial commit |
21 |
|
|
// + refactored from flib/Site/Request.php and flib/Site/Handler.php |
22 |
|
|
// |
23 |
joko |
1.1 |
// Revision 1.5 2002/12/19 16:24:52 joko |
24 |
|
|
// + debugging |
25 |
|
|
// |
26 |
|
|
// Revision 1.4 2002/12/13 09:18:48 joko |
27 |
|
|
// + new mechanisms for handling the request: split up into _read and _parse |
28 |
|
|
// + introduced caching-mechanism |
29 |
|
|
// + fixed overriding-mechanism |
30 |
|
|
// |
31 |
|
|
// Revision 1.3 2002/12/13 00:22:27 jonen |
32 |
|
|
// - removed $site_state vars at cachedRequest |
33 |
|
|
// changes related to new Session class |
34 |
|
|
// |
35 |
|
|
// Revision 1.2 2002/12/12 21:39:24 joko |
36 |
|
|
// + fix to 'cacheThisRequest' - now uses the current one to cache if none is passed |
37 |
|
|
// |
38 |
|
|
// Revision 1.1 2002/11/12 05:42:31 joko |
39 |
|
|
// + initial checkin |
40 |
|
|
// |
41 |
|
|
// ------------------------------------------------------------------------- |
42 |
|
|
|
43 |
|
|
|
44 |
joko |
1.3 |
/** |
45 |
|
|
* --- Application::AbstractRequest class. |
46 |
|
|
* |
47 |
|
|
* @author Andreas Motl <andreas.motl@ilo.de> |
48 |
|
|
* @package org.netfrag.glib |
49 |
|
|
* @subpackage Application |
50 |
|
|
* @name Application::AbstractRequest |
51 |
|
|
* |
52 |
|
|
*/ |
53 |
joko |
1.1 |
class Application_AbstractRequest { |
54 |
|
|
|
55 |
|
|
// parent's instance |
56 |
|
|
var $parent; |
57 |
|
|
|
58 |
|
|
// to keep some status-information for reading/parsing |
59 |
|
|
var $meta; |
60 |
|
|
|
61 |
|
|
// to keep some lowlevel-information about the request |
62 |
|
|
var $raw; |
63 |
|
|
|
64 |
|
|
// the read and parsed request - ready for further processing with the Request - object |
65 |
|
|
var $request; |
66 |
|
|
|
67 |
|
|
function getRequest() { |
68 |
|
|
$parent = $this->parent; |
69 |
joko |
1.2 |
$this->$parent->log( get_class($this) . "->getRequest()", PEAR_LOG_DEBUG ); |
70 |
joko |
1.1 |
$this->_init(); |
71 |
joko |
1.2 |
//print Dumper($this->request); |
72 |
|
|
//exit; |
73 |
joko |
1.1 |
return $this->request; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
function _init() { |
77 |
|
|
if (!$this->meta[read]) { |
78 |
|
|
$this->_read(); |
79 |
|
|
} |
80 |
|
|
if (!$this->meta[parse]) { |
81 |
|
|
$this->_parse(); |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
function _read() { |
87 |
|
|
|
88 |
joko |
1.2 |
$this->meta[read] = 1; |
89 |
|
|
|
90 |
joko |
1.1 |
$parent = $this->parent; |
91 |
|
|
|
92 |
joko |
1.2 |
$this->$parent->log( get_class($this) . "->_read begin", PEAR_LOG_DEBUG ); |
93 |
|
|
|
94 |
joko |
1.1 |
// shift external arguments from url |
95 |
|
|
$identifier = $_GET[x]; |
96 |
|
|
$externalpage = $_GET[p]; |
97 |
|
|
// fallback to post |
98 |
|
|
if (!$identifier) { $identifier = $_POST[x]; } |
99 |
|
|
|
100 |
joko |
1.2 |
$this->$parent->log( get_class($this) . "->_read( identifier $identifier )", PEAR_LOG_DEBUG ); |
101 |
joko |
1.1 |
|
102 |
|
|
// remember raw arguments in object |
103 |
|
|
$this->raw[identifier] = $identifier; |
104 |
|
|
$this->raw[externalpage] = $externalpage; |
105 |
|
|
// TODO: url |
106 |
|
|
|
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
function _parse() { |
111 |
|
|
|
112 |
joko |
1.2 |
$this->meta[parse] = 1; |
113 |
|
|
|
114 |
joko |
1.1 |
$parent = $this->parent; |
115 |
|
|
|
116 |
joko |
1.2 |
$this->$parent->log( get_class($this) . "->_parse begin", PEAR_LOG_DEBUG ); |
117 |
|
|
|
118 |
joko |
1.1 |
// generic identifier |
119 |
|
|
$ident = $this->$parent->decodeIdentifier($this->raw[identifier]); |
120 |
|
|
|
121 |
|
|
// get handler for identifier |
122 |
joko |
1.2 |
$this->$parent->log( get_class($this) . "->_parse: getHandler( identifier $ident )", PEAR_LOG_DEBUG ); |
123 |
joko |
1.1 |
//$handler = $this->getHandler($ident); |
124 |
|
|
$handler = $this->$parent->getHandler($ident); |
125 |
|
|
|
126 |
|
|
// trace |
127 |
|
|
//print "handler:<br>" . Dumper($handler) . "<br>"; |
128 |
|
|
|
129 |
|
|
// modify handlername |
130 |
|
|
$handler[name] = $ident; |
131 |
|
|
|
132 |
|
|
// parse action from identifier |
133 |
|
|
if ($ident && substr($ident, -1) != '/') { |
134 |
|
|
$action = substr($ident, strrpos($ident, '/') + 1); |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
// this is the internal (metadata-)structure of the request-object |
138 |
|
|
$result = array( |
139 |
|
|
'raw' => $this->raw, |
140 |
|
|
'ident' => $ident, |
141 |
|
|
'handler' => $handler, |
142 |
|
|
'action' => $action, |
143 |
|
|
); |
144 |
|
|
|
145 |
|
|
$this->request = $result; |
146 |
|
|
|
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
function getCached() { |
150 |
|
|
$parent = $this->parent; |
151 |
|
|
return $this->$parent->session->get('cachedRequest'); |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
function cacheRequest($request = array()) { |
155 |
|
|
$parent = $this->parent; |
156 |
|
|
if (!count($request)) { |
157 |
|
|
$request = $this->getRequest(); |
158 |
|
|
} |
159 |
|
|
//print Dumper($request); |
160 |
|
|
$this->$parent->session->set('cachedRequest', $request); |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
function overrideRequestIdentifier($ident) { |
164 |
|
|
$this->overrideIdentifier($ident); |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
function overrideIdentifier($ident) { |
168 |
|
|
$parent = $this->parent; |
169 |
|
|
$ident_encoded = $this->$parent->encodeIdentifier($ident); |
170 |
|
|
$this->raw[identifier] = $ident_encoded; |
171 |
|
|
$this->meta[parse] = 0; |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
function getIdentifier() { |
175 |
|
|
$this->_init(); |
176 |
|
|
return $this->request[ident]; |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
function isPage() { |
180 |
|
|
$this->_init(); |
181 |
|
|
return $this->request[handler][isPage]; |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
?> |