BaseController.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Controllers;
  3. use App\Services\Auth;
  4. use App\Services\Factory;
  5. use App\Services\View;
  6. /**
  7. * BaseController
  8. */
  9. class BaseController
  10. {
  11. protected $view;
  12. protected $smarty;
  13. protected $app;
  14. /**
  15. * @var \Illuminate\Translation\Translator
  16. */
  17. protected $lang;
  18. public function __construct()
  19. {
  20. $this->lang = Factory::getLang();
  21. }
  22. /**
  23. * @return \Illuminate\Translation\Translator
  24. */
  25. protected function getLang()
  26. {
  27. return Factory::getLang();
  28. }
  29. /**
  30. * @return \Smarty
  31. */
  32. public function smarty()
  33. {
  34. $this->smarty = View::getSmarty();
  35. return $this->smarty;
  36. }
  37. /**
  38. * @return \Smarty
  39. */
  40. public function view()
  41. {
  42. return $this->smarty();
  43. }
  44. /**
  45. * @param $response
  46. * @param $res
  47. * @param int $statusCode
  48. * @return mixed
  49. */
  50. public function echoJson($response, $res, $statusCode = 200)
  51. {
  52. $newResponse = $response->withJson($res, $statusCode);
  53. return $newResponse;
  54. }
  55. /**
  56. * @param $response
  57. * @param $to
  58. * @return mixed
  59. */
  60. public function redirect($response, $to)
  61. {
  62. $newResponse = $response->withStatus(302)->withHeader('Location', $to);
  63. return $newResponse;
  64. }
  65. }