Context.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Context file.
  4. *
  5. * Provides a handy class with usefull data to be accessible from anywhere in the app.
  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. * Application context.
  13. *
  14. * Stores usefull data to be retrieved anywhere in the app.
  15. *
  16. * @category Context
  17. */
  18. class Context {
  19. /**
  20. * @var User Currently logged in user.
  21. */
  22. private $user;
  23. /**
  24. * @var Player Currently selected player. Does not need to be owned by the logged-in user.
  25. */
  26. private $player;
  27. /**
  28. * @var SQLITE3 Database connection.
  29. */
  30. private $db;
  31. /**
  32. * @var int Selected game mode.
  33. * @see GAME_MODE_ID.
  34. */
  35. private $game_mode;
  36. /**
  37. * Retrieves the selected user.
  38. *
  39. * @return User The selected user, null if no specified.
  40. */
  41. public function get_user(){
  42. return $this->user;
  43. }
  44. /**
  45. * Retrieves the logged in player.
  46. *
  47. * @return Player The current player, null if not logged in.
  48. */
  49. public function get_player(){
  50. return $this->player;
  51. }
  52. /**
  53. * Retrieves the database connection.
  54. *
  55. * @return SQLITE3 The database connection.
  56. */
  57. public function get_db(){
  58. return $this->db;
  59. }
  60. /**
  61. * Retrieves the current game mode.
  62. *
  63. * @see GAME_MODE_ID
  64. * @return int Game mode.
  65. */
  66. public function get_game_mode(){
  67. return $this->game_mode;
  68. }
  69. /**
  70. * Sets the current user.
  71. *
  72. * @param The current user.
  73. */
  74. protected function set_user($user){
  75. $this->user = $user;
  76. }
  77. /**
  78. * Sets the currently logged-in player.
  79. *
  80. * @param Player Logged-in player.
  81. */
  82. protected function set_player($player){
  83. $this->player = $player;
  84. }
  85. /**
  86. * Sets the database connection
  87. *
  88. * @param SQLITE3 Database connection.
  89. */
  90. protected function set_db($db){
  91. $this->db = $db;
  92. }
  93. /**
  94. * Sets the game mode.
  95. *
  96. * @see GAME_MODE_ID
  97. * @param int Game mode.
  98. */
  99. protected function set_game_mode($game_mode){
  100. $this->game_mode = $game_mode;
  101. }
  102. }