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