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