Action.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Action superclass file.
  4. *
  5. * Provides a class to be extended for individual actions.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. /**
  12. * Action superclass.
  13. *
  14. * Every action must inherit from this one.
  15. *
  16. * @category Action
  17. */
  18. abstract class Action{
  19. /**
  20. * @var int HTTP status code returned by the action. 0 before executing.
  21. */
  22. protected $code = 0;
  23. /**
  24. * @var string HTTP status message. Empty before executing.
  25. */
  26. protected $message = "";
  27. /**
  28. * @var string Output returned by the action. Empty before excuting.
  29. */
  30. protected $output = "";
  31. /**
  32. * Executes the action.
  33. *
  34. * To be implemented in the individual actions.
  35. */
  36. abstract public function execute();
  37. /**
  38. * Retrieves the HTTP status code returned by the action.
  39. *
  40. * If the action has not been executed yet, the code will be 0.
  41. *
  42. * @return int HTTP status code.
  43. */
  44. public function get_code(){
  45. return $this->code;
  46. }
  47. /**
  48. * Retrieves the HTTP status message returned by the action.
  49. *
  50. * If the action has not been executed yet, the message will be empty.
  51. *
  52. * @return string HTTP status message.
  53. */
  54. public function get_message(){
  55. return $this->message;
  56. }
  57. /**
  58. * Retrieves the output buffered by the action.
  59. *
  60. * If the action has not been executed yet or it didn't buffer anything, it will be empty.
  61. *
  62. * @return string Action output.
  63. */
  64. public function get_output(){
  65. return $this->output;
  66. }
  67. }