1 |
joko |
1.1 |
<?php |
2 |
|
|
/** |
3 |
joko |
1.8 |
* This file contains the DesignPattern::MVC class |
4 |
joko |
1.1 |
* |
5 |
joko |
1.7 |
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
joko |
1.6 |
* @package org.netfrag.glib |
7 |
|
|
* @name DesignPattern::MVC |
8 |
joko |
1.9 |
* |
9 |
|
|
* |
10 |
|
|
* |
11 |
|
|
* <b>Cvs-Log:</b> |
12 |
joko |
1.5 |
* |
13 |
joko |
1.9 |
* <pre> |
14 |
joko |
1.11 |
* $Id: MVC.php,v 1.10 2003/03/05 17:02:22 joko Exp $ |
15 |
joko |
1.2 |
* |
16 |
|
|
* $Log: MVC.php,v $ |
17 |
joko |
1.11 |
* Revision 1.10 2003/03/05 17:02:22 joko |
18 |
|
|
* updated docu (phpDocumentor testing....) |
19 |
|
|
* |
20 |
joko |
1.10 |
* Revision 1.9 2003/03/05 16:32:18 joko |
21 |
|
|
* updated docu (phpDocumentor testing....) |
22 |
|
|
* |
23 |
joko |
1.9 |
* Revision 1.8 2003/03/05 16:10:17 joko |
24 |
|
|
* updated docu (phpDocumentor testing....) |
25 |
|
|
* |
26 |
joko |
1.8 |
* Revision 1.7 2003/03/05 15:41:03 joko |
27 |
|
|
* updated docu (phpDocumentor testing....) |
28 |
|
|
* |
29 |
joko |
1.7 |
* Revision 1.6 2003/03/05 15:24:23 joko |
30 |
|
|
* updated docu (phpDocumentor testing....) |
31 |
|
|
* |
32 |
joko |
1.6 |
* Revision 1.5 2003/03/03 21:57:42 joko |
33 |
|
|
* changed base class |
34 |
|
|
* |
35 |
joko |
1.5 |
* Revision 1.4 2003/03/01 22:44:54 joko |
36 |
|
|
* setup_views not required? |
37 |
|
|
* |
38 |
joko |
1.4 |
* Revision 1.3 2003/03/01 21:13:00 joko |
39 |
|
|
* now actually doing something via '->perform' |
40 |
|
|
* |
41 |
joko |
1.3 |
* Revision 1.2 2003/03/01 16:53:57 joko |
42 |
joko |
1.5 |
* + now propagating/forwarding passed-in data to add_[model|view|controller] to base class method DesignPattern::Container::push_element to store it |
43 |
joko |
1.3 |
* is this a case for aspect-oriented-programming? |
44 |
|
|
* - removed calls to _abstract_method |
45 |
|
|
* |
46 |
joko |
1.2 |
* Revision 1.1 2003/03/01 15:31:18 joko |
47 |
|
|
* + initial commit |
48 |
joko |
1.9 |
* </pre> |
49 |
joko |
1.1 |
* |
50 |
|
|
* |
51 |
|
|
*/ |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
/** |
55 |
joko |
1.8 |
* This tries to abstract some parts of the MVC Pattern |
56 |
joko |
1.1 |
* |
57 |
|
|
* @author Andreas Motl <andreas.motl@ilo.de> |
58 |
joko |
1.6 |
* @link http://www.netfrag.org/~joko/ |
59 |
joko |
1.1 |
* @copyright (c) 2003 - All Rights reserved. |
60 |
|
|
* @license GNU LGPL (GNU Lesser General Public License) |
61 |
joko |
1.6 |
* @link http://www.gnu.org/licenses/lgpl.txt |
62 |
joko |
1.1 |
* |
63 |
|
|
* @package org.netfrag.glib |
64 |
joko |
1.10 |
* @subpackage DesignPattern |
65 |
joko |
1.6 |
* @name DesignPattern::MVC |
66 |
joko |
1.1 |
* |
67 |
joko |
1.9 |
* |
68 |
joko |
1.6 |
* @todo xyz |
69 |
|
|
* @todo bla, bli, blub |
70 |
joko |
1.1 |
* |
71 |
|
|
* |
72 |
|
|
*/ |
73 |
joko |
1.5 |
class DesignPattern_MVC extends DesignPattern_Facade { |
74 |
joko |
1.1 |
|
75 |
joko |
1.3 |
var $_model = array(); |
76 |
|
|
var $_view = array(); |
77 |
|
|
var $_controller = array(); |
78 |
|
|
|
79 |
|
|
var $_performed_result = null; |
80 |
joko |
1.1 |
|
81 |
|
|
|
82 |
|
|
/** |
83 |
|
|
* The constructor ... |
84 |
|
|
* ... just does nothing. |
85 |
|
|
* |
86 |
|
|
* @param registry |
87 |
|
|
*/ |
88 |
joko |
1.5 |
function constructor() { |
89 |
|
|
parent::constructor(); |
90 |
joko |
1.1 |
} |
91 |
|
|
|
92 |
|
|
function _abstract_method($method) { |
93 |
joko |
1.2 |
$package = get_class($this); |
94 |
joko |
1.3 |
$package_p = get_parent_class($this); |
95 |
|
|
print "DesignPattern::MVC.$package_p.$package: Please implement method '$method'.<br/>"; |
96 |
joko |
1.1 |
} |
97 |
joko |
1.2 |
|
98 |
joko |
1.3 |
// spool controller rules |
99 |
|
|
function &perform() { |
100 |
|
|
|
101 |
|
|
$this->_model_data = &$this->get_model_data(); |
102 |
|
|
$this->_controller_data = &$this->get_controller_data(); |
103 |
|
|
|
104 |
|
|
//print Dumper($this); |
105 |
|
|
//exit; |
106 |
|
|
|
107 |
|
|
// create instance of controller from module |
108 |
|
|
$this->_controller_instance = mkObject($this->_controller_data[module]); |
109 |
|
|
|
110 |
|
|
// trace |
111 |
|
|
//print Dumper($this); |
112 |
|
|
//print Dumper($this->_controller_data); |
113 |
|
|
//print Dumper($this->_controller_instance); |
114 |
|
|
//exit; |
115 |
|
|
|
116 |
|
|
//$this->perform_rules(); |
117 |
|
|
|
118 |
|
|
// new!!! request data is propagated here!!! |
119 |
|
|
// FIXME: '_raw[request]' - really? |
120 |
|
|
$this->_controller_instance->set_request(&$this->_raw[request]); |
121 |
|
|
|
122 |
|
|
$this->_controller_instance->set_rules($this->_controller_data[rules]); |
123 |
|
|
$this->_performed_result = $this->_controller_instance->perform($this->_model_data); |
124 |
|
|
|
125 |
|
|
// finally, re-integrate into main application flow |
126 |
|
|
return $this->handle(); |
127 |
|
|
|
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
// dispatch on controller state flags/variables |
131 |
|
|
function handle() { |
132 |
|
|
$this->_abstract_method('handle'); |
133 |
|
|
} |
134 |
joko |
1.2 |
|
135 |
joko |
1.3 |
function setup_views() { |
136 |
joko |
1.4 |
//$this->_abstract_method('setup_views'); |
137 |
joko |
1.3 |
} |
138 |
joko |
1.5 |
|
139 |
|
|
|
140 |
joko |
1.1 |
function add_model() { |
141 |
joko |
1.2 |
$args = &func_get_args(); |
142 |
joko |
1.5 |
$this->_container->push('model', &$args[0]); |
143 |
joko |
1.1 |
} |
144 |
|
|
|
145 |
|
|
function add_view() { |
146 |
joko |
1.2 |
$args = &func_get_args(); |
147 |
joko |
1.5 |
$this->_container->push('view', &$args[0]); |
148 |
joko |
1.1 |
} |
149 |
|
|
|
150 |
|
|
function add_controller() { |
151 |
joko |
1.2 |
$args = &func_get_args(); |
152 |
joko |
1.5 |
$this->_container->push('controller', &$args[0]); |
153 |
joko |
1.3 |
} |
154 |
|
|
|
155 |
|
|
function &get_model_data() { |
156 |
joko |
1.5 |
return $this->_container->last('model'); |
157 |
joko |
1.3 |
} |
158 |
|
|
|
159 |
|
|
function &get_view_data() { |
160 |
|
|
$args = &func_get_args(); |
161 |
|
|
$slot = $args[0]; |
162 |
joko |
1.5 |
return $this->_container->slot('view', $slot); |
163 |
joko |
1.3 |
} |
164 |
|
|
|
165 |
|
|
function &get_controller_data() { |
166 |
joko |
1.5 |
return $this->_container->last('controller'); |
167 |
joko |
1.1 |
} |
168 |
|
|
|
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
?> |