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