ApiController.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Shaarli\Api\Controllers;
  3. use Shaarli\Config\ConfigManager;
  4. use \Slim\Container;
  5. /**
  6. * Abstract Class ApiController
  7. *
  8. * Defines REST API Controller dependencies injected from the container.
  9. *
  10. * @package Api\Controllers
  11. */
  12. abstract class ApiController
  13. {
  14. /**
  15. * @var Container
  16. */
  17. protected $ci;
  18. /**
  19. * @var ConfigManager
  20. */
  21. protected $conf;
  22. /**
  23. * @var \LinkDB
  24. */
  25. protected $linkDb;
  26. /**
  27. * @var \History
  28. */
  29. protected $history;
  30. /**
  31. * @var int|null JSON style option.
  32. */
  33. protected $jsonStyle;
  34. /**
  35. * ApiController constructor.
  36. *
  37. * Note: enabling debug mode displays JSON with readable formatting.
  38. *
  39. * @param Container $ci Slim container.
  40. */
  41. public function __construct(Container $ci)
  42. {
  43. $this->ci = $ci;
  44. $this->conf = $ci->get('conf');
  45. $this->linkDb = $ci->get('db');
  46. $this->history = $ci->get('history');
  47. if ($this->conf->get('dev.debug', false)) {
  48. $this->jsonStyle = JSON_PRETTY_PRINT;
  49. } else {
  50. $this->jsonStyle = null;
  51. }
  52. }
  53. /**
  54. * Get the container.
  55. *
  56. * @return Container
  57. */
  58. public function getCi()
  59. {
  60. return $this->ci;
  61. }
  62. }