| 1 | <?php | <?php | 
|  |  |  | 
| 2 | /** | /** | 
| 3 | * This file contains the DesignPattern::MVC class. | * This file contains the DesignPattern::MVC class | 
| 4 | * | * | 
| 5 | * @author Andreas Motl <andreas.motl@ilo.de> | * @author Andreas Motl <andreas.motl@ilo.de> | 
| 6 | * @package org.netfrag.glib | * @package org.netfrag.glib | 
| 7 |  | * @name DesignPattern::MVC | 
| 8 |  | * | 
| 9 |  | * | 
| 10 | */ | */ | 
| 11 |  |  | 
| 12 | /** |  | 
| 13 |  | /** | 
| 14 |  | * | 
| 15 |  | * <b>Cvs-Log:</b> | 
| 16 |  | * | 
| 17 |  | * <pre> | 
| 18 | * $Id$ | * $Id$ | 
| 19 | * | * | 
| 20 | * $Log$ | * $Log$ | 
| 21 |  | * Revision 1.13  2003/04/04 17:37:05  joko | 
| 22 |  | * modifications regarding error-/exception-handling | 
| 23 |  | * | 
| 24 |  | * Revision 1.12  2003/03/10 23:30:27  joko | 
| 25 |  | * + fixed metadata for phpDocumentor | 
| 26 |  | * | 
| 27 |  | * Revision 1.11  2003/03/10 22:31:56  joko | 
| 28 |  | * + fixed metadata for phpDocumentor | 
| 29 |  | * | 
| 30 |  | * Revision 1.10  2003/03/05 17:02:22  joko | 
| 31 |  | * updated docu (phpDocumentor testing....) | 
| 32 |  | * | 
| 33 |  | * Revision 1.9  2003/03/05 16:32:18  joko | 
| 34 |  | * updated docu (phpDocumentor testing....) | 
| 35 |  | * | 
| 36 |  | * Revision 1.8  2003/03/05 16:10:17  joko | 
| 37 |  | * updated docu (phpDocumentor testing....) | 
| 38 |  | * | 
| 39 |  | * Revision 1.7  2003/03/05 15:41:03  joko | 
| 40 |  | * updated docu (phpDocumentor testing....) | 
| 41 |  | * | 
| 42 |  | * Revision 1.6  2003/03/05 15:24:23  joko | 
| 43 |  | * updated docu (phpDocumentor testing....) | 
| 44 |  | * | 
| 45 |  | * Revision 1.5  2003/03/03 21:57:42  joko | 
| 46 |  | * changed base class | 
| 47 |  | * | 
| 48 |  | * Revision 1.4  2003/03/01 22:44:54  joko | 
| 49 |  | * setup_views not required? | 
| 50 |  | * | 
| 51 | * Revision 1.3  2003/03/01 21:13:00  joko | * Revision 1.3  2003/03/01 21:13:00  joko | 
| 52 | * now actually doing something via '->perform' | * now actually doing something via '->perform' | 
| 53 | * | * | 
| 54 | * Revision 1.2  2003/03/01 16:53:57  joko | * Revision 1.2  2003/03/01 16:53:57  joko | 
| 55 | * + now propagating/forwarding passed-in data to add_[model|view|controller] to base class method DesignPattern::Container::__push_element to store it | * + now propagating/forwarding passed-in data to add_[model|view|controller] to base class method DesignPattern::Container::push_element to store it | 
| 56 | *    is this a case for aspect-oriented-programming? | *    is this a case for aspect-oriented-programming? | 
| 57 | * - removed calls to _abstract_method | * - removed calls to _abstract_method | 
| 58 | * | * | 
| 59 | * Revision 1.1  2003/03/01 15:31:18  joko | * Revision 1.1  2003/03/01 15:31:18  joko | 
| 60 | * + initial commit | * + initial commit | 
| 61 |  | * </pre> | 
| 62 | * | * | 
| 63 | * | * | 
| 64 | */ | */ | 
| 65 |  |  | 
| 66 |  |  | 
| 67 | /** | /** | 
| 68 | * This tries to abstract some parts of the MVC Pattern. | * This tries to abstract some parts of the MVC Pattern | 
|  | * |  | 
| 69 | * | * | 
| 70 | * @author Andreas Motl <andreas.motl@ilo.de> | * @author Andreas Motl <andreas.motl@ilo.de> | 
| 71 |  | * @link http://www.netfrag.org/~joko/ | 
| 72 | * @copyright (c) 2003 - All Rights reserved. | * @copyright (c) 2003 - All Rights reserved. | 
| 73 | * @license GNU LGPL (GNU Lesser General Public License) | * @license GNU LGPL (GNU Lesser General Public License) | 
| 74 | * | * @link http://www.gnu.org/licenses/lgpl.txt | 
|  | * @author-url http://www.netfrag.org/~joko/ |  | 
|  | * @license-url http://www.gnu.org/licenses/lgpl.txt |  | 
| 75 | * | * | 
| 76 | * @package org.netfrag.glib | * @package org.netfrag.glib | 
| 77 | * @module Application::ComponentRegistry | * @subpackage DesignPattern | 
| 78 |  | * @name DesignPattern::MVC | 
| 79 | * | * | 
|  | */ |  | 
|  |  |  | 
|  | /** |  | 
|  | * Todo: |  | 
| 80 | * | * | 
| 81 | *  o xyz | * @todo xyz | 
| 82 | *  o bla, bli, blub | * @todo bla, bli, blub | 
| 83 | * | * | 
| 84 | * | * | 
| 85 | */ | */ | 
| 86 |  | class DesignPattern_MVC extends DesignPattern_Facade { | 
|  |  |  | 
|  | // isn't required by now: |  | 
|  | //loadModule('DesignPattern::Object'); |  | 
|  | //class DesignPattern_MVC extends DesignPattern_Object { |  | 
|  |  |  | 
|  | loadModule('DesignPattern::Container'); |  | 
|  | class DesignPattern_MVC extends DesignPattern_Container { |  | 
| 87 |  |  | 
| 88 | var $_model = array(); | var $_model = array(); | 
| 89 | var $_view = array(); | var $_view = array(); | 
| 98 | * | * | 
| 99 | * @param registry | * @param registry | 
| 100 | */ | */ | 
| 101 | function DesignPattern_MVC() { | function constructor() { | 
| 102 |  | set_error_handler('php_error_handler'); | 
| 103 |  | parent::constructor(); | 
| 104 | } | } | 
| 105 |  |  | 
| 106 | function _abstract_method($method) { | function _abstract_method($method) { | 
| 107 | $package = get_class($this); | $package = get_class($this); | 
| 108 | $package_p = get_parent_class($this); | $package_p = get_parent_class($this); | 
| 109 | print "DesignPattern::MVC.$package_p.$package: Please implement method '$method'.<br/>"; | user_error( "DesignPattern::MVC.$package_p.$package: Please implement method '$method'." ); | 
| 110 | } | } | 
| 111 |  |  | 
| 112 | // spool controller rules | // spool controller rules | 
| 147 | } | } | 
| 148 |  |  | 
| 149 | function setup_views() { | function setup_views() { | 
| 150 | $this->_abstract_method('setup_views'); | //$this->_abstract_method('setup_views'); | 
| 151 | } | } | 
| 152 |  |  | 
| 153 |  |  | 
| 154 | function add_model() { | function add_model() { | 
| 155 | $args = &func_get_args(); | $args = &func_get_args(); | 
| 156 | $this->__push('model', &$args[0]); | $this->_container->push('model', &$args[0]); | 
| 157 | } | } | 
| 158 |  |  | 
| 159 | function add_view() { | function add_view() { | 
| 160 | $args = &func_get_args(); | $args = &func_get_args(); | 
| 161 | $this->__push('view', &$args[0]); | $this->_container->push('view', &$args[0]); | 
| 162 | } | } | 
| 163 |  |  | 
| 164 | function add_controller() { | function add_controller() { | 
| 165 | $args = &func_get_args(); | $args = &func_get_args(); | 
| 166 | $this->__push('controller', &$args[0]); | $this->_container->push('controller', &$args[0]); | 
| 167 | } | } | 
| 168 |  |  | 
| 169 | function &get_model_data() { | function &get_model_data() { | 
| 170 | return $this->__last('model'); | return $this->_container->last('model'); | 
| 171 | } | } | 
| 172 |  |  | 
| 173 | function &get_view_data() { | function &get_view_data() { | 
| 174 | $args = &func_get_args(); | $args = &func_get_args(); | 
| 175 | $slot = $args[0]; | $slot = $args[0]; | 
| 176 | return $this->__slot('view', $slot); | return $this->_container->slot('view', $slot); | 
| 177 | } | } | 
| 178 |  |  | 
| 179 | function &get_controller_data() { | function &get_controller_data() { | 
| 180 | return $this->__last('controller'); | return $this->_container->last('controller'); | 
| 181 | } | } | 
| 182 |  |  | 
| 183 |  | function check_performed_result() { | 
| 184 |  | if (sizeof($this->_performed_result)) { | 
| 185 |  | return 1; | 
| 186 |  | } else { | 
| 187 |  | user_error("MVC[" . get_class($this) . "] failed - performed result was empty."); | 
| 188 |  | } | 
| 189 |  | } | 
| 190 |  |  | 
| 191 | } | } | 
| 192 |  |  | 
| 193 | ?> | ?> |