| 11 | * $Id$ | * $Id$ | 
| 12 | * | * | 
| 13 | * $Log$ | * $Log$ | 
| 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 | * Revision 1.1  2003/03/01 15:31:18  joko | 
| 23 | * + initial commit | * + initial commit | 
| 24 | * | * | 
| 27 |  |  | 
| 28 |  |  | 
| 29 | /** | /** | 
| 30 | * This tries to implement some parts of the MVC Model. | * This tries to abstract some parts of the MVC Pattern. | 
| 31 | * | * | 
| 32 | * | * | 
| 33 | * @author Andreas Motl <andreas.motl@ilo.de> | * @author Andreas Motl <andreas.motl@ilo.de> | 
| 56 | //loadModule('DesignPattern::Object'); | //loadModule('DesignPattern::Object'); | 
| 57 | //class DesignPattern_MVC extends DesignPattern_Object { | //class DesignPattern_MVC extends DesignPattern_Object { | 
| 58 |  |  | 
| 59 | class DesignPattern_MVC { | loadModule('DesignPattern::Container'); | 
| 60 |  | class DesignPattern_MVC extends DesignPattern_Container { | 
| 61 |  |  | 
| 62 | var $_model = NULL; | var $_model = array(); | 
| 63 | var $_view = NULL; | var $_view = array(); | 
| 64 | var $_controller = NULL; | var $_controller = array(); | 
| 65 |  |  | 
| 66 |  | var $_performed_result = null; | 
| 67 |  |  | 
| 68 |  |  | 
| 69 | /** | /** | 
| 76 | } | } | 
| 77 |  |  | 
| 78 | function _abstract_method($method) { | function _abstract_method($method) { | 
| 79 | print "Please implement code inside '$method'.<br/>"; | $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() { | function add_model() { | 
| 126 | $this->_abstract_method('add_model'); | $args = &func_get_args(); | 
| 127 |  | $this->__push('model', &$args[0]); | 
| 128 | } | } | 
| 129 |  |  | 
| 130 | function add_view() { | function add_view() { | 
| 131 | $this->_abstract_method('add_view'); | $args = &func_get_args(); | 
| 132 |  | $this->__push('view', &$args[0]); | 
| 133 | } | } | 
| 134 |  |  | 
| 135 | function add_controller() { | function add_controller() { | 
| 136 | $this->_abstract_method('add_controller'); | $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 |  |  | 
|  | function setup_views() { |  | 
|  | $this->_abstract_method('setup_views'); |  | 
|  | } |  | 
|  |  |  | 
| 154 | } | } | 
| 155 |  |  | 
| 156 | ?> | ?> |