controller.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Part of the Fuel framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Fuel\Core;
  13. abstract class Controller
  14. {
  15. /**
  16. * @var Request The current Request object
  17. */
  18. public $request;
  19. /**
  20. * Sets the controller request object.
  21. *
  22. * @param Request The current request object
  23. */
  24. public function __construct(\Request $request)
  25. {
  26. $this->request = $request;
  27. }
  28. /**
  29. * This method gets called before the action is called
  30. */
  31. public function before() {}
  32. /**
  33. * This method gets called after the action is called
  34. */
  35. public function after($response)
  36. {
  37. // Make sure the $response is a Response object
  38. if ( ! $response instanceof Response)
  39. {
  40. $response = \Response::forge($response);
  41. }
  42. return $response;
  43. }
  44. /**
  45. * This method returns the named parameter requested, or all of them
  46. * if no parameter is given.
  47. *
  48. * @param string $param The name of the parameter
  49. * @param mixed $default Default value
  50. * @return mixed
  51. */
  52. public function param($param, $default = null)
  53. {
  54. return $this->request->param($param, $default);
  55. }
  56. /**
  57. * This method returns all of the named parameters.
  58. *
  59. * @return array
  60. */
  61. public function params()
  62. {
  63. return $this->request->params();
  64. }
  65. }