application_controller.php 1.1 KB

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