/[cvs]/nfo/php/libs/org.netfrag.glib/DesignPattern/MVC.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.glib/DesignPattern/MVC.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations)
Fri Apr 4 17:37:05 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.12: +15 -3 lines
modifications regarding error-/exception-handling

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed