aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/api/controllers/ApiController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/api/controllers/ApiController.php')
-rw-r--r--application/api/controllers/ApiController.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/application/api/controllers/ApiController.php b/application/api/controllers/ApiController.php
new file mode 100644
index 00000000..3be85b98
--- /dev/null
+++ b/application/api/controllers/ApiController.php
@@ -0,0 +1,71 @@
1<?php
2
3namespace Shaarli\Api\Controllers;
4
5use Shaarli\Config\ConfigManager;
6use \Slim\Container;
7
8/**
9 * Abstract Class ApiController
10 *
11 * Defines REST API Controller dependencies injected from the container.
12 *
13 * @package Api\Controllers
14 */
15abstract class ApiController
16{
17 /**
18 * @var Container
19 */
20 protected $ci;
21
22 /**
23 * @var ConfigManager
24 */
25 protected $conf;
26
27 /**
28 * @var \LinkDB
29 */
30 protected $linkDb;
31
32 /**
33 * @var \History
34 */
35 protected $history;
36
37 /**
38 * @var int|null JSON style option.
39 */
40 protected $jsonStyle;
41
42 /**
43 * ApiController constructor.
44 *
45 * Note: enabling debug mode displays JSON with readable formatting.
46 *
47 * @param Container $ci Slim container.
48 */
49 public function __construct(Container $ci)
50 {
51 $this->ci = $ci;
52 $this->conf = $ci->get('conf');
53 $this->linkDb = $ci->get('db');
54 $this->history = $ci->get('history');
55 if ($this->conf->get('dev.debug', false)) {
56 $this->jsonStyle = JSON_PRETTY_PRINT;
57 } else {
58 $this->jsonStyle = null;
59 }
60 }
61
62 /**
63 * Get the container.
64 *
65 * @return Container
66 */
67 public function getCi()
68 {
69 return $this->ci;
70 }
71}