2016-12-15 10:13:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Shaarli\Api\Controllers;
|
|
|
|
|
2017-05-07 16:50:20 +02:00
|
|
|
use Shaarli\Config\ConfigManager;
|
2016-12-15 10:13:00 +01:00
|
|
|
use \Slim\Container;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \LinkDB
|
|
|
|
*/
|
|
|
|
protected $linkDb;
|
|
|
|
|
2017-05-07 16:50:20 +02:00
|
|
|
/**
|
|
|
|
* @var \History
|
|
|
|
*/
|
|
|
|
protected $history;
|
|
|
|
|
2016-12-15 10:13:00 +01:00
|
|
|
/**
|
|
|
|
* @var int|null JSON style option.
|
|
|
|
*/
|
|
|
|
protected $jsonStyle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ApiController constructor.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
}
|