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