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