2016-12-15 10:13:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Shaarli\Api\Controllers;
|
|
|
|
|
2019-01-12 23:55:38 +01:00
|
|
|
use Shaarli\Bookmark\LinkDB;
|
2017-05-07 16:50:20 +02:00
|
|
|
use Shaarli\Config\ConfigManager;
|
2019-01-12 23:55:38 +01:00
|
|
|
use Slim\Container;
|
2016-12-15 10:13:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract Class ApiController
|
|
|
|
*
|
|
|
|
* Defines REST API Controller dependencies injected from the container.
|
|
|
|
*
|
|
|
|
* @package Api\Controllers
|
|
|
|
*/
|
|
|
|
abstract class ApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Container
|
|
|
|
*/
|
|
|
|
protected $ci;
|
|
|
|
|
|
|
|
/**
|
2017-05-07 16:50:20 +02:00
|
|
|
* @var ConfigManager
|
2016-12-15 10:13:00 +01:00
|
|
|
*/
|
|
|
|
protected $conf;
|
|
|
|
|
|
|
|
/**
|
2019-01-12 23:55:38 +01:00
|
|
|
* @var LinkDB
|
2016-12-15 10:13:00 +01:00
|
|
|
*/
|
|
|
|
protected $linkDb;
|
|
|
|
|
2017-05-07 16:50:20 +02:00
|
|
|
/**
|
2019-01-12 23:55:38 +01:00
|
|
|
* @var HistoryController
|
2017-05-07 16:50:20 +02:00
|
|
|
*/
|
|
|
|
protected $history;
|
|
|
|
|
2016-12-15 10:13:00 +01:00
|
|
|
/**
|
|
|
|
* @var int|null JSON style option.
|
|
|
|
*/
|
|
|
|
protected $jsonStyle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ApiController constructor.
|
2018-10-13 00:19:03 +02:00
|
|
|
*
|
2016-12-15 10:13:00 +01:00
|
|
|
* Note: enabling debug mode displays JSON with readable formatting.
|
|
|
|
*
|
|
|
|
* @param Container $ci Slim container.
|
|
|
|
*/
|
|
|
|
public function __construct(Container $ci)
|
|
|
|
{
|
|
|
|
$this->ci = $ci;
|
|
|
|
$this->conf = $ci->get('conf');
|
|
|
|
$this->linkDb = $ci->get('db');
|
2017-05-07 16:50:20 +02:00
|
|
|
$this->history = $ci->get('history');
|
2016-12-15 10:13:00 +01:00
|
|
|
if ($this->conf->get('dev.debug', false)) {
|
|
|
|
$this->jsonStyle = JSON_PRETTY_PRINT;
|
|
|
|
} else {
|
|
|
|
$this->jsonStyle = null;
|
|
|
|
}
|
|
|
|
}
|
2017-01-05 15:58:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the container.
|
|
|
|
*
|
|
|
|
* @return Container
|
|
|
|
*/
|
|
|
|
public function getCi()
|
|
|
|
{
|
|
|
|
return $this->ci;
|
|
|
|
}
|
2016-12-15 10:13:00 +01:00
|
|
|
}
|