code cleanup

This commit is contained in:
Roman 2021-04-02 21:58:06 +02:00
parent 4a52ab2fd7
commit eea0aeacc6
67 changed files with 472 additions and 425 deletions

@ -44,7 +44,7 @@ namespace Api\ApiKey {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
@ -81,7 +81,7 @@ namespace Api\ApiKey {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@ -127,7 +127,7 @@ namespace Api\ApiKey {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@ -162,7 +162,7 @@ namespace Api\ApiKey {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}

@ -34,7 +34,7 @@ namespace Api\Contact {
parent::__construct($user, $externalCall, $parameters);
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}

@ -238,7 +238,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -292,7 +292,7 @@ namespace Api\File {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -316,7 +316,7 @@ namespace Api\File {
$this->csrfTokenRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -360,7 +360,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -407,7 +407,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -450,7 +450,7 @@ namespace Api\File {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -482,7 +482,7 @@ namespace Api\File {
));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -551,7 +551,7 @@ namespace Api\File {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -653,7 +653,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -826,7 +826,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -891,7 +891,7 @@ namespace Api\File {
$this->csrfTokenRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -946,7 +946,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -1017,7 +1017,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}

@ -54,7 +54,7 @@ namespace Api\Groups {
return $this->success;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@ -116,7 +116,7 @@ namespace Api\Groups {
));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -162,7 +162,7 @@ namespace Api\Groups {
));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}

@ -23,7 +23,7 @@ namespace Api\Language {
parent::__construct($user, $externalCall, array());
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@ -108,7 +108,7 @@ namespace Api\Language {
return $this->success;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}

@ -24,7 +24,7 @@ namespace Api\Mail {
));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -77,7 +77,7 @@ namespace Api\Mail {
return null;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}

@ -107,7 +107,7 @@ namespace Api\Notifications {
return $this->success;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@ -213,7 +213,7 @@ namespace Api\Notifications {
return $this->success;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@ -235,7 +235,7 @@ namespace Api\Notifications {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}

@ -8,14 +8,22 @@ class ArrayType extends Parameter {
public int $elementType;
public int $canBeOne;
public function __construct($name, $elementType = Parameter::TYPE_MIXED, $canBeOne=false, $optional = FALSE, $defaultValue = NULL) {
/**
* ArrayType constructor.
* @param string $name the name of the parameter
* @param int $elementType element type inside the array, for example, allow only integer values (Parameter::TYPE_INT)
* @param bool $canBeOne true, if a single element can be passed inside the request (e.g. array=1 instead of array[]=1). Will be automatically casted to an array
* @param bool $optional true if the parameter is optional
* @param array|null $defaultValue the default value to use, if the parameter is not given
*/
public function __construct(string $name, int $elementType = Parameter::TYPE_MIXED, bool $canBeOne = false, bool $optional = FALSE, ?array $defaultValue = NULL) {
$this->elementType = $elementType;
$this->elementParameter = new Parameter('', $elementType);
$this->canBeOne = $canBeOne;
parent::__construct($name, Parameter::TYPE_ARRAY, $optional, $defaultValue);
}
public function parseParam($value) {
public function parseParam($value): bool {
if(!is_array($value)) {
if (!$this->canBeOne) {
return false;
@ -38,12 +46,12 @@ class ArrayType extends Parameter {
return true;
}
public function getTypeName() {
public function getTypeName(): string {
$elementType = $this->elementParameter->getTypeName();
return parent::getTypeName() . "($elementType)";
}
public function toString() {
public function toString(): string {
$typeName = $this->getTypeName();
$str = "$typeName $this->name";
$defaultValue = (is_null($this->value) ? 'NULL' : (is_array($this->value) ? '[' . implode(",", $this->value) . ']' : $this->value));

@ -26,11 +26,11 @@ class Parameter {
public string $name;
public $value;
public $optional;
public bool $optional;
public int $type;
public string $typeName;
public function __construct($name, $type, $optional = FALSE, $defaultValue = NULL) {
public function __construct(string $name, int $type, bool $optional = FALSE, $defaultValue = NULL) {
$this->name = $name;
$this->optional = $optional;
$this->value = $defaultValue;
@ -38,11 +38,11 @@ class Parameter {
$this->typeName = $this->getTypeName();
}
public function getTypeName() {
public function getTypeName(): string {
return ($this->type >= 0 && $this->type < count(Parameter::names)) ? Parameter::names[$this->type] : "INVALID";
}
public function toString() {
public function toString(): string {
$typeName = Parameter::names[$this->type];
$str = "$typeName $this->name";
@ -54,7 +54,7 @@ class Parameter {
return $str;
}
public static function parseType($value) {
public static function parseType($value): int {
if(is_array($value))
return Parameter::TYPE_ARRAY;
else if(is_numeric($value) && intval($value) == $value)
@ -77,7 +77,7 @@ class Parameter {
return Parameter::TYPE_STRING;
}
public function parseParam($value) {
public function parseParam($value): bool {
switch($this->type) {
case Parameter::TYPE_INT:
if(is_numeric($value) && intval($value) == $value) {

@ -5,12 +5,12 @@ namespace Api\Parameter;
class StringType extends Parameter {
public int $maxLength;
public function __construct($name, $maxLength = -1, $optional = FALSE, $defaultValue = NULL) {
public function __construct(string $name, int $maxLength = -1, bool $optional = FALSE, ?string $defaultValue = NULL) {
$this->maxLength = $maxLength;
parent::__construct($name, Parameter::TYPE_STRING, $optional, $defaultValue);
}
public function parseParam($value) {
public function parseParam($value): bool {
if(!is_string($value)) {
return false;
}
@ -23,12 +23,12 @@ class StringType extends Parameter {
return true;
}
public function getTypeName() {
public function getTypeName(): string {
$maxLength = ($this->maxLength > 0 ? "($this->maxLength)" : "");
return parent::getTypeName() . $maxLength;
}
public function toString() {
public function toString(): string {
$typeName = $this->getTypeName();
$str = "$typeName $this->name";
$defaultValue = (is_null($this->value) ? 'NULL' : $this->value);

@ -16,7 +16,7 @@ class PatchSQL extends Request {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}

@ -35,7 +35,7 @@ namespace Api\Permission {
$this->isPublic = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -102,7 +102,7 @@ namespace Api\Permission {
return $this->success;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -147,7 +147,7 @@ namespace Api\Permission {
));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}

@ -45,7 +45,7 @@ class Request {
}
}
public function parseParams($values) {
public function parseParams($values): bool {
foreach ($this->params as $name => $param) {
$value = $values[$name] ?? NULL;
@ -62,6 +62,7 @@ class Request {
}
}
}
return true;
}
@ -75,7 +76,7 @@ class Request {
}
}
public function execute($values = array()) {
public function execute($values = array()): bool {
$this->params = $this->aDefaultParams;
$this->success = false;
$this->result = array();
@ -155,11 +156,13 @@ class Request {
}
}
if(!$this->parseParams($values))
if (!$this->parseParams($values)) {
return false;
}
if($this->variableParamCount)
if ($this->variableParamCount) {
$this->parseVariableParams($values);
}
if (!$this->user->getSQL()->isConnected()) {
$this->lastError = $this->user->getSQL()->getLastError();
@ -171,23 +174,39 @@ class Request {
return true;
}
protected function createError($err) {
protected function createError($err): bool {
$this->success = false;
$this->lastError = $err;
return false;
}
protected function getParam($name) {
return isset($this->params[$name]) ? $this->params[$name]->value : NULL;
return $this->params[$name] ?? NULL;
}
public function isPublic() { return $this->isPublic; }
public function getLastError() { return $this->lastError; }
public function getResult() { return $this->result; }
public function success() { return $this->success; }
public function loginRequired() { return $this->loginRequired; }
public function isExternalCall() { return $this->externalCall; }
public function clearError() { $this->success = true; $this->lastError = ""; }
public function isPublic(): bool {
return $this->isPublic;
}
public function getLastError(): string {
return $this->lastError;
}
public function getResult(): array {
return $this->result;
}
public function success(): bool {
return $this->success;
}
public function loginRequired(): bool {
return $this->loginRequired;
}
public function isExternalCall(): bool {
return $this->externalCall;
}
private function getMethod() {
$class = str_replace("\\", "/", get_class($this));
@ -195,7 +214,7 @@ class Request {
return $class;
}
public function getJsonResult() {
public function getJsonResult(): string {
$this->result['success'] = $this->success;
$this->result['msg'] = $this->lastError;
return json_encode($this->result);

@ -34,7 +34,7 @@ namespace Api\Routes {
parent::__construct($user, $externalCall, array());
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@ -81,7 +81,7 @@ namespace Api\Routes {
$this->isPublic = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@ -133,7 +133,7 @@ namespace Api\Routes {
));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}

@ -29,7 +29,7 @@ namespace Api\Settings {
));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@ -72,7 +72,7 @@ namespace Api\Settings {
));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}

@ -66,7 +66,7 @@ class Stats extends Request {
return ($this->success ? $res[0]["count"] : $this->success);
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}

@ -9,11 +9,11 @@ namespace Api {
protected function userExists(?string $username, ?string $email) {
$conditions = array();
if (!is_null($username) && !empty($username)) {
if ($username) {
$conditions[] = new Compare("User.name", $username);
}
if (!is_null($email) && !empty($email)) {
if ($email) {
$conditions[] = new Compare("User.email", $email);
}
@ -152,7 +152,7 @@ namespace Api\User {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -229,7 +229,7 @@ namespace Api\User {
return false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -306,7 +306,7 @@ namespace Api\User {
));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -350,7 +350,7 @@ namespace Api\User {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -377,7 +377,7 @@ namespace Api\User {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -469,7 +469,7 @@ namespace Api\User {
return $this->success;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -533,7 +533,7 @@ namespace Api\User {
return $this->success;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -586,7 +586,7 @@ namespace Api\User {
return $this->createError(L('Wrong username or password'));
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -648,7 +648,7 @@ namespace Api\User {
$this->apiKeyAllowed = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -693,7 +693,7 @@ namespace Api\User {
return $this->success;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -804,7 +804,7 @@ namespace Api\User {
return array();
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -847,7 +847,7 @@ namespace Api\User {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -945,7 +945,7 @@ namespace Api\User {
$this->loginRequired = true;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -986,7 +986,7 @@ namespace Api\User {
$this->csrfTokenRequired = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -1105,7 +1105,7 @@ namespace Api\User {
return $this->success;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}

@ -16,7 +16,7 @@ class VerifyCaptcha extends Request {
$this->isPublic = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}

@ -27,7 +27,7 @@ namespace Api\Visitors {
$this->isPublic = false;
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@ -75,7 +75,7 @@ namespace Api\Visitors {
}
}
public function execute($values = array()) {
public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}

@ -86,7 +86,7 @@ class Configuration {
return @file_put_contents($path, $code);
}
public function delete(string $className) {
public function delete(string $className): bool {
$path = getClassPath("\\Configuration\\$className");
if (file_exists($path)) {
return unlink($path);

@ -11,7 +11,7 @@ class CreateDatabase extends DatabaseScript {
// NOTE:
// explicit serial ids removed due to postgres' serial implementation
public static function createQueries(SQL $sql) {
public static function createQueries(SQL $sql): array {
$queries = array();
// Language

@ -10,7 +10,7 @@ use Driver\SQL\Strategy\UpdateStrategy;
class file_api extends DatabaseScript {
public static function createQueries(SQL $sql) {
public static function createQueries(SQL $sql): array {
$queries = array();

@ -11,12 +11,16 @@ use Objects\User;
class Settings {
//
private bool $installationComplete;
// settings
private string $siteName;
private string $baseUrl;
private string $jwtSecret;
private bool $installationComplete;
private bool $registrationAllowed;
private bool $recaptchaEnabled;
private bool $mailEnabled;
private string $recaptchaPublicKey;
private string $recaptchaPrivateKey;
@ -24,7 +28,7 @@ class Settings {
return $this->jwtSecret;
}
public function isInstalled() {
public function isInstalled(): bool {
return $this->installationComplete;
}
@ -42,10 +46,11 @@ class Settings {
$settings->recaptchaPublicKey = "";
$settings->recaptchaPrivateKey = "";
$settings->recaptchaEnabled = false;
$settings->mailEnabled = false;
return $settings;
}
public function loadFromDatabase(User $user) {
public function loadFromDatabase(User $user): bool {
$req = new \Api\Settings\Get($user);
$success = $req->execute();
@ -58,6 +63,7 @@ class Settings {
$this->recaptchaEnabled = $result["recaptcha_enabled"] ?? $this->recaptchaEnabled;
$this->recaptchaPublicKey = $result["recaptcha_public_key"] ?? $this->recaptchaPublicKey;
$this->recaptchaPrivateKey = $result["recaptcha_private_key"] ?? $this->recaptchaPrivateKey;
$this->mailEnabled = $result["mail_enabled"] ?? $this->mailEnabled;
if (!isset($result["jwt_secret"])) {
$req = new \Api\Settings\Set($user);

@ -34,7 +34,7 @@ namespace Documents\Account {
$this->loadFontawesome();
}
protected function initMetas() {
protected function initMetas(): array {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
@ -44,11 +44,11 @@ namespace Documents\Account {
);
}
protected function initRawFields() {
protected function initRawFields(): array {
return array();
}
protected function initTitle() {
protected function initTitle(): string {
return "Account";
}
}
@ -59,7 +59,7 @@ namespace Documents\Account {
parent::__construct($document);
}
protected function getContent() {
protected function getContent(): string {
$view = $this->getDocument()->getView();
if ($view === null) {

@ -19,8 +19,6 @@ namespace Documents {
namespace Documents\Admin {
use Elements\Head;
use Elements\Link;
use Elements\Script;
class AdminHead extends Head {
@ -32,7 +30,7 @@ namespace Documents\Admin {
$this->loadFontawesome();
}
protected function initMetas() {
protected function initMetas(): array {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
@ -42,12 +40,12 @@ namespace Documents\Admin {
);
}
protected function initRawFields() {
protected function initRawFields(): array {
return array();
}
protected function initTitle() {
return "WebBase - Administration";
protected function initTitle(): string {
return $this->getSiteName() . " - Administration";
}
}
}

@ -15,7 +15,6 @@ namespace Documents {
namespace Documents\Document404 {
use Elements\Body;
use Elements\Head;
use Elements\SimpleBody;
use Views\View404;
@ -29,7 +28,7 @@ namespace Documents\Document404 {
protected function initSources() {
}
protected function initMetas() {
protected function initMetas(): array {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
@ -39,11 +38,11 @@ namespace Documents\Document404 {
);
}
protected function initRawFields() {
protected function initRawFields(): array {
return array();
}
protected function initTitle() {
protected function initTitle(): string {
return "WebBase - Not Found";
}
}
@ -58,7 +57,7 @@ namespace Documents\Document404 {
http_response_code(404);
}
protected function getContent() {
protected function getContent(): string {
return $this->load(View404::class);
}
}

@ -28,7 +28,7 @@ namespace Documents\Files {
$this->loadFontawesome();
}
protected function initMetas() {
protected function initMetas(): array {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
@ -39,11 +39,11 @@ namespace Documents\Files {
);
}
protected function initRawFields() {
protected function initRawFields(): array {
return array();
}
protected function initTitle() {
protected function initTitle(): string {
return "File Control Panel";
}
}
@ -54,7 +54,7 @@ namespace Documents\Files {
parent::__construct($document);
}
protected function getContent() {
protected function getContent(): string {
$html = "<noscript>" . $this->createErrorText("Javascript is required for this site to render.") . "</noscript>";
$html .= "<div id=\"root\"></div>";
$html .= new Script(Script::MIME_TEXT_JAVASCRIPT, Script::FILES);

@ -41,7 +41,7 @@ namespace Documents\Install {
$this->addJS(Script::INSTALL);
}
protected function initMetas() {
protected function initMetas(): array {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
@ -51,11 +51,11 @@ namespace Documents\Install {
);
}
protected function initRawFields() {
protected function initRawFields(): array {
return array();
}
protected function initTitle() {
protected function initTitle(): string {
return "WebBase - Installation";
}
@ -88,7 +88,7 @@ namespace Documents\Install {
$this->steps = array();
}
private function getParameter($name) {
private function getParameter($name): ?string {
if (isset($_REQUEST[$name]) && is_string($_REQUEST[$name])) {
return trim($_REQUEST[$name]);
}
@ -96,7 +96,7 @@ namespace Documents\Install {
return NULL;
}
private function getCurrentStep() {
private function getCurrentStep(): int {
if (!$this->checkRequirements()["success"]) {
return self::CHECKING_REQUIREMENTS;
@ -156,7 +156,7 @@ namespace Documents\Install {
return $step;
}
private function checkRequirements() {
private function checkRequirements(): array {
$msg = $this->errorString;
$success = true;
@ -191,7 +191,7 @@ namespace Documents\Install {
return array("success" => $success, "msg" => $msg);
}
private function databaseConfiguration() {
private function databaseConfiguration(): array {
$host = $this->getParameter("host");
$port = $this->getParameter("port");
@ -290,7 +290,7 @@ namespace Documents\Install {
return array("success" => $success, "msg" => $msg);
}
private function createUser() {
private function createUser(): array {
$user = $this->getDocument()->getUser();
if ($this->getParameter("prev") === "true") {
@ -347,7 +347,7 @@ namespace Documents\Install {
return array("msg" => $msg, "success" => $success);
}
private function addMailService() {
private function addMailService(): array {
$user = $this->getDocument()->getUser();
if ($this->getParameter("prev") === "true") {
@ -442,7 +442,7 @@ namespace Documents\Install {
return array("success" => $success, "msg" => $msg);
}
private function performStep() {
private function performStep(): array {
switch ($this->currentStep) {
@ -466,7 +466,7 @@ namespace Documents\Install {
}
}
private function createProgressSidebar() {
private function createProgressSidebar(): string {
$items = array();
foreach ($this->steps as $num => $step) {
@ -514,7 +514,7 @@ namespace Documents\Install {
return implode("", $items);
}
private function createFormItem($formItem, $inline=false) {
private function createFormItem($formItem, $inline = false): string {
$title = $formItem["title"];
$name = $formItem["name"];
@ -579,7 +579,7 @@ namespace Documents\Install {
}
}
private function createProgessMainview() {
private function createProgessMainview(): string {
$views = array(
self::CHECKING_REQUIREMENTS => array(
@ -732,7 +732,7 @@ namespace Documents\Install {
return $html;
}
function getCode() {
function getCode(): string {
$html = parent::getCode();
$this->steps = array(

@ -4,7 +4,7 @@ namespace Driver\SQL\Column;
class BoolColumn extends Column {
public function __construct($name, $defaultValue=false) {
public function __construct(string $name, bool $defaultValue = false) {
parent::__construct($name, false, $defaultValue);
}

@ -8,14 +8,14 @@ class Column {
private bool $nullable;
private $defaultValue;
public function __construct($name, $nullable = false, $defaultValue = NULL) {
public function __construct(string $name, bool $nullable = false, $defaultValue = NULL) {
$this->name = $name;
$this->nullable = $nullable;
$this->defaultValue = $defaultValue;
}
public function getName() { return $this->name; }
public function notNull() { return !$this->nullable; }
public function getName(): string { return $this->name; }
public function notNull(): bool { return !$this->nullable; }
public function getDefaultValue() { return $this->defaultValue; }
}

@ -4,7 +4,7 @@ namespace Driver\SQL\Column;
class DateTimeColumn extends Column {
public function __construct($name, $nullable=false, $defaultValue=NULL) {
public function __construct(string $name, bool $nullable = false, $defaultValue = NULL) {
parent::__construct($name, $nullable, $defaultValue);
}
}

@ -6,10 +6,10 @@ class EnumColumn extends Column {
private array $values;
public function __construct($name, $values, $nullable=false, $defaultValue=NULL) {
public function __construct(string $name, array $values, bool $nullable = false, $defaultValue = NULL) {
parent::__construct($name, $nullable, $defaultValue);
$this->values = $values;
}
public function getValues() { return $this->values; }
public function getValues(): array { return $this->values; }
}

@ -4,7 +4,7 @@ namespace Driver\SQL\Column;
class IntColumn extends Column {
public function __construct($name, $nullable=false, $defaultValue=NULL) {
public function __construct(string $name, bool $nullable = false, $defaultValue = NULL) {
parent::__construct($name, $nullable, $defaultValue);
}

@ -4,7 +4,7 @@ namespace Driver\SQL\Column;
class JsonColumn extends Column {
public function __construct($name, $nullable=false, $defaultValue=null) {
public function __construct(string $name, bool $nullable = false, $defaultValue = null) {
parent::__construct($name, $nullable, $defaultValue);
}

@ -4,7 +4,7 @@ namespace Driver\SQL\Column;
class SerialColumn extends Column {
public function __construct($name, $defaultValue=NULL) {
public function __construct(string $name, $defaultValue = NULL) {
parent::__construct($name, false, $defaultValue); # not nullable
}

@ -6,10 +6,10 @@ class StringColumn extends Column {
private ?int $maxSize;
public function __construct($name, $maxSize=null, $nullable=false, $defaultValue=null) {
public function __construct(string $name, ?int $maxSize = null, bool $nullable = false, $defaultValue = null) {
parent::__construct($name, $nullable, $defaultValue);
$this->maxSize = $maxSize;
}
public function getMaxSize() { return $this->maxSize; }
public function getMaxSize(): ?int { return $this->maxSize; }
}

@ -8,14 +8,14 @@ class Compare extends Condition {
private string $column;
private $value;
public function __construct($col, $val, $operator='=') {
public function __construct(string $col, $val, string $operator = '=') {
$this->operator = $operator;
$this->column = $col;
$this->value = $val;
}
public function getColumn() { return $this->column; }
public function getColumn(): string { return $this->column; }
public function getValue() { return $this->value; }
public function getOperator() { return $this->operator; }
public function getOperator(): string { return $this->operator; }
}

@ -10,5 +10,5 @@ class CondAnd extends Condition {
$this->conditions = $conditions;
}
public function getConditions() { return $this->conditions; }
public function getConditions(): array { return $this->conditions; }
}

@ -12,6 +12,6 @@ class CondIn extends Condition {
$this->expression = $expression;
}
public function getColumn() { return $this->column; }
public function getColumn(): string { return $this->column; }
public function getExpression() { return $this->expression; }
}

@ -8,7 +8,7 @@ abstract class CondKeyword extends Condition {
private $rightExpression;
private string $keyword;
public function __construct($keyword, $leftExpression, $rightExpression) {
public function __construct(string $keyword, $leftExpression, $rightExpression) {
$this->leftExpression = $leftExpression;
$this->rightExpression = $rightExpression;
$this->keyword = $keyword;
@ -16,5 +16,5 @@ abstract class CondKeyword extends Condition {
public function getLeftExp() { return $this->leftExpression; }
public function getRightExp() { return $this->rightExpression; }
public function getKeyword() { return $this->keyword; }
public function getKeyword(): string { return $this->keyword; }
}

@ -10,5 +10,5 @@ class CondNull extends Condition {
$this->column = $col;
}
public function getColumn() { return $this->column; }
public function getColumn(): string { return $this->column; }
}

@ -10,5 +10,5 @@ class CondOr extends Condition {
$this->conditions = (!empty($conditions) && is_array($conditions[0])) ? $conditions[0] : $conditions;
}
public function getConditions() { return $this->conditions; }
public function getConditions(): array { return $this->conditions; }
}

@ -10,5 +10,5 @@ abstract class Constraint {
$this->columnNames = (!is_array($columnNames) ? array($columnNames) : $columnNames);
}
public function getColumnNames() { return $this->columnNames; }
public function getColumnNames(): array { return $this->columnNames; }
}

@ -10,14 +10,14 @@ class ForeignKey extends Constraint {
private string $referencedColumn;
private ?Strategy $strategy;
public function __construct($name, $refTable, $refColumn, $strategy = NULL) {
public function __construct(string $name, string $refTable, string $refColumn, ?Strategy $strategy = NULL) {
parent::__construct($name);
$this->referencedTable = $refTable;
$this->referencedColumn = $refColumn;
$this->strategy = $strategy;
}
public function getReferencedTable() { return $this->referencedTable; }
public function getReferencedColumn() { return $this->referencedColumn; }
public function onDelete() { return $this->strategy; }
public function getReferencedTable(): string { return $this->referencedTable; }
public function getReferencedColumn(): string { return $this->referencedColumn; }
public function onDelete(): ?Strategy { return $this->strategy; }
}

@ -4,9 +4,10 @@ namespace Driver\SQL\Expression;
use Driver\SQL\Condition\Compare;
# TODO: change confusing class inheritance here
class Add extends Compare {
public function __construct($col, $val) {
public function __construct(string $col, $val) {
parent::__construct($col, $val, "+");
}

@ -8,9 +8,9 @@ class Join {
private string $table;
private string $columnA;
private string $columnB;
private $tableAlias;
private ?string $tableAlias;
public function __construct($type, $table, $columnA, $columnB, $tableAlias=null) {
public function __construct(string $type, string $table, string $columnA, string $columnB, ?string $tableAlias = null) {
$this->type = $type;
$this->table = $table;
$this->columnA = $columnA;
@ -18,10 +18,10 @@ class Join {
$this->tableAlias = $tableAlias;
}
public function getType() { return $this->type; }
public function getTable() { return $this->table; }
public function getColumnA() { return $this->columnA; }
public function getColumnB() { return $this->columnB; }
public function getTableAlias() { return $this->tableAlias; }
public function getType(): string { return $this->type; }
public function getTable(): string { return $this->table; }
public function getColumnA(): string { return $this->columnA; }
public function getColumnB(): string { return $this->columnB; }
public function getTableAlias(): ?string { return $this->tableAlias; }
}

@ -6,10 +6,10 @@ class Keyword {
private string $value;
public function __construct($value) {
public function __construct(string $value) {
$this->value = $value;
}
public function getValue() { return $this->value; }
public function getValue(): string { return $this->value; }
}

@ -13,6 +13,8 @@ use Driver\SQL\Column\JsonColumn;
use Driver\SQL\Constraint\PrimaryKey;
use Driver\SQL\Constraint\Unique;
use Driver\SQL\Constraint\ForeignKey;
use Driver\SQL\SQL;
use Driver\SQL\Strategy\Strategy;
class CreateTable extends Query {
@ -21,7 +23,7 @@ class CreateTable extends Query {
private array $constraints;
private bool $ifNotExists;
public function __construct($sql, $name) {
public function __construct(SQL $sql, string $name) {
parent::__construct($sql);
$this->tableName = $name;
$this->columns = array();
@ -29,67 +31,67 @@ class CreateTable extends Query {
$this->ifNotExists = false;
}
public function addSerial($name) {
public function addSerial(string $name): CreateTable {
$this->columns[$name] = new SerialColumn($name);
return $this;
}
public function addString($name, $maxSize=NULL, $nullable=false, $defaultValue=NULL) {
public function addString(string $name, ?int $maxSize = NULL, bool $nullable = false, $defaultValue = NULL): CreateTable {
$this->columns[$name] = new StringColumn($name, $maxSize, $nullable, $defaultValue);
return $this;
}
public function addDateTime($name, $nullable=false, $defaultValue=NULL) {
public function addDateTime(string $name, bool $nullable = false, $defaultValue = NULL): CreateTable {
$this->columns[$name] = new DateTimeColumn($name, $nullable, $defaultValue);
return $this;
}
public function addInt($name, $nullable=false, $defaultValue=NULL) {
public function addInt(string $name, bool $nullable = false, $defaultValue = NULL): CreateTable {
$this->columns[$name] = new IntColumn($name, $nullable, $defaultValue);
return $this;
}
public function addBool($name, $defaultValue=false) {
public function addBool(string $name, $defaultValue = false): CreateTable {
$this->columns[$name] = new BoolColumn($name, $defaultValue);
return $this;
}
public function addJson($name, $nullable=false, $defaultValue=NULL) {
public function addJson(string $name, bool $nullable = false, $defaultValue = NULL): CreateTable {
$this->columns[$name] = new JsonColumn($name, $nullable, $defaultValue);
return $this;
}
public function addEnum($name, $values, $nullable=false, $defaultValue=NULL) {
public function addEnum(string $name, array $values, bool $nullable = false, $defaultValue = NULL): CreateTable {
$this->columns[$name] = new EnumColumn($name, $values, $nullable, $defaultValue);
return $this;
}
public function primaryKey(...$names) {
public function primaryKey(...$names): CreateTable {
$this->constraints[] = new PrimaryKey($names);
return $this;
}
public function unique(...$names) {
public function unique(...$names): CreateTable {
$this->constraints[] = new Unique($names);
return $this;
}
public function foreignKey($name, $refTable, $refColumn, $strategy = NULL) {
public function foreignKey(string $name, string $refTable, string $refColumn, ?Strategy $strategy = NULL): CreateTable {
$this->constraints[] = new ForeignKey($name, $refTable, $refColumn, $strategy);
return $this;
}
public function onlyIfNotExists() {
public function onlyIfNotExists(): CreateTable {
$this->ifNotExists = true;
return $this;
}
public function execute() {
public function execute(): bool {
return $this->sql->executeCreateTable($this);
}
public function ifNotExists() { return $this->ifNotExists; }
public function getTableName() { return $this->tableName; }
public function getColumns() { return $this->columns; }
public function getConstraints() { return $this->constraints; }
public function ifNotExists(): bool { return $this->ifNotExists; }
public function getTableName(): string { return $this->tableName; }
public function getColumns(): array { return $this->columns; }
public function getConstraints(): array { return $this->constraints; }
}

@ -3,19 +3,20 @@
namespace Driver\SQL\Query;
use Driver\SQL\Condition\CondOr;
use Driver\SQL\SQL;
class Delete extends Query {
private string $table;
private array $conditions;
public function __construct($sql, $table) {
public function __construct(SQL $sql, string $table) {
parent::__construct($sql);
$this->table = $table;
$this->conditions = array();
}
public function where(...$conditions) {
public function where(...$conditions): Delete {
$this->conditions[] = (count($conditions) === 1 ? $conditions : new CondOr($conditions));
return $this;
}
@ -24,6 +25,6 @@ class Delete extends Query {
return $this->sql->executeDelete($this);
}
public function getTable() { return $this->table; }
public function getConditions() { return $this->conditions; }
public function getTable(): string { return $this->table; }
public function getConditions(): array { return $this->conditions; }
}

@ -14,16 +14,16 @@ class Drop extends Query {
* @param SQL $sql
* @param string $table
*/
public function __construct(\Driver\SQL\SQL $sql, string $table) {
public function __construct(SQL $sql, string $table) {
parent::__construct($sql);
$this->table = $table;
}
public function execute() {
$this->sql->executeDrop($this);
public function execute(): bool {
return $this->sql->executeDrop($this);
}
public function getTable() {
public function getTable(): string {
return $this->table;
}
}

@ -2,6 +2,7 @@
namespace Driver\SQL\Query;
use Driver\SQL\SQL;
use Driver\SQL\Strategy\Strategy;
class Insert extends Query {
@ -12,7 +13,7 @@ class Insert extends Query {
private ?Strategy $onDuplicateKey;
private ?string $returning;
public function __construct($sql, $name, $columns=array()) {
public function __construct(SQL $sql, string $name, array $columns = array()) {
parent::__construct($sql);
$this->tableName = $name;
$this->columns = $columns;
@ -21,28 +22,28 @@ class Insert extends Query {
$this->returning = NULL;
}
public function addRow(...$values) {
public function addRow(...$values): Insert {
$this->rows[] = $values;
return $this;
}
public function onDuplicateKeyStrategy($strategy) {
public function onDuplicateKeyStrategy(Strategy $strategy): Insert {
$this->onDuplicateKey = $strategy;
return $this;
}
public function returning($column) {
public function returning(string $column): Insert {
$this->returning = $column;
return $this;
}
public function execute() {
public function execute(): bool {
return $this->sql->executeInsert($this);
}
public function getTableName() { return $this->tableName; }
public function getColumns() { return $this->columns; }
public function getRows() { return $this->rows; }
public function onDuplicateKey() { return $this->onDuplicateKey; }
public function getReturning() { return $this->returning; }
public function getTableName(): string { return $this->tableName; }
public function getColumns(): array { return $this->columns; }
public function getRows(): array { return $this->rows; }
public function onDuplicateKey(): ?Strategy { return $this->onDuplicateKey; }
public function getReturning(): ?string { return $this->returning; }
}

@ -9,16 +9,16 @@ abstract class Query {
protected SQL $sql;
public bool $dump;
public function __construct($sql) {
public function __construct(SQL $sql) {
$this->sql = $sql;
$this->dump = false;
}
public function dump() {
public function dump(): Query {
$this->dump = true;
return $this;
}
public abstract function execute();
public abstract function execute(): bool;
}

@ -30,68 +30,68 @@ class Select extends Query {
$this->sortAscending = true;
}
public function from(...$tables) {
public function from(...$tables): Select {
$this->tables = array_merge($this->tables, $tables);
return $this;
}
public function where(...$conditions) {
public function where(...$conditions): Select {
$this->conditions[] = (count($conditions) === 1 ? $conditions : new CondOr($conditions));
return $this;
}
public function innerJoin($table, $columnA, $columnB, $tableAlias=null) {
public function innerJoin(string $table, string $columnA, string $columnB, ?string $tableAlias = null): Select {
$this->joins[] = new Join("INNER", $table, $columnA, $columnB, $tableAlias);
return $this;
}
public function leftJoin($table, $columnA, $columnB, $tableAlias=null) {
public function leftJoin(string $table, string $columnA, string $columnB, ?string $tableAlias = null): Select {
$this->joins[] = new Join("LEFT", $table, $columnA, $columnB, $tableAlias);
return $this;
}
public function groupBy(...$columns) {
public function groupBy(...$columns): Select {
$this->groupColumns = $columns;
return $this;
}
public function orderBy(...$columns) {
public function orderBy(...$columns): Select {
$this->orderColumns = $columns;
return $this;
}
public function ascending() {
public function ascending(): Select {
$this->sortAscending = true;
return $this;
}
public function descending() {
public function descending(): Select {
$this->sortAscending = false;
return $this;
}
public function limit($limit) {
public function limit(int $limit): Select {
$this->limit = $limit;
return $this;
}
public function offset($offset) {
public function offset(int $offset): Select {
$this->offset = $offset;
return $this;
}
public function execute() {
public function execute(): bool {
return $this->sql->executeSelect($this);
}
public function getColumns() { return $this->columns; }
public function getTables() { return $this->tables; }
public function getConditions() { return $this->conditions; }
public function getJoins() { return $this->joins; }
public function isOrderedAscending() { return $this->sortAscending; }
public function getOrderBy() { return $this->orderColumns; }
public function getLimit() { return $this->limit; }
public function getOffset() { return $this->offset; }
public function getGroupBy() { return $this->groupColumns; }
public function getColumns(): array { return $this->columns; }
public function getTables(): array { return $this->tables; }
public function getConditions(): array { return $this->conditions; }
public function getJoins(): array { return $this->joins; }
public function isOrderedAscending(): bool { return $this->sortAscending; }
public function getOrderBy(): array { return $this->orderColumns; }
public function getLimit(): int { return $this->limit; }
public function getOffset(): int { return $this->offset; }
public function getGroupBy(): array { return $this->groupColumns; }
}

@ -2,18 +2,20 @@
namespace Driver\SQL\Query;
use Driver\SQL\SQL;
class Truncate extends Query {
private string $tableName;
public function __construct($sql, $name) {
public function __construct(SQL $sql, string $name) {
parent::__construct($sql);
$this->tableName = $name;
}
public function execute() {
public function execute(): bool {
return $this->sql->executeTruncate($this);
}
public function getTable() { return $this->tableName; }
public function getTable(): string { return $this->tableName; }
}

@ -3,6 +3,7 @@
namespace Driver\SQL\Query;
use Driver\SQL\Condition\CondOr;
use Driver\SQL\SQL;
class Update extends Query {
@ -10,28 +11,28 @@ class Update extends Query {
private string $table;
private array $conditions;
public function __construct($sql, $table) {
public function __construct(SQL $sql, string $table) {
parent::__construct($sql);
$this->values = array();
$this->table = $table;
$this->conditions = array();
}
public function where(...$conditions) {
public function where(...$conditions): Update {
$this->conditions[] = (count($conditions) === 1 ? $conditions : new CondOr($conditions));
return $this;
}
public function set($key, $val) {
public function set(string $key, $val): Update {
$this->values[$key] = $val;
return $this;
}
public function execute() {
public function execute(): bool {
return $this->sql->executeUpdate($this);
}
public function getTable() { return $this->table; }
public function getConditions() { return $this->conditions; }
public function getValues() { return $this->values; }
public function getTable(): string { return $this->table; }
public function getConditions(): array { return $this->conditions; }
public function getValues(): array { return $this->values; }
}

@ -12,9 +12,11 @@ class UpdateStrategy extends Strategy {
$this->values = $values;
}
public function getConflictingColumns() {
public function getConflictingColumns(): array {
return $this->conflictingColumns;
}
public function getValues() { return $this->values; }
public function getValues(): array {
return $this->values;
}
}

@ -11,16 +11,16 @@ class EmptyHead extends Head {
protected function initSources() {
}
protected function initMetas() {
protected function initMetas(): array {
return array(
);
}
protected function initRawFields() {
protected function initRawFields(): array {
return array();
}
protected function initTitle() {
protected function initTitle(): string {
return "";
}
}

@ -24,9 +24,9 @@ abstract class Head extends View {
}
protected abstract function initSources();
protected abstract function initMetas();
protected abstract function initRawFields();
protected abstract function initTitle();
protected abstract function initMetas(): array;
protected abstract function initRawFields(): array;
protected abstract function initTitle(): string;
protected function init() {
$this->keywords = array();

@ -3,14 +3,15 @@
namespace Elements;
abstract class SimpleBody extends Body {
public function __construct($document) {
parent::__construct($document);
}
public function getCode() {
public function getCode(): string {
$content = $this->getContent();
return parent::getCode() . "<body>$content</body>";
}
protected abstract function getContent();
protected abstract function getContent(): string;
}

@ -7,23 +7,25 @@ abstract class View extends StaticView {
private Document $document;
private bool $loadView;
protected bool $searchable;
protected string $reference;
protected string $title;
protected array $langModules;
public function __construct(Document $document, $loadView = true) {
public function __construct(Document $document, bool $loadView = true) {
$this->document = $document;
$this->searchable = false;
$this->reference = "";
$this->title = "Untitled View";
$this->langModules = array();
$this->loadView = $loadView;
}
public function getTitle() { return $this->title; }
public function getDocument() { return $this->document; }
public function isSearchable() { return $this->searchable; }
public function getReference() { return $this->reference; }
public function getTitle(): string { return $this->title; }
public function getDocument(): Document { return $this->document; }
public function isSearchable(): bool { return $this->searchable; }
public function getSiteName(): string {
// what a chain lol
return $this->getDocument()->getUser()->getConfiguration()->getSettings()->getSiteName();
}
protected function load(string $viewClass) : string {
try {
@ -50,7 +52,7 @@ abstract class View extends StaticView {
// Virtual Methods
public function loadView() { }
public function getCode() {
public function getCode(): string {
// Load translations
$this->loadLanguageModules();
@ -64,33 +66,33 @@ abstract class View extends StaticView {
}
// UI Functions
private function createList($items, $tag) {
private function createList($items, $tag): string {
if(count($items) === 0)
return "<$tag></$tag>";
else
return "<$tag><li>" . implode("</li><li>", $items) . "</li></$tag>";
}
public function createOrderedList($items=array()) {
public function createOrderedList($items=array()): string {
return $this->createList($items, "ol");
}
public function createUnorderedList($items=array()) {
public function createUnorderedList($items=array()): string {
return $this->createList($items, "ul");
}
protected function createLink($link, $title=null, $classes="") {
protected function createLink($link, $title=null, $classes=""): string {
if(is_null($title)) $title=$link;
if(!empty($classes)) $classes = " class=\"$classes\"";
return "<a href=\"$link\"$classes>$title</a>";
}
protected function createExternalLink($link, $title=null) {
protected function createExternalLink($link, $title=null): string {
if(is_null($title)) $title=$link;
return "<a href=\"$link\" target=\"_blank\" class=\"external\">$title</a>";
}
protected function createIcon($icon, $type = "fas", $classes = "") {
protected function createIcon($icon, $type = "fas", $classes = ""): string {
$iconClass = "$type fa-$icon";
if($icon === "spinner" || $icon === "circle-notch")
@ -102,39 +104,39 @@ abstract class View extends StaticView {
return "<i class=\"$iconClass\" ></i>";
}
protected function createErrorText($text, $id="", $hidden=false) {
protected function createErrorText($text, $id="", $hidden=false): string {
return $this->createStatusText("danger", $text, $id, $hidden);
}
protected function createWarningText($text, $id="", $hidden=false) {
protected function createWarningText($text, $id="", $hidden=false): string {
return $this->createStatusText("warning", $text, $id, $hidden);
}
protected function createSuccessText($text, $id="", $hidden=false) {
protected function createSuccessText($text, $id="", $hidden=false): string {
return $this->createStatusText("success", $text, $id, $hidden);
}
protected function createSecondaryText($text, $id="", $hidden=false) {
protected function createSecondaryText($text, $id="", $hidden=false): string {
return $this->createStatusText("secondary", $text, $id, $hidden);
}
protected function createInfoText($text, $id="", $hidden=false) {
protected function createInfoText($text, $id="", $hidden=false): string {
return $this->createStatusText("info", $text, $id, $hidden);
}
protected function createStatusText($type, $text, $id="", $hidden=false, $classes="") {
protected function createStatusText($type, $text, $id="", $hidden=false, $classes=""): string {
if(strlen($id) > 0) $id = " id=\"$id\"";
if($hidden) $classes .= " hidden";
if(strlen($classes) > 0) $classes = " $classes";
return "<div class=\"alert alert-$type$hidden$classes\" role=\"alert\"$id>$text</div>";
}
protected function createBadge($type, $text) {
protected function createBadge($type, $text): string {
$text = htmlspecialchars($text);
return "<span class=\"badge badge-$type\">$text</span>";
}
protected function createJumbotron(string $content, bool $fluid=false, $class="") {
protected function createJumbotron(string $content, bool $fluid=false, $class=""): string {
$jumbotronClass = "jumbotron" . ($fluid ? "-fluid" : "");
if (!empty($class)) $jumbotronClass .= " $class";
@ -148,12 +150,12 @@ abstract class View extends StaticView {
</div>";
}
public function createSimpleParagraph(string $content, string $class="") {
public function createSimpleParagraph(string $content, string $class=""): string {
if($class) $class = " class=\"$class\"";
return "<p$class>$content</p>";
}
public function createParagraph($title, $id, $content) {
public function createParagraph($title, $id, $content): string {
$id = replaceCssSelector($id);
$iconId = urlencode("$id-icon");
return "
@ -166,7 +168,7 @@ abstract class View extends StaticView {
</div>";
}
protected function createBootstrapTable($data, string $classes="") {
protected function createBootstrapTable($data, string $classes=""): string {
$classes = empty($classes) ? "" : " $classes";
$code = "<div class=\"container$classes\">";
foreach($data as $row) {

@ -3,9 +3,6 @@
namespace Objects;
use Configuration\Configuration;
use DateTime;
use Driver\SQL\Expression\Add;
use Driver\SQL\Strategy\UpdateStrategy;
use Exception;
use External\JWT;
use Driver\SQL\SQL;
@ -52,19 +49,19 @@ class User extends ApiObject {
}
}
public function getId() { return $this->uid; }
public function isLoggedIn() { return $this->loggedIn; }
public function getUsername() { return $this->username; }
public function getEmail() { return $this->email; }
public function getSQL() { return $this->sql; }
public function getLanguage() { return $this->language; }
public function getId(): int { return $this->uid; }
public function isLoggedIn(): bool { return $this->loggedIn; }
public function getUsername(): string { return $this->username; }
public function getEmail(): ?string { return $this->email; }
public function getSQL(): ?SQL { return $this->sql; }
public function getLanguage(): Language { return $this->language; }
public function setLanguage(Language $language) { $this->language = $language; $language->load(); }
public function getSession() { return $this->session; }
public function getConfiguration() { return $this->configuration; }
public function getGroups() { return $this->groups; }
public function hasGroup(int $group) { return isset($this->groups[$group]); }
public function getSession(): ?Session { return $this->session; }
public function getConfiguration(): Configuration { return $this->configuration; }
public function getGroups(): array { return $this->groups; }
public function hasGroup(int $group): bool { return isset($this->groups[$group]); }
public function __debugInfo() {
public function __debugInfo(): array {
$debugInfo = array(
'loggedIn' => $this->loggedIn,
'language' => $this->language->getName(),
@ -78,7 +75,7 @@ class User extends ApiObject {
return $debugInfo;
}
public function jsonSerialize() {
public function jsonSerialize(): array {
if ($this->isLoggedIn()) {
return array(
'uid' => $this->uid,
@ -103,7 +100,7 @@ class User extends ApiObject {
$this->session = null;
}
public function logout() {
public function logout(): bool {
$success = true;
if($this->loggedIn) {
$success = $this->session->destroy();
@ -113,7 +110,7 @@ class User extends ApiObject {
return $success;
}
public function updateLanguage($lang) {
public function updateLanguage($lang): bool {
if($this->sql) {
$request = new \Api\Language\Set($this);
return $request->execute(array("langCode" => $lang));
@ -131,7 +128,13 @@ class User extends ApiObject {
session_write_close();
}
public function readData($userId, $sessionId, $sessionUpdate = true) {
/**
* @param $userId user's id
* @param $sessionId session's id
* @param bool $sessionUpdate update session information, including session's lifetime and browser information
* @return bool true, if the data could be loaded
*/
public function readData($userId, $sessionId, $sessionUpdate = true): bool {
$res = $this->sql->select("User.name", "User.email",
"Language.uid as langId", "Language.code as langCode", "Language.name as langName",
@ -203,7 +206,7 @@ class User extends ApiObject {
}
}
public function createSession($userId, $stayLoggedIn) {
public function createSession($userId, $stayLoggedIn): bool {
$this->uid = $userId;
$this->session = Session::create($this, $stayLoggedIn);
if ($this->session) {
@ -214,10 +217,11 @@ class User extends ApiObject {
return false;
}
public function authorize($apiKey) {
public function authorize($apiKey): bool {
if($this->loggedIn)
if ($this->loggedIn) {
return true;
}
$res = $this->sql->select("ApiKey.user_id as uid", "User.name", "User.email", "User.confirmed",
"Language.uid as langId", "Language.code as langCode", "Language.name as langName")
@ -264,7 +268,7 @@ class User extends ApiObject {
}
}
private function isBot() {
private function isBot(): bool {
if (!isset($_SERVER["HTTP_USER_AGENT"]) || empty($_SERVER["HTTP_USER_AGENT"])) {
return false;
}

@ -26,7 +26,7 @@ abstract class AccountView extends View {
}
}
public function getCode() {
public function getCode(): string {
$html = parent::getCode();
$content = $this->getAccountContent();

@ -11,7 +11,7 @@ class AdminDashboardBody extends Body {
parent::__construct($document);
}
public function getCode() {
public function getCode(): string {
$html = parent::getCode();
$script = new Script(Script::MIME_TEXT_JAVASCRIPT, "/js/admin.min.js");
$html .= "<body><div class=\"wrapper\" id=\"root\">$script</div></body>";

@ -24,7 +24,7 @@ class LoginBody extends Body {
$head->addCSS(Link::ACCOUNT);
}
public function getCode() {
public function getCode(): string {
$html = parent::getCode();
$username = L("Username");

@ -56,7 +56,7 @@ class LanguageFlags extends View {
}
}
public function getCode() {
public function getCode(): string {
return implode('', $this->languageFlags);
}
}

@ -6,7 +6,7 @@ use Elements\View;
class View404 extends View {
public function getCode() {
public function getCode(): string {
return parent::getCode() . "<b>Not found</b>";
}

@ -1,6 +1,6 @@
<?php
define("WEBBASE_VERSION", "1.2.1");
define("WEBBASE_VERSION", "1.2.2");
function getProtocol() {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";