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