1 |
joko |
1.1 |
<?php |
2 |
|
|
|
3 |
|
|
/** |
4 |
|
|
* This file contains the abstract Application::Request::BaseController class. |
5 |
|
|
* |
6 |
|
|
* @author Andreas Motl <andreas.motl@ilo.de> |
7 |
|
|
* @package org.netfrag.glib |
8 |
joko |
1.3 |
* @name Application::Request::BaseController |
9 |
joko |
1.1 |
* |
10 |
|
|
*/ |
11 |
|
|
|
12 |
|
|
/** |
13 |
joko |
1.3 |
* $Id: BaseController.php,v 1.2 2003/03/03 21:12:55 joko Exp $ |
14 |
joko |
1.2 |
* |
15 |
|
|
* $Log: BaseController.php,v $ |
16 |
joko |
1.3 |
* Revision 1.2 2003/03/03 21:12:55 joko |
17 |
|
|
* split up processing into more steps |
18 |
|
|
* |
19 |
joko |
1.2 |
* Revision 1.1 2003/03/01 21:11:18 joko |
20 |
|
|
* + initial commit |
21 |
joko |
1.1 |
* |
22 |
|
|
* |
23 |
|
|
*/ |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/** |
27 |
joko |
1.3 |
* Application::Request::BaseController |
28 |
joko |
1.1 |
* |
29 |
|
|
* @author Andreas Motl <andreas.motl@ilo.de> |
30 |
|
|
* @copyright (c) 2003 - All Rights reserved. |
31 |
|
|
* @license GNU LGPL (GNU Lesser General Public License) |
32 |
|
|
* |
33 |
|
|
* @author-url http://www.netfrag.org/~joko/ |
34 |
|
|
* @license-url http://www.gnu.org/licenses/lgpl.txt |
35 |
|
|
* |
36 |
|
|
* @package org.netfrag.glib |
37 |
joko |
1.3 |
* @subpackage Application |
38 |
|
|
* @name Application::Request::BaseController |
39 |
joko |
1.1 |
* |
40 |
|
|
*/ |
41 |
|
|
class Application_Request_BaseController { |
42 |
|
|
|
43 |
|
|
var $_request = null; |
44 |
|
|
|
45 |
|
|
var $_rules = null; |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
/** |
49 |
|
|
* The constructor ... |
50 |
|
|
* ... just does nothing. |
51 |
|
|
* |
52 |
|
|
* @param registry |
53 |
|
|
*/ |
54 |
|
|
function Application_Request_BaseController() { |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
function _abstract_method($method) { |
58 |
|
|
$package = get_class($this); |
59 |
|
|
print "$package: Please implement method '$method'.<br/>"; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
/* |
63 |
|
|
function set_request() { |
64 |
|
|
$this->_abstract_method('set_request'); |
65 |
|
|
} |
66 |
|
|
*/ |
67 |
|
|
|
68 |
joko |
1.2 |
function get_request() { |
69 |
|
|
$this->_abstract_method('get_request'); |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
function get_request_translated() { |
73 |
|
|
$this->_abstract_method('get_request_translated'); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
/* |
77 |
|
|
function translate_request() { |
78 |
|
|
$this->_abstract_method('translate_request'); |
79 |
|
|
} |
80 |
|
|
*/ |
81 |
|
|
|
82 |
|
|
function translate_request($request_raw) { |
83 |
|
|
|
84 |
|
|
// 1. map it! mungle request and model together - generic processing here! |
85 |
|
|
// now: translate it! (done in concrete mvc controller now) |
86 |
|
|
|
87 |
|
|
$request_translated = array(); |
88 |
|
|
|
89 |
|
|
$metadata = $this->metadata; |
90 |
|
|
|
91 |
|
|
// check all areas |
92 |
|
|
foreach ($metadata[request_args] as $area_name) { |
93 |
|
|
$area_metadata = $metadata[request_arg][$area_name]; |
94 |
|
|
if ($http_arg_key = $area_metadata[query_arg]) { |
95 |
|
|
$this->translate_to($request_raw, $http_arg_key, $request_translated, $area_name); |
96 |
|
|
} |
97 |
|
|
if ($http_arg_keys = $area_metadata[query_args]) { |
98 |
|
|
foreach ($http_arg_keys as $key) { |
99 |
|
|
$this->translate_to($request_raw, $key, $request_translated, $area_name); |
100 |
|
|
} |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
if (!sizeof($request_translated)) { |
105 |
|
|
user_error("MVC Error - HttpController: mapped request is empty!"); |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
return $request_translated; |
109 |
|
|
|
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
function translate_to(&$source, $source_key, &$target, $target_key) { |
113 |
|
|
if (in_array($source_key, array_keys($source))) { |
114 |
|
|
$target[$target_key] = $source[$source_key]; |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
|
118 |
joko |
1.1 |
// called from parent context |
119 |
|
|
function set_request(&$request) { |
120 |
|
|
$this->_request = &$request; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
// called from DesignPattern::MVC |
124 |
|
|
function set_rules(&$rules) { |
125 |
|
|
$this->_rules = &$rules; |
126 |
|
|
} |
127 |
|
|
|
128 |
joko |
1.2 |
/* |
129 |
joko |
1.1 |
function &get_request() { |
130 |
|
|
return $this->_request; |
131 |
|
|
} |
132 |
joko |
1.2 |
*/ |
133 |
joko |
1.1 |
|
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
?> |