ApiController.php 1023 B

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