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