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