1 |
<?php |
2 |
|
3 |
/** |
4 |
* This file contains the concrete Application::Request::Http Controller class. |
5 |
* |
6 |
* @author Andreas Motl <andreas.motl@ilo.de> |
7 |
* @package org.netfrag.glib |
8 |
* @module Application::Request::HttpController |
9 |
* |
10 |
*/ |
11 |
|
12 |
/** |
13 |
* $Id: MVC.php,v 1.2 2003/03/01 16:53:57 joko Exp $ |
14 |
* |
15 |
* $Log: MVC.php,v $ |
16 |
* |
17 |
*/ |
18 |
|
19 |
|
20 |
/** |
21 |
* --- |
22 |
* |
23 |
* |
24 |
* @author Andreas Motl <andreas.motl@ilo.de> |
25 |
* @copyright (c) 2003 - All Rights reserved. |
26 |
* @license GNU LGPL (GNU Lesser General Public License) |
27 |
* |
28 |
* @author-url http://www.netfrag.org/~joko/ |
29 |
* @license-url http://www.gnu.org/licenses/lgpl.txt |
30 |
* |
31 |
* @package org.netfrag.glib |
32 |
* @module Application::Request::HttpController |
33 |
* |
34 |
*/ |
35 |
|
36 |
/** |
37 |
* Todo: |
38 |
* |
39 |
* o xyz |
40 |
* o bla, bli, blub |
41 |
* |
42 |
* |
43 |
*/ |
44 |
|
45 |
|
46 |
loadModule('Application::Request::BaseController'); |
47 |
class Application_Request_HttpController extends Application_Request_BaseController { |
48 |
|
49 |
/** |
50 |
* The constructor ... |
51 |
* ... just does nothing. |
52 |
* |
53 |
* @param registry |
54 |
*/ |
55 |
function Application_Request_HttpController(&$request) { |
56 |
//print Dumper($request); |
57 |
//exit; |
58 |
// propagate request data |
59 |
$this->set_request($request); |
60 |
} |
61 |
|
62 |
function get_request() { |
63 |
return array_join_merge($_GET, $_POST); |
64 |
} |
65 |
|
66 |
function perform(&$metadata) { |
67 |
|
68 |
//print "model: " . Dumper($metadata); |
69 |
//print "request: " . Dumper($this->get_request()); |
70 |
$request_raw = $this->get_request(); |
71 |
|
72 |
// 1. map it! mungle request and model together - generic processing here! |
73 |
$request_mapped = array(); |
74 |
|
75 |
// check all areas |
76 |
foreach ($metadata[areas] as $area_name) { |
77 |
$area_metadata = $metadata[area][$area_name]; |
78 |
$http_arg_key = $area_metadata[query_arg]; |
79 |
if (in_array($http_arg_key, array_keys($request_raw))) { |
80 |
$request_mapped[$area_name] = $request_raw[$http_arg_key]; |
81 |
} |
82 |
} |
83 |
|
84 |
// trace |
85 |
//print Dumper($request_mapped); |
86 |
//exit; |
87 |
|
88 |
/* |
89 |
|
90 |
// set default identifier if still empty |
91 |
if ($page_ident = $this->request['ap']) { |
92 |
$this->_pageIdent = $page_ident; |
93 |
|
94 |
} elseif ($topic_ident = $this->request['t']) { |
95 |
$this->_topicIdent = $topic_ident; |
96 |
|
97 |
} else { |
98 |
$this->_pageIdent = 'overview'; |
99 |
$this->_topicIdent = ''; |
100 |
} |
101 |
|
102 |
//print "ident: " . $this->_pageIdent . "<br>"; |
103 |
|
104 |
*/ |
105 |
|
106 |
// 2. rule it! mungle request through dispatching rules - lambda-style callbacks |
107 |
$results = array(); |
108 |
foreach ($this->_rules as $rule) { |
109 |
//$in = array(); |
110 |
$in = $request_mapped; |
111 |
$out = array(); |
112 |
call_user_func($rule, &$in, &$out); |
113 |
array_push($results, array( in => $in, out => $out)); |
114 |
} |
115 |
|
116 |
// trace |
117 |
//print Dumper($results); |
118 |
//exit; |
119 |
|
120 |
// 3. merge it! merge dispatching output ($_out!) |
121 |
$final = array(); |
122 |
foreach ($results as $result) { |
123 |
//print Dumper($result[out]); |
124 |
$final = array_join_merge($final, $result[out]); |
125 |
} |
126 |
|
127 |
// trace |
128 |
//print Dumper($final); |
129 |
//exit; |
130 |
|
131 |
return $final; |
132 |
|
133 |
} |
134 |
|
135 |
|
136 |
|
137 |
} |
138 |
|
139 |
?> |