application_controller.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. }
  22. protected function dispatchRestful() {
  23. switch ($this->request->method) {
  24. case 'GET':
  25. return $this->view();
  26. break;
  27. case 'POST':
  28. return $this->create();
  29. break;
  30. case 'PUT':
  31. return $this->update();
  32. break;
  33. case 'DELETE':
  34. return $this->destroy();
  35. break;
  36. }
  37. }
  38. }