mirror of
https://github.com/grocy/grocy.git
synced 2026-04-08 13:46:14 +02:00
utilise Localisation service as a singleton
This commit is contained in:
parent
aa1cc4ad88
commit
9f277f51b3
8
app.php
8
app.php
|
|
@ -74,11 +74,11 @@ $appContainer = new \Slim\Container([
|
||||||
]);
|
]);
|
||||||
$app = new \Slim\App($appContainer);
|
$app = new \Slim\App($appContainer);
|
||||||
|
|
||||||
$fp = fopen('/www/data/sql.log', 'a');
|
#$fp = fopen('/www/data/sql.log', 'a');
|
||||||
fwrite($fp, "!!!Starting up loading app\n");
|
#fwrite($fp, "!!!Starting up loading app\n");
|
||||||
fwrite($fp, "!!!".print_r(ini_get_all(),True)."\n");
|
#fwrite($fp, "!!!".print_r(ini_get_all(),True)."\n");
|
||||||
#fwrite($fp, "!!!".print_r(opcache_get_status(),True)."\n");
|
#fwrite($fp, "!!!".print_r(opcache_get_status(),True)."\n");
|
||||||
fclose($fp);
|
#fclose($fp);
|
||||||
|
|
||||||
phpinfo();
|
phpinfo();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class BaseController
|
||||||
$databaseService = DatabaseService::getInstance();
|
$databaseService = DatabaseService::getInstance();
|
||||||
$this->Database = $databaseService->GetDbConnection();
|
$this->Database = $databaseService->GetDbConnection();
|
||||||
|
|
||||||
$localizationService = new LocalizationService(GROCY_CULTURE);
|
$localizationService = LocalizationService::getInstance(GROCY_CULTURE);
|
||||||
$this->LocalizationService = $localizationService;
|
$this->LocalizationService = $localizationService;
|
||||||
|
|
||||||
$applicationService = ApplicationService::getInstance();
|
$applicationService = ApplicationService::getInstance();
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class ApiKeyAuthMiddleware extends BaseMiddleware
|
||||||
$validSession = true;
|
$validSession = true;
|
||||||
$validApiKey = true;
|
$validApiKey = true;
|
||||||
$usedApiKey = null;
|
$usedApiKey = null;
|
||||||
|
|
||||||
$sessionService = new SessionService();
|
$sessionService = new SessionService();
|
||||||
if (!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName]))
|
if (!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName]))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class BaseService
|
||||||
$this->DatabaseService = DatabaseService::getInstance();
|
$this->DatabaseService = DatabaseService::getInstance();
|
||||||
$this->Database = $this->DatabaseService->GetDbConnection();
|
$this->Database = $this->DatabaseService->GetDbConnection();
|
||||||
|
|
||||||
$localizationService = new LocalizationService(GROCY_CULTURE);
|
$localizationService = LocalizationService::getInstance(GROCY_CULTURE);
|
||||||
$this->LocalizationService = $localizationService;
|
$this->LocalizationService = $localizationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ class FilesService extends BaseService
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->StoragePath = GROCY_DATAPATH . '/storage';
|
$this->StoragePath = GROCY_DATAPATH . '/storage';
|
||||||
|
|
||||||
if (!file_exists($this->StoragePath))
|
if (!file_exists($this->StoragePath))
|
||||||
{
|
{
|
||||||
mkdir($this->StoragePath);
|
mkdir($this->StoragePath);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ use \Gettext\Translator;
|
||||||
|
|
||||||
class LocalizationService
|
class LocalizationService
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static $instanceMap = array();
|
||||||
|
|
||||||
public function __construct(string $culture)
|
public function __construct(string $culture)
|
||||||
{
|
{
|
||||||
$this->Culture = $culture;
|
$this->Culture = $culture;
|
||||||
|
|
@ -18,6 +21,16 @@ class LocalizationService
|
||||||
$this->LoadLocalizations($culture);
|
$this->LoadLocalizations($culture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getInstance(string $culture)
|
||||||
|
{
|
||||||
|
if (!in_array($culture, self::$instanceMap))
|
||||||
|
{
|
||||||
|
self::$instanceMap[$culture] = new self($culture);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instanceMap[$culture];
|
||||||
|
}
|
||||||
|
|
||||||
protected $DatabaseService;
|
protected $DatabaseService;
|
||||||
protected $Database;
|
protected $Database;
|
||||||
protected $Pot;
|
protected $Pot;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class SessionService extends BaseService
|
||||||
public function CreateSession($userId, $stayLoggedInPermanently = false)
|
public function CreateSession($userId, $stayLoggedInPermanently = false)
|
||||||
{
|
{
|
||||||
$newSessionKey = $this->GenerateSessionKey();
|
$newSessionKey = $this->GenerateSessionKey();
|
||||||
|
|
||||||
$expires = date('Y-m-d H:i:s', intval(time() + 2592000)); // Default is that sessions expire in 30 days
|
$expires = date('Y-m-d H:i:s', intval(time() + 2592000)); // Default is that sessions expire in 30 days
|
||||||
if ($stayLoggedInPermanently === true)
|
if ($stayLoggedInPermanently === true)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user