Readme, some fixes, rel noopener for _blank links

This commit is contained in:
2021-04-03 10:39:13 +02:00
parent 2087e56626
commit 18e7955b12
12 changed files with 82 additions and 27 deletions

View File

@@ -4,7 +4,7 @@ namespace Objects;
abstract class ApiObject implements \JsonSerializable {
public abstract function jsonSerialize();
public abstract function jsonSerialize(): array;
public function __toString() { return json_encode($this); }

View File

@@ -31,7 +31,10 @@ namespace Objects {
public function getEntries() { return $this->entries; }
public function getModules() { return $this->modules; }
public function loadModule(LanguageModule $module) {
/**
* @param $module LanguageModule class or object
*/
public function loadModule($module) {
if(!is_object($module))
$module = new $module;
@@ -40,7 +43,7 @@ namespace Objects {
$this->modules[] = $module;
}
public function translate($key) {
public function translate(string $key): string {
if(isset($this->entries[$key]))
return $this->entries[$key];
@@ -51,7 +54,7 @@ namespace Objects {
setcookie('lang', $this->langCode, 0, "/", "");
}
public function jsonSerialize() {
public function jsonSerialize(): array {
return array(
'uid' => $this->languageId,
'code' => $this->langCode,

View File

@@ -28,7 +28,7 @@ class Session extends ApiObject {
$this->csrfToken = $csrfToken ?? generateRandomString(16);
}
public static function create($user, $stayLoggedIn) {
public static function create($user, $stayLoggedIn): ?Session {
$session = new Session($user, null, null);
if($session->insert($stayLoggedIn)) {
return $session;
@@ -69,15 +69,15 @@ class Session extends ApiObject {
setcookie('session', $sessionCookie, $this->getExpiresTime(), "/", "", $secure);
}
public function getExpiresTime() {
public function getExpiresTime(): int {
return ($this->stayLoggedIn == 0 ? 0 : $this->expires);
}
public function getExpiresSeconds() {
public function getExpiresSeconds(): int {
return ($this->stayLoggedIn == 0 ? -1 : $this->expires - time());
}
public function jsonSerialize() {
public function jsonSerialize(): array {
return array(
'uid' => $this->sessionId,
'user_id' => $this->user->getId(),
@@ -89,7 +89,7 @@ class Session extends ApiObject {
);
}
public function insert($stayLoggedIn) {
public function insert($stayLoggedIn): bool {
$this->updateMetaData();
$sql = $this->user->getSQL();