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