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