Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / writer / remote / lib / application_controller.php
1 <?php
2 /**
3  * @class ApplicationController
4  */
5 class ApplicationController {
6     public $request, $id, $params;
7
8     /**
9      * dispatch
10      * Dispatch request to appropriate controller-action by convention according to the HTTP method.
11      */
12     public function dispatch($request) {
13         $this->request = $request;
14         $this->id = $request->id;
15         $this->params = $request->params;
16
17         if ($request->isRestful()) {
18             return $this->dispatchRestful();
19         }
20         if ($request->action) {
21             return $this->{$request->action}();
22         }
23
24         // normal dispatch here.  discover action
25     }
26
27     protected function dispatchRestful() {
28         switch ($this->request->method) {
29             case 'GET':
30                 return $this->view();
31                 break;
32             case 'POST':
33                 return $this->create();
34                 break;
35             case 'PUT':
36                 return $this->update();
37                 break;
38             case 'DELETE':
39                 return $this->destroy();
40                 break;
41         }
42     }
43 }
44