repod/lib/Service/UserService.php
Michel Roux 93e4998394
Some checks failed
repod / nextcloud (push) Successful in 56s
repod / xml (push) Successful in 13s
repod / nodejs (push) Failing after 1m50s
cs fix
2023-12-23 16:25:20 +00:00

39 lines
736 B
PHP

<?php
declare(strict_types=1);
namespace OCA\RePod\Service;
use OCP\IUserSession;
use OCP\L10N\IFactory;
class UserService
{
public function __construct(
private IFactory $l10n,
private IUserSession $userSession
) {}
public function getUserUID(): string {
$user = $this->userSession->getUser();
return $user ? $user->getUID() : '';
}
public function getIsoCode(): string {
return $this->l10n->getUserLanguage($this->userSession->getUser());
}
public function getCountryCode(): string {
$isoCodes = explode('_', $this->getIsoCode());
return isset($isoCodes[1]) ? $isoCodes[1] : 'us';
}
public function getLangCode(): string {
$isoCodes = explode('_', $this->getIsoCode());
return $isoCodes[0];
}
}