| 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 |
* $Id: MVC.php,v 1.3 2003/03/01 21:13:00 joko Exp $ |
| 12 |
* |
| 13 |
* $Log: MVC.php,v $ |
| 14 |
* Revision 1.3 2003/03/01 21:13:00 joko |
| 15 |
* now actually doing something via '->perform' |
| 16 |
* |
| 17 |
* 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 |
* Revision 1.1 2003/03/01 15:31:18 joko |
| 23 |
* + initial commit |
| 24 |
* |
| 25 |
* |
| 26 |
*/ |
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* This tries to abstract some parts of the MVC Pattern. |
| 31 |
* |
| 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 |
loadModule('DesignPattern::Container'); |
| 60 |
class DesignPattern_MVC extends DesignPattern_Container { |
| 61 |
|
| 62 |
var $_model = array(); |
| 63 |
var $_view = array(); |
| 64 |
var $_controller = array(); |
| 65 |
|
| 66 |
var $_performed_result = null; |
| 67 |
|
| 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 |
$package = get_class($this); |
| 80 |
$package_p = get_parent_class($this); |
| 81 |
print "DesignPattern::MVC.$package_p.$package: Please implement method '$method'.<br/>"; |
| 82 |
} |
| 83 |
|
| 84 |
// 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 |
|
| 121 |
function setup_views() { |
| 122 |
//$this->_abstract_method('setup_views'); |
| 123 |
} |
| 124 |
|
| 125 |
function add_model() { |
| 126 |
$args = &func_get_args(); |
| 127 |
$this->__push('model', &$args[0]); |
| 128 |
} |
| 129 |
|
| 130 |
function add_view() { |
| 131 |
$args = &func_get_args(); |
| 132 |
$this->__push('view', &$args[0]); |
| 133 |
} |
| 134 |
|
| 135 |
function add_controller() { |
| 136 |
$args = &func_get_args(); |
| 137 |
$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 |
} |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
?> |