ATWF A Tcl Web Framwork

Check-in [23292c4f81]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:initial version

git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@613 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db

Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:23292c4f812d2001944311ab27653aefb6199bce
User & Date: arnulf@wiedemann-pri.de 2010-12-04 23:10:14
Context
2010-12-05
16:54
small fixes

git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@614 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db check-in: 4204f29af9 user: arnulf@wiedemann-pri.de tags: trunk

2010-12-04
23:10
initial version

git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@613 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db check-in: 23292c4f81 user: arnulf@wiedemann-pri.de tags: trunk

23:08
smaller fixes

git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@612 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db check-in: 2b9139ef97 user: arnulf@wiedemann-pri.de tags: trunk

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added demos/ATWF_Bootstrap.txt.

















































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
scan the .ini file
setOptions $options
   foreach {key value} $options
     # look for the method without case sensitivity!!
     if there exists a method set$key
       call it with param $value
     standard resources are
       Db
       Frontcontroller
       Layout
       Locale
       Modules
       Navigation
       Resource
       Router
       Session
       Translate
       View
     foreach part of key resources (which exists in .ini file)
       registerPluginResource $part $part_options
          constructor calls setOptions (in Resourcebase)
	  in setOptions:
            if there is a for resources.$part.$sub_part 
	    named set$sub_part call it with param $value
	    Application::Resource::Resourcebase has method setBootstrap
	    which is always called and then bootstrap is removed from the options
	    in $part options




     FrontCntroller dispatch {request response} {
	# _plugins is [::ATWF::Controllers::Plugins::Broker #auto]
	# if we need an error handler register ::ATWF::Controllers::Plugins::ErrorHandler with priority 100
	# if we need a view renderer register ::ATWF::Controllers::Actions::Helpers::ViewRenderer
	# Instantiate default request object (HTTP version) if none provided
	# set request [::ATWF::Controllers::Requests::Http #auto]
	    # in constructor
	    setRequestUri
	        # get request uri from $_SERVER HTTP_X_REWRITE_URL or $_SERVER REQUEST_URI
		# use the part without schema and httpHost
		# use ?... part and parse that into vars and call setQuery $vars
		# setQuery sets dict _GET
	    setParams $_GET
	        # this calls setParam foreach key value pair
		# setParam calls getAlias for the key (if it exists}
		# and calls Controllers::Requests::Request setParam
	        # this sets dict _params in Controllers::Requests::Request
	    setParams $_POST
	        # same as above
        setRequest $request 
        setBaseUrl $_baseUrl , # (if available)

	# Instantiate default response object (HTTP version) if none provided
	set response [::ATWF::Controllers::Responses::Http #auto]
        setResponse $response

	# Register request and response objects with plugin broker
        # for every plugin call method setRequest
	$_plugins setRequest $request
        $_plugins setResponse $response

        # initialize router
	# get a router if none provided: [::ATWF::Controllers::Routers::Rewrite #auto]
        set router [getRouter]
	    # Rewrite instantiates [::ATWF::Controllers::Routers::Router #auto]
	    # in constructor calls setParams with parameter params
        $router setParams [getParams]
	    # again call of $router setParams, as no params are provide when instantiating the object
            # getParams normally returns: bootstrap ::bootstrap0
        #initialize dispatcher
	set dispatcher [getDispatcher]
        $dispatcher [setParams [getParams]]
        $dispatcher setResponse $response

	# begin dispatch
        try {
	    # route request to controller/action if a router is provided

            # default plugins are ErrorHandler and
	    # ::ATWF::Layouts::Controllers::Plugins::Layout 8this is normally from configs)
	    # Notify plugins of router startup
            $_plugins routeStartup $request
	        # ErrorHandler and Layout do nothing here

            $router route $request
	        if {[$_useDefaultRoutes]} {
		    addDefaultRoutes
		        set compat [uplevel #0 ::ATWF::Controllers::Routers::Routings::Module #auto [list [list] $dispatcher $request]]
			set _routes [dict merge [dict create default $compat] $_routes]
		}
		foreach {name route} $_routes {
		    if {[set params [$route match [$request getPathInfo]]] ne ""} {
			    # split up path info into parts
			    # if first part of path is a valid module [$_dispatcher isValidModule [dict get $path 0]]
			    # set key $_moduleKey (which is module per default) to it
			    # and set _moduleValid true
			    # then set $_controllerKey (which is controller per default) to the next part
			    # then set $_actionKey (which is action per default) to the next part
			    # if the path has additional parts use always one element as key and one element as value 
			    # i.e.: .../a/b/d/c -> key a value b and key c value d
			    # and add these to the dict returned
                            # add _defaults to the returned dict, if available
		        _setRequestParams $request $params
			    foreach {param value} $params {
			        $request setParam $param $value
			        if {$param eq [$request getModuleKey]} {
			            $request setModuleName $value
			        }
			        if {$param eq [$request getControllerKey]} {
			            $request setControllerName $value
			        }
		                if {$param eq [$request getActionKey]} {
			            $request setActionName $value
			        }
			    }
			set _currentRoute $name
			break
		    }
		}

	    # notify plugins of router completion
            $_plugins  routeShutdown $request
	        # ErrorHandler and Layout do nothing here

	    # notify plugins of dispatch loop startup
            $_plugins dispatchLoopStartup $request
	        # ErrorHandler and Layout do nothing here

	    # attempt to dispatch the controller/action
	    # if $request indicates that itr needs to be dispatched
	    # move to next action in request
            while {1} {
                $request setDispatched true

		# notify plugins of dispatch startup
                $_plugins  preDispatch $request
	            # ErrorHandler and Layout do nothing here

                if {[$request isDispatched]} {
		    continue
		}

                # dispatch request
		try {
                    $dispatcher dispatch $request $response
		        # dispatcher is per default ::ATWF::Controllers::Dispatchers::Standard
			setResponse $response
			# default is isDispatchable
			set className [getControllerClass $request]
			set className [loadClass $className]
		        # Instantiate controller with request, response, and invocation
		        # arguments; throw exception if it's not an action controller
		        set controller [uplevel #0 $className #auto [list $request [getResponse] [getParams]]]
			    # params: bootstrap ::bootstrap0
			    # the Controller class is derived from Controllers::Action
			    # and the constructor thereof calls init method
			    # in init of the derived class there can be a call to ContextSwitch
			        set contextSwitch [$_helper getHelper ContextSwitch]
				    # that instantiates ::ATWF::Controllers::Actions::Helpers::ContextSwitch
                                    # Return if no context switching enabled, or no context switching
				    # enabled for this action
				    set contexts [getActionContexts $action]
				    if {$contexts eq ""} {
				        return
				    }
				    # Return if no context parameter provided
				    if {[set context [$request getParam [getContextParam]]] eq ""} {
				        if {$format eq ""} {
					    return
					}
					set context $format
					set format [list]
				    }
				    # Check if context allowed by action controller
				    if {![hasActionContext $action $context]} {
				        return
				    }
			            # Return if invalid context parameter provided and no format or invalid
				    # format provided
				    if {![hasContext $context]} {
				        if {($format eq "") || ![hasContext $format]} {
				            return
				        }
				    }
				    # Use provided format if passed
				    if {!($format ne "") && [hasContext $format]} {
				        set context $format
				    }
			            set suffix [getSuffix $context]
				    [_getViewRenderer] setViewSuffix $suffix
                                    set headers [getHeaders $context]
                                    if {$headers ne ""} {
                                        set response [getResponse]
                                        foreach {header content} $headers {
                                            $response setHeader $header $content
                                        }
                                    }
                                    if {[getAutoDisableLayout]} {
                                        set layout [::ATWF::Layout::getMvcInstance]
                                        if {$layout ne ""} {
                                            $layout disableLayout
                                        }
                                    }
                                    if {[set callback [getCallback $context TRIGGER_INIT]] ne ""} {
				        $callback
				    }
				    set _currentContext $context
                                 # end initContext
			    # end init
		        # Retrieve the action name
			set action [getActionMethod $request]
			# Dispatch the method call
			$request setDispatched true
			# by default, buffer output
			set disableOb [getParam disableOutputBuffering]
			set obLevel [::ATWF::Output::ob_get_level]
			if {$disableOb eq ""} {
			    ::ATWF::Output::ob_start
			}
			$controller dispatch $action
			    # calls per default ::ATWF::Action::dispatch
			    dispatch {action} {
			        $_helper notifyPreDispatch
				preDispatch
				if {[[getRequest] isDispatched]} {
			            # preDispatch didn't change the action, so we can continue
				    set method [$this info function $action -name]
				    $this $action
				}
				postDispatch
			        $_helper notifyPostDispatch
			    }


	        }
                # notify plugins of dispatch completion
		$_plugins postDispatch $request
	            # Layout does:
		    set layout [getLayout]
                    set helper [getLayoutActionHelper]

                    # Return early if forward detected
                    if {![$request isDispatched]
                        || [$layout getMvcSuccessfulActionOnly]
                            && ($helper ne "") && ![$helper isActionControllerSuccessful]} {
                        return
                    }
                
                    # Return early if layout has been disabled
                    if {![$layout isEnabled]} {
                        return
                    }

                    set response [getResponse]
                    set content [$response getBody true]
                    set contentKey [$layout getContentKey]
                
                    if {[dict exists $content default]} {
                        dict set content $contentKey [dict get $content default]
                    }
                    if {$contentKey ne "default"} {
                        set content [dict remove $content default]
                    }
                
                    $layout assign $content
                    
                    set fullContent [list]
                    set obStartLevel [::ATWF::Output::ob_get_level]
                    try {
                        set fullContent [$layout render]
                        $response setBody $fullContent
                    } trap error [list msg opts] {
                        while {[::ATWF::Output::ob_get_level] > $obStartLevel} {
                            append fullContent [::ATWF::Output::ob_get_clean]
                        }
                        $request setParam layoutFullContent $fullContent
                        $request setParam layoutContent [$layout content]
                        $response setBody [list]
                    }
                if {[$request isDispatched]} {
		    break
		}
            } ; # end of to be dispatched
	}
	# notify plugins of dispatch loop completion
	try {
            $_plugins dispatchLoopShutdown $request
	}
        if {[returnResponse]} {
	    return $response
	}
	$resonse sendResponse
    }