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