Namespace and ClassPath rewrites

This commit is contained in:
Roman 2022-11-18 18:06:46 +01:00
parent c277aababc
commit 951ff14c5f
217 changed files with 1017 additions and 936 deletions

@ -9,7 +9,7 @@ RewriteRule ^(api(/.*)?)$ /index.php?api=$1 [L,QSA]
RewriteEngine On RewriteEngine On
RewriteOptions AllowNoSlash RewriteOptions AllowNoSlash
RewriteRule ^((\.idea|\.git|src|test|core|docker|files)(/.*)?)$ /index.php?site=$1 [L,QSA] RewriteRule ^((\.idea|\.git|src|test|Site|Core|docker|files)(/.*)?)$ /index.php?site=$1 [L,QSA]
FallbackResource /index.php FallbackResource /index.php

@ -1,9 +1,9 @@
<?php <?php
namespace Api { namespace Core\API {
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Objects\Context; use Core\Objects\Context;
abstract class ApiKeyAPI extends Request { abstract class ApiKeyAPI extends Request {
@ -33,14 +33,14 @@ namespace Api {
} }
} }
namespace Api\ApiKey { namespace Core\API\ApiKey {
use Api\ApiKeyAPI; use Core\API\ApiKeyAPI;
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondAnd; use Core\Driver\SQL\Condition\CondAnd;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\ApiKey; use Core\Objects\DatabaseEntity\ApiKey;
class Create extends ApiKeyAPI { class Create extends ApiKeyAPI {

@ -1,8 +1,8 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
abstract class ContactAPI extends Request { abstract class ContactAPI extends Request {
@ -15,7 +15,7 @@ namespace Api {
} }
protected function sendMail(string $name, ?string $fromEmail, string $subject, string $message, ?string $to = null): bool { protected function sendMail(string $name, ?string $fromEmail, string $subject, string $message, ?string $to = null): bool {
$request = new \Api\Mail\Send($this->context); $request = new \Core\API\Mail\Send($this->context);
$this->success = $request->execute(array( $this->success = $request->execute(array(
"subject" => $subject, "subject" => $subject,
"body" => $message, "body" => $message,
@ -34,17 +34,17 @@ namespace Api {
} }
} }
namespace Api\Contact { namespace Core\API\Contact {
use Api\ContactAPI; use Core\API\ContactAPI;
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Api\VerifyCaptcha; use Core\API\VerifyCaptcha;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondNot; use Core\Driver\SQL\Condition\CondNot;
use Driver\SQL\Expression\CaseWhen; use Core\Driver\SQL\Expression\CaseWhen;
use Driver\SQL\Expression\Sum; use Core\Driver\SQL\Expression\Sum;
use Objects\Context; use Core\Objects\Context;
class Request extends ContactAPI { class Request extends ContactAPI {

@ -1,9 +1,9 @@
<?php <?php
namespace Api { namespace Core\API {
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Objects\Context; use Core\Objects\Context;
abstract class GroupsAPI extends Request { abstract class GroupsAPI extends Request {
@ -25,13 +25,13 @@ namespace Api {
} }
} }
namespace Api\Groups { namespace Core\API\Groups {
use Api\GroupsAPI; use Core\API\GroupsAPI;
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\Group; use Core\Objects\DatabaseEntity\Group;
class Fetch extends GroupsAPI { class Fetch extends GroupsAPI {

@ -1,8 +1,8 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
abstract class LanguageAPI extends Request { abstract class LanguageAPI extends Request {
public function __construct(Context $context, bool $externalCall = false, array $params = array()) { public function __construct(Context $context, bool $externalCall = false, array $params = array()) {
@ -11,15 +11,15 @@ namespace Api {
} }
} }
namespace Api\Language { namespace Core\API\Language {
use Api\LanguageAPI; use Core\API\LanguageAPI;
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondOr; use Core\Driver\SQL\Condition\CondOr;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\Language; use Core\Objects\DatabaseEntity\Language;
class Get extends LanguageAPI { class Get extends LanguageAPI {

@ -1,8 +1,8 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
abstract class LogsAPI extends Request { abstract class LogsAPI extends Request {
public function __construct(Context $context, bool $externalCall = false, array $params = array()) { public function __construct(Context $context, bool $externalCall = false, array $params = array()) {
@ -12,17 +12,17 @@ namespace Api {
} }
namespace Api\Logs { namespace Core\API\Logs {
use Api\LogsAPI; use Core\API\LogsAPI;
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Driver\Logger\Logger; use Core\Driver\Logger\Logger;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondIn; use Core\Driver\SQL\Condition\CondIn;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\SystemLog; use Core\Objects\DatabaseEntity\SystemLog;
class Get extends LogsAPI { class Get extends LogsAPI {
@ -82,7 +82,7 @@ namespace Api\Logs {
} }
// get all log entries from filesystem (if database failed) // get all log entries from filesystem (if database failed)
$logPath = realpath(implode(DIRECTORY_SEPARATOR, [WEBROOT, "core", "Logs"])); $logPath = realpath(implode(DIRECTORY_SEPARATOR, [WEBROOT, "Core", "Logs"]));
if ($logPath) { if ($logPath) {
$index = 1; $index = 1;
foreach (scandir($logPath) as $fileName) { foreach (scandir($logPath) as $fileName) {

@ -1,9 +1,9 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\ConnectionData; use Core\Objects\ConnectionData;
use Objects\Context; use Core\Objects\Context;
abstract class MailAPI extends Request { abstract class MailAPI extends Request {
@ -12,7 +12,7 @@ namespace Api {
} }
protected function getMailConfig(): ?ConnectionData { protected function getMailConfig(): ?ConnectionData {
$req = new \Api\Settings\Get($this->context); $req = new \Core\API\Settings\Get($this->context);
$this->success = $req->execute(array("key" => "^mail_")); $this->success = $req->execute(array("key" => "^mail_"));
$this->lastError = $req->getLastError(); $this->lastError = $req->getLastError();
@ -40,19 +40,19 @@ namespace Api {
} }
} }
namespace Api\Mail { namespace Core\API\Mail {
use Api\MailAPI; use Core\API\MailAPI;
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use DateTimeInterface; use DateTimeInterface;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondIn; use Core\Driver\SQL\Condition\CondIn;
use External\PHPMailer\Exception; use Core\External\PHPMailer\Exception;
use External\PHPMailer\PHPMailer; use Core\External\PHPMailer\PHPMailer;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\GpgKey; use Core\Objects\DatabaseEntity\GpgKey;
class Test extends MailAPI { class Test extends MailAPI {
@ -66,7 +66,7 @@ namespace Api\Mail {
public function _execute(): bool { public function _execute(): bool {
$receiver = $this->getParam("receiver"); $receiver = $this->getParam("receiver");
$req = new \Api\Mail\Send($this->context); $req = new \Core\API\Mail\Send($this->context);
$this->success = $req->execute(array( $this->success = $req->execute(array(
"to" => $receiver, "to" => $receiver,
"subject" => "Test E-Mail", "subject" => "Test E-Mail",

@ -1,8 +1,8 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
abstract class NewsAPI extends Request { abstract class NewsAPI extends Request {
public function __construct(Context $context, bool $externalCall = false, array $params = array()) { public function __construct(Context $context, bool $externalCall = false, array $params = array()) {
@ -12,14 +12,14 @@ namespace Api {
} }
} }
namespace Api\News { namespace Core\API\News {
use Api\NewsAPI; use Core\API\NewsAPI;
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\News; use Core\Objects\DatabaseEntity\News;
class Get extends NewsAPI { class Get extends NewsAPI {

@ -1,8 +1,8 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
abstract class NotificationsAPI extends Request { abstract class NotificationsAPI extends Request {
public function __construct(Context $context, bool $externalCall = false, array $params = array()) { public function __construct(Context $context, bool $externalCall = false, array $params = array()) {
@ -11,19 +11,19 @@ namespace Api {
} }
} }
namespace Api\Notifications { namespace Core\API\Notifications {
use Api\NotificationsAPI; use Core\API\NotificationsAPI;
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondIn; use Core\Driver\SQL\Condition\CondIn;
use Driver\SQL\Query\Select; use Core\Driver\SQL\Query\Select;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\Group; use Core\Objects\DatabaseEntity\Group;
use Objects\DatabaseEntity\Notification; use Core\Objects\DatabaseEntity\Notification;
use Objects\DatabaseEntity\User; use Core\Objects\DatabaseEntity\User;
class Create extends NotificationsAPI { class Create extends NotificationsAPI {

@ -1,6 +1,6 @@
<?php <?php
namespace Api\Parameter; namespace Core\API\Parameter;
class ArrayType extends Parameter { class ArrayType extends Parameter {

@ -1,6 +1,6 @@
<?php <?php
namespace Api\Parameter; namespace Core\API\Parameter;
use DateTime; use DateTime;

@ -1,6 +1,6 @@
<?php <?php
namespace Api\Parameter; namespace Core\API\Parameter;
class StringType extends Parameter { class StringType extends Parameter {

@ -1,8 +1,8 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
abstract class PermissionAPI extends Request { abstract class PermissionAPI extends Request {
@ -21,20 +21,20 @@ namespace Api {
} }
} }
namespace Api\Permission { namespace Core\API\Permission {
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Api\PermissionAPI; use Core\API\PermissionAPI;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondIn; use Core\Driver\SQL\Condition\CondIn;
use Driver\SQL\Condition\CondLike; use Core\Driver\SQL\Condition\CondLike;
use Driver\SQL\Condition\CondNot; use Core\Driver\SQL\Condition\CondNot;
use Driver\SQL\Strategy\UpdateStrategy; use Core\Driver\SQL\Strategy\UpdateStrategy;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\Group; use Core\Objects\DatabaseEntity\Group;
use Objects\DatabaseEntity\User; use Core\Objects\DatabaseEntity\User;
class Check extends PermissionAPI { class Check extends PermissionAPI {

@ -1,9 +1,9 @@
<?php <?php
namespace Api; namespace Core\API;
use Driver\Logger\Logger; use Core\Driver\Logger\Logger;
use Objects\Context; use Core\Objects\Context;
use PhpMqtt\Client\MqttClient; use PhpMqtt\Client\MqttClient;
/** /**
@ -223,8 +223,8 @@ abstract class Request {
} }
// Check for permission // Check for permission
if (!($this instanceof \Api\Permission\Save)) { if (!($this instanceof \API\Permission\Save)) {
$req = new \Api\Permission\Check($this->context); $req = new \Core\API\Permission\Check($this->context);
$this->success = $req->execute(array("method" => $this->getMethod())); $this->success = $req->execute(array("method" => $this->getMethod()));
$this->lastError = $req->getLastError(); $this->lastError = $req->getLastError();
if (!$this->success) { if (!$this->success) {

@ -1,15 +1,15 @@
<?php <?php
namespace Api { namespace Core\API {
use Api\Routes\GenerateCache; use Core\API\Routes\GenerateCache;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Objects\Context; use Core\Objects\Context;
abstract class RoutesAPI extends Request { abstract class RoutesAPI extends Request {
const ACTIONS = array("redirect_temporary", "redirect_permanently", "static", "dynamic"); const ACTIONS = array("redirect_temporary", "redirect_permanently", "static", "dynamic");
const ROUTER_CACHE_CLASS = "\\Cache\\RouterCache"; const ROUTER_CACHE_CLASS = "\\Core\\Cache\\RouterCache";
protected string $routerCachePath; protected string $routerCachePath;
@ -61,18 +61,18 @@ namespace Api {
} }
} }
namespace Api\Routes { namespace Core\API\Routes {
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Api\RoutesAPI; use Core\API\RoutesAPI;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondBool; use Core\Driver\SQL\Condition\CondBool;
use Objects\Context; use Core\Objects\Context;
use Objects\Router\DocumentRoute; use Core\Objects\Router\DocumentRoute;
use Objects\Router\RedirectRoute; use Core\Objects\Router\RedirectRoute;
use Objects\Router\Router; use Core\Objects\Router\Router;
use Objects\Router\StaticFileRoute; use Core\Objects\Router\StaticFileRoute;
class Fetch extends RoutesAPI { class Fetch extends RoutesAPI {

@ -1,11 +1,11 @@
<?php <?php
namespace Api; namespace Core\API;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Objects\Context; use Core\Objects\Context;
use Objects\Search\Searchable; use Core\Objects\Search\Searchable;
use Objects\Search\SearchQuery; use Core\Objects\Search\SearchQuery;
class Search extends Request { class Search extends Request {

@ -1,8 +1,8 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
abstract class SettingsAPI extends Request { abstract class SettingsAPI extends Request {
public function __construct(Context $context, bool $externalCall = false, array $params = array()) { public function __construct(Context $context, bool $externalCall = false, array $params = array()) {
@ -11,18 +11,19 @@ namespace Api {
} }
} }
namespace Api\Settings { namespace Core\API\Settings {
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Api\SettingsAPI; use Core\API\SettingsAPI;
use Driver\SQL\Column\Column; use Core\Configuration\Settings;
use Driver\SQL\Condition\CondBool; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Condition\CondIn; use Core\Driver\SQL\Condition\CondBool;
use Driver\SQL\Condition\CondNot; use Core\Driver\SQL\Condition\CondIn;
use Driver\SQL\Condition\CondRegex; use Core\Driver\SQL\Condition\CondNot;
use Driver\SQL\Strategy\UpdateStrategy; use Core\Driver\SQL\Condition\CondRegex;
use Objects\Context; use Core\Driver\SQL\Strategy\UpdateStrategy;
use Core\Objects\Context;
class Get extends SettingsAPI { class Get extends SettingsAPI {
@ -161,4 +162,33 @@ namespace Api\Settings {
return $this->success; return $this->success;
} }
} }
class GenerateJWT extends SettingsAPI {
public function __construct(Context $context, bool $externalCall = false) {
parent::__construct($context, $externalCall, [
"type" => new StringType("type", 32, true, "HS512")
]);
}
protected function _execute(): bool {
$algorithm = $this->getParam("type");
if (!Settings::isJwtAlgorithmSupported($algorithm)) {
return $this->createError("Algorithm is not supported");
}
$settings = $this->context->getSettings();
if (!$settings->generateJwtKey($algorithm)) {
return $this->createError("Error generating JWT-Key: " . $settings->getLogger()->getLastMessage());
}
$saveRequest = $settings->saveJwtKey($this->context);
if (!$saveRequest->success()) {
return $this->createError("Error saving JWT-Key: " . $saveRequest->getLastError());
}
$this->result["jwt_public_key"] = $settings->getJwtPublicKey(false)?->getKeyMaterial();
return true;
}
}
} }

@ -1,12 +1,12 @@
<?php <?php
namespace Api; namespace Core\API;
use DateTime; use DateTime;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondBool; use Core\Driver\SQL\Condition\CondBool;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\User; use Core\Objects\DatabaseEntity\User;
class Stats extends Request { class Stats extends Request {
@ -38,7 +38,7 @@ class Stats extends Request {
} }
private function checkSettings(): bool { private function checkSettings(): bool {
$req = new \Api\Settings\Get($this->context); $req = new \Core\API\Settings\Get($this->context);
$this->success = $req->execute(array("key" => "^(mail_enabled|recaptcha_enabled)$")); $this->success = $req->execute(array("key" => "^(mail_enabled|recaptcha_enabled)$"));
$this->lastError = $req->getLastError(); $this->lastError = $req->getLastError();
@ -71,7 +71,7 @@ class Stats extends Request {
public function _execute(): bool { public function _execute(): bool {
$userCount = $this->getUserCount(); $userCount = $this->getUserCount();
$pageCount = $this->getPageCount(); $pageCount = $this->getPageCount();
$req = new \Api\Visitors\Stats($this->context); $req = new \Core\API\Visitors\Stats($this->context);
$this->success = $req->execute(array("type"=>"monthly")); $this->success = $req->execute(array("type"=>"monthly"));
$this->lastError = $req->getLastError(); $this->lastError = $req->getLastError();
if (!$this->success) { if (!$this->success) {

@ -1,10 +1,10 @@
<?php <?php
namespace Api; namespace Core\API;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\User; use Core\Objects\DatabaseEntity\User;
class Swagger extends Request { class Swagger extends Request {
@ -23,25 +23,32 @@ class Swagger extends Request {
// first load all direct classes // first load all direct classes
$classes = []; $classes = [];
$basePath = realpath(WEBROOT . "/core/Api/"); $apiDirs = ["Core", "Site"];
foreach (scandir($basePath) as $fileName) { foreach ($apiDirs as $apiDir) {
$fullPath = $basePath . "/" . $fileName; $basePath = realpath(WEBROOT . "/$apiDir/Api/");
if (is_file($fullPath) && endsWith($fileName, ".class.php")) { if (!$basePath) {
require_once $fullPath; continue;
$apiName = explode(".", $fileName)[0]; }
$className = "\\Api\\$apiName";
if (!class_exists($className)) {
var_dump("Class not exist: $className");
continue;
}
$reflection = new \ReflectionClass($className); foreach (scandir($basePath) as $fileName) {
if (!$reflection->isSubclassOf(Request::class) || $reflection->isAbstract()) { $fullPath = $basePath . "/" . $fileName;
continue; if (is_file($fullPath) && endsWith($fileName, ".class.php")) {
} require_once $fullPath;
$apiName = explode(".", $fileName)[0];
$className = "\\API\\$apiName";
if (!class_exists($className)) {
var_dump("Class not exist: $className");
continue;
}
$endpoint = "/" . strtolower($apiName); $reflection = new \ReflectionClass($className);
$classes[$endpoint] = $reflection; if (!$reflection->isSubclassOf(Request::class) || $reflection->isAbstract()) {
continue;
}
$endpoint = "/" . strtolower($apiName);
$classes[$endpoint] = $reflection;
}
} }
} }

@ -1,8 +1,8 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
abstract class TemplateAPI extends Request { abstract class TemplateAPI extends Request {
function __construct(Context $context, bool $externalCall = false, array $params = array()) { function __construct(Context $context, bool $externalCall = false, array $params = array()) {
@ -13,13 +13,13 @@ namespace Api {
} }
namespace Api\Template { namespace Core\API\Template {
use Api\Parameter\ArrayType; use Core\API\Parameter\ArrayType;
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Api\TemplateAPI; use Core\API\TemplateAPI;
use Objects\Context; use Core\Objects\Context;
use Twig\Environment; use Twig\Environment;
use Twig\Error\LoaderError; use Twig\Error\LoaderError;
use Twig\Error\RuntimeError; use Twig\Error\RuntimeError;
@ -45,8 +45,8 @@ namespace Api\Template {
return $this->createError("Invalid template file extension. Allowed: " . implode(",", $allowedExtensions)); return $this->createError("Invalid template file extension. Allowed: " . implode(",", $allowedExtensions));
} }
$templateDir = WEBROOT . "/core/Templates/"; $templateDir = WEBROOT . "/Core/Templates/";
$templateCache = WEBROOT . "/core/Cache/Templates/"; $templateCache = WEBROOT . "/Core/Cache/Templates/";
$path = realpath($templateDir . $templateFile); $path = realpath($templateDir . $templateFile);
if (!startsWith($path, realpath($templateDir))) { if (!startsWith($path, realpath($templateDir))) {
return $this->createError("Template file not in template directory"); return $this->createError("Template file not in template directory");

@ -1,10 +1,10 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
use Objects\TwoFactor\AuthenticationData; use Core\Objects\TwoFactor\AuthenticationData;
use Objects\TwoFactor\KeyBasedTwoFactorToken; use Core\Objects\TwoFactor\KeyBasedTwoFactorToken;
abstract class TfaAPI extends Request { abstract class TfaAPI extends Request {
@ -54,16 +54,16 @@ namespace Api {
} }
} }
namespace Api\TFA { namespace Core\API\TFA {
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Api\TfaAPI; use Core\API\TfaAPI;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Objects\Context; use Core\Objects\Context;
use Objects\TwoFactor\AttestationObject; use Core\Objects\TwoFactor\AttestationObject;
use Objects\TwoFactor\AuthenticationData; use Core\Objects\TwoFactor\AuthenticationData;
use Objects\TwoFactor\KeyBasedTwoFactorToken; use Core\Objects\TwoFactor\KeyBasedTwoFactorToken;
use Objects\TwoFactor\TimeBasedTwoFactorToken; use Core\Objects\TwoFactor\TimeBasedTwoFactorToken;
// General // General
class Remove extends TfaAPI { class Remove extends TfaAPI {
@ -110,7 +110,7 @@ namespace Api\TFA {
if ($this->success && $token->isConfirmed()) { if ($this->success && $token->isConfirmed()) {
// send an email // send an email
$settings = $this->context->getSettings(); $settings = $this->context->getSettings();
$req = new \Api\Template\Render($this->context); $req = new \Core\API\Template\Render($this->context);
$this->success = $req->execute([ $this->success = $req->execute([
"file" => "mail/2fa_remove.twig", "file" => "mail/2fa_remove.twig",
"parameters" => [ "parameters" => [
@ -123,7 +123,7 @@ namespace Api\TFA {
if ($this->success) { if ($this->success) {
$body = $req->getResult()["html"]; $body = $req->getResult()["html"];
$gpg = $currentUser->getGPG(); $gpg = $currentUser->getGPG();
$req = new \Api\Mail\Send($this->context); $req = new \Core\API\Mail\Send($this->context);
$this->success = $req->execute([ $this->success = $req->execute([
"to" => $currentUser->getEmail(), "to" => $currentUser->getEmail(),
"subject" => "[Security Lab] 2FA-Authentication removed", "subject" => "[Security Lab] 2FA-Authentication removed",

@ -1,11 +1,11 @@
<?php <?php
namespace Api { namespace Core\API {
use Cassandra\Date; use Cassandra\Date;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\Language; use Core\Objects\DatabaseEntity\Language;
abstract class UserAPI extends Request { abstract class UserAPI extends Request {
@ -77,7 +77,7 @@ namespace Api {
protected function insertUser($username, $email, $password, $confirmed, $fullName = "") { protected function insertUser($username, $email, $password, $confirmed, $fullName = "") {
$sql = $this->context->getSQL(); $sql = $this->context->getSQL();
$user = new \Objects\DatabaseEntity\User(); $user = new \Core\Objects\DatabaseEntity\User();
$user->language = Language::DEFAULT_LANGUAGE(false); $user->language = Language::DEFAULT_LANGUAGE(false);
$user->registeredAt = new \DateTime(); $user->registeredAt = new \DateTime();
$user->password = $this->hashPassword($password); $user->password = $this->hashPassword($password);
@ -151,27 +151,27 @@ namespace Api {
} }
namespace Api\User { namespace Core\API\User {
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Api\Template\Render; use Core\API\Template\Render;
use Api\UserAPI; use Core\API\UserAPI;
use Api\VerifyCaptcha; use Core\API\VerifyCaptcha;
use DateTime; use DateTime;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondBool; use Core\Driver\SQL\Condition\CondBool;
use Driver\SQL\Condition\CondIn; use Core\Driver\SQL\Condition\CondIn;
use Driver\SQL\Condition\CondNot; use Core\Driver\SQL\Condition\CondNot;
use Driver\SQL\Expression\JsonArrayAgg; use Core\Driver\SQL\Expression\JsonArrayAgg;
use ImagickException; use ImagickException;
use Objects\Context; use Core\Objects\Context;
use Objects\DatabaseEntity\DatabaseEntityHandler; use Core\Objects\DatabaseEntity\DatabaseEntityHandler;
use Objects\DatabaseEntity\GpgKey; use Core\Objects\DatabaseEntity\GpgKey;
use Objects\DatabaseEntity\TwoFactorToken; use Core\Objects\DatabaseEntity\TwoFactorToken;
use Objects\TwoFactor\KeyBasedTwoFactorToken; use Core\Objects\TwoFactor\KeyBasedTwoFactorToken;
use Objects\DatabaseEntity\User; use Core\Objects\DatabaseEntity\User;
class Create extends UserAPI { class Create extends UserAPI {
@ -534,7 +534,7 @@ namespace Api\User {
if ($this->success) { if ($this->success) {
$messageBody = $req->getResult()["html"]; $messageBody = $req->getResult()["html"];
$request = new \Api\Mail\Send($this->context); $request = new \Core\API\Mail\Send($this->context);
$this->success = $request->execute(array( $this->success = $request->execute(array(
"to" => $email, "to" => $email,
"subject" => "[$siteName] Account Invitation", "subject" => "[$siteName] Account Invitation",
@ -863,7 +863,7 @@ namespace Api\User {
if ($this->success) { if ($this->success) {
$messageBody = $req->getResult()["html"]; $messageBody = $req->getResult()["html"];
$request = new \Api\Mail\Send($this->context); $request = new \Core\API\Mail\Send($this->context);
$this->success = $request->execute(array( $this->success = $request->execute(array(
"to" => $email, "to" => $email,
"subject" => "[$siteName] E-Mail Confirmation", "subject" => "[$siteName] E-Mail Confirmation",
@ -1146,7 +1146,7 @@ namespace Api\User {
$gpgFingerprint = $user["gpg_fingerprint"]; $gpgFingerprint = $user["gpg_fingerprint"];
} }
$request = new \Api\Mail\Send($this->context); $request = new \Core\API\Mail\Send($this->context);
$this->success = $request->execute(array( $this->success = $request->execute(array(
"to" => $email, "to" => $email,
"subject" => "[$siteName] Password Reset", "subject" => "[$siteName] Password Reset",
@ -1272,7 +1272,7 @@ namespace Api\User {
if ($this->success) { if ($this->success) {
$messageBody = $req->getResult()["html"]; $messageBody = $req->getResult()["html"];
$request = new \Api\Mail\Send($this->context); $request = new \Core\API\Mail\Send($this->context);
$this->success = $request->execute(array( $this->success = $request->execute(array(
"to" => $email, "to" => $email,
"subject" => "[$siteName] E-Mail Confirmation", "subject" => "[$siteName] E-Mail Confirmation",
@ -1517,7 +1517,7 @@ namespace Api\User {
Best Regards<br> Best Regards<br>
ilum:e Security Lab"; ilum:e Security Lab";
$sendMail = new \Api\Mail\Send($this->context); $sendMail = new \Core\API\Mail\Send($this->context);
$this->success = $sendMail->execute(array( $this->success = $sendMail->execute(array(
"to" => $currentUser->getEmail(), "to" => $currentUser->getEmail(),
"subject" => "Security Lab - Confirm GPG-Key", "subject" => "Security Lab - Confirm GPG-Key",

@ -1,9 +1,9 @@
<?php <?php
namespace Api; namespace Core\API;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Objects\Context; use Core\Objects\Context;
class VerifyCaptcha extends Request { class VerifyCaptcha extends Request {

@ -1,8 +1,8 @@
<?php <?php
namespace Api { namespace Core\API {
use Objects\Context; use Core\Objects\Context;
abstract class VisitorsAPI extends Request { abstract class VisitorsAPI extends Request {
public function __construct(Context $context, bool $externalCall = false, array $params = []) { public function __construct(Context $context, bool $externalCall = false, array $params = []) {
@ -11,17 +11,17 @@ namespace Api {
} }
} }
namespace Api\Visitors { namespace Core\API\Visitors {
use Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Api\Parameter\StringType; use Core\API\Parameter\StringType;
use Api\VisitorsAPI; use Core\API\VisitorsAPI;
use DateTime; use DateTime;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Expression\Add; use Core\Driver\SQL\Expression\Add;
use Driver\SQL\Query\Select; use Core\Driver\SQL\Query\Select;
use Driver\SQL\Strategy\UpdateStrategy; use Core\Driver\SQL\Strategy\UpdateStrategy;
use Objects\Context; use Core\Objects\Context;
class ProcessVisit extends VisitorsAPI { class ProcessVisit extends VisitorsAPI {
public function __construct(Context $context, bool $externalCall = false) { public function __construct(Context $context, bool $externalCall = false) {

3
Core/Cache/.gitignore vendored Normal file

@ -0,0 +1,3 @@
*
!.gitkeep
!.gitignore

@ -1,11 +1,12 @@
<?php <?php
namespace Configuration; namespace Core\Configuration;
use Objects\ConnectionData; use Core\Objects\ConnectionData;
class Configuration { class Configuration {
const className = "\Site\Configuration\Database";
private ?ConnectionData $database; private ?ConnectionData $database;
private Settings $settings; private Settings $settings;
@ -13,12 +14,12 @@ class Configuration {
$this->database = null; $this->database = null;
$this->settings = Settings::loadDefaults(); $this->settings = Settings::loadDefaults();
$class = \Configuration\Database::class; $className = self::className;
$path = getClassPath($class, ".class"); $path = getClassPath($className, ".class");
if (file_exists($path) && is_readable($path)) { if (file_exists($path) && is_readable($path)) {
include_once $path; include_once $path;
if (class_exists($class)) { if (class_exists($className)) {
$this->database = new \Configuration\Database(); $this->database = new $className();
} }
} }
} }
@ -32,7 +33,9 @@ class Configuration {
} }
public static function create(string $className, $data) { public static function create(string $className, $data) {
$path = getClassPath("\\Configuration\\$className"); $path = getClassPath($className);
$classNameShort = explode("\\", $className);
$classNameShort = end($classNameShort);
if ($data) { if ($data) {
if (is_string($data)) { if (is_string($data)) {
@ -40,9 +43,9 @@ class Configuration {
$code = intendCode( $code = intendCode(
"<?php "<?php
namespace Configuration; namespace Core\Configuration;
class $className extends KeyData { class $classNameShort extends KeyData {
public function __construct() { public function __construct() {
parent::__construct($key); parent::__construct($key);
@ -67,9 +70,9 @@ class Configuration {
$code = intendCode( $code = intendCode(
"<?php "<?php
namespace Configuration; namespace Site\Configuration;
class $className extends \\$superClass { class $classNameShort extends \\$superClass {
public function __construct() { public function __construct() {
parent::__construct($host, $port, $login, $password);$properties parent::__construct($host, $port, $login, $password);$properties
@ -95,7 +98,7 @@ class Configuration {
return true; return true;
} }
public function setDatabase(ConnectionData $connectionData) { public function setDatabase(ConnectionData $connectionData): void {
$this->database = $connectionData; $this->database = $connectionData;
} }
} }

@ -1,11 +1,11 @@
<?php <?php
namespace Configuration; namespace Core\Configuration;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
use \Driver\SQL\Strategy\SetNullStrategy; use Core\Driver\SQL\Strategy\SetNullStrategy;
use \Driver\SQL\Strategy\CascadeStrategy; use Core\Driver\SQL\Strategy\CascadeStrategy;
use Objects\DatabaseEntity\DatabaseEntity; use Core\Objects\DatabaseEntity\DatabaseEntity;
use PHPUnit\Util\Exception; use PHPUnit\Util\Exception;
class CreateDatabase extends DatabaseScript { class CreateDatabase extends DatabaseScript {
@ -73,14 +73,14 @@ class CreateDatabase extends DatabaseScript {
->unique("request"); ->unique("request");
$queries[] = $sql->insert("Route", ["request", "action", "target", "extra", "exact"]) $queries[] = $sql->insert("Route", ["request", "action", "target", "extra", "exact"])
->addRow("/admin", "dynamic", "\\Documents\\Admin", NULL, false) ->addRow("/admin", "dynamic", "\\Core\\Documents\\Admin", NULL, false)
->addRow("/register", "dynamic", "\\Documents\\Account", json_encode(["account/register.twig"]), true) ->addRow("/register", "dynamic", "\\Core\\Documents\\Account", json_encode(["account/register.twig"]), true)
->addRow("/confirmEmail", "dynamic", "\\Documents\\Account", json_encode(["account/confirm_email.twig"]), true) ->addRow("/confirmEmail", "dynamic", "\\Core\\Documents\\Account", json_encode(["account/confirm_email.twig"]), true)
->addRow("/acceptInvite", "dynamic", "\\Documents\\Account", json_encode(["account/accept_invite.twig"]), true) ->addRow("/acceptInvite", "dynamic", "\\Core\\Documents\\Account", json_encode(["account/accept_invite.twig"]), true)
->addRow("/resetPassword", "dynamic", "\\Documents\\Account", json_encode(["account/reset_password.twig"]), true) ->addRow("/resetPassword", "dynamic", "\\Core\\Documents\\Account", json_encode(["account/reset_password.twig"]), true)
->addRow("/login", "dynamic", "\\Documents\\Account", json_encode(["account/login.twig"]), true) ->addRow("/login", "dynamic", "\\Core\\Documents\\Account", json_encode(["account/login.twig"]), true)
->addRow("/resendConfirmEmail", "dynamic", "\\Documents\\Account", json_encode(["account/resend_confirm_email.twig"]), true) ->addRow("/resendConfirmEmail", "dynamic", "\\Core\\Documents\\Account", json_encode(["account/resend_confirm_email.twig"]), true)
->addRow("/debug", "dynamic", "\\Documents\\Info", NULL, true) ->addRow("/debug", "dynamic", "\\Core\\Documents\\Info", NULL, true)
->addRow("/", "static", "/static/welcome.html", NULL, true); ->addRow("/", "static", "/static/welcome.html", NULL, true);
$queries[] = $sql->createTable("Settings") $queries[] = $sql->createTable("Settings")
@ -141,12 +141,13 @@ class CreateDatabase extends DatabaseScript {
->addString("replyTo", 64, true) ->addString("replyTo", 64, true)
->addString("replyName", 32, true) ->addString("replyName", 32, true)
->addString("gpgFingerprint", 64, true) ->addString("gpgFingerprint", 64, true)
->addEnum("status", ["waiting","success","error"], false, 'waiting') ->addEnum("status", ["waiting", "success", "error"], false, 'waiting')
->addInt("retryCount", false, 5) ->addInt("retryCount", false, 5)
->addDateTime("nextTry", false, $sql->now()) ->addDateTime("nextTry", false, $sql->now())
->addString("errorMessage", NULL, true) ->addString("errorMessage", NULL, true)
->primaryKey("id"); ->primaryKey("id");
$queries = array_merge($queries, \Configuration\Patch\EntityLog_2021_04_08::createTableLog($sql, "MailQueue", 30));
$queries = array_merge($queries, \Core\Configuration\Patch\EntityLog_2021_04_08::createTableLog($sql, "MailQueue", 30));
$queries[] = $sql->insert("ApiPermission", array("method", "groups", "description")) $queries[] = $sql->insert("ApiPermission", array("method", "groups", "description"))
->addRow("ApiKey/create", array(), "Allows users to create API-Keys for themselves") ->addRow("ApiKey/create", array(), "Allows users to create API-Keys for themselves")
@ -181,40 +182,46 @@ class CreateDatabase extends DatabaseScript {
} }
private static function loadPatches(&$queries, $sql) { private static function loadPatches(&$queries, $sql) {
$patchDirectory = './core/Configuration/Patch/'; $baseDirs = ["Core", "Site"];
if (file_exists($patchDirectory) && is_dir($patchDirectory)) { foreach ($baseDirs as $baseDir) {
$scan_arr = scandir($patchDirectory); $patchDirectory = "./$baseDir/Configuration/Patch/";
$files_arr = array_diff($scan_arr, array('.', '..')); if (file_exists($patchDirectory) && is_dir($patchDirectory)) {
foreach ($files_arr as $file) { $scan_arr = scandir($patchDirectory);
$suffix = ".class.php"; $files_arr = array_diff($scan_arr, array('.', '..'));
if (endsWith($file, $suffix)) { foreach ($files_arr as $file) {
$className = substr($file, 0, strlen($file) - strlen($suffix)); $suffix = ".class.php";
$className = "\\Configuration\\Patch\\$className"; if (endsWith($file, $suffix)) {
$method = "$className::createQueries"; $className = substr($file, 0, strlen($file) - strlen($suffix));
$patchQueries = call_user_func($method, $sql); $className = "\\$baseDir\\Configuration\\Patch\\$className";
foreach ($patchQueries as $query) $queries[] = $query; $method = "$className::createQueries";
$patchQueries = call_user_func($method, $sql);
foreach ($patchQueries as $query) $queries[] = $query;
}
} }
} }
} }
} }
public static function loadEntities(&$queries, $sql) { public static function loadEntities(&$queries, $sql) {
$entityDirectory = './core/Objects/DatabaseEntity/'; $handlers = [];
if (file_exists($entityDirectory) && is_dir($entityDirectory)) { $baseDirs = ["Core", "Site"];
$scan_arr = scandir($entityDirectory); foreach ($baseDirs as $baseDir) {
$files_arr = array_diff($scan_arr, array('.', '..')); $entityDirectory = "./$baseDir/Objects/DatabaseEntity/";
$handlers = []; if (file_exists($entityDirectory) && is_dir($entityDirectory)) {
foreach ($files_arr as $file) { $scan_arr = scandir($entityDirectory);
$suffix = ".class.php"; $files_arr = array_diff($scan_arr, array('.', '..'));
if (endsWith($file, $suffix)) { foreach ($files_arr as $file) {
$className = substr($file, 0, strlen($file) - strlen($suffix)); $suffix = ".class.php";
if (!in_array($className, ["DatabaseEntity", "DatabaseEntityQuery", "DatabaseEntityHandler"])) { if (endsWith($file, $suffix)) {
$className = "\\Objects\\DatabaseEntity\\$className"; $className = substr($file, 0, strlen($file) - strlen($suffix));
$reflectionClass = new \ReflectionClass($className); if (!in_array($className, ["DatabaseEntity", "DatabaseEntityQuery", "DatabaseEntityHandler"])) {
if ($reflectionClass->isSubclassOf(DatabaseEntity::class)) { $className = "\\$baseDir\\Objects\\DatabaseEntity\\$className";
$method = "$className::getHandler"; $reflectionClass = new \ReflectionClass($className);
$handler = call_user_func($method, $sql); if ($reflectionClass->isSubclassOf(DatabaseEntity::class)) {
$handlers[$handler->getTableName()] = $handler; $method = "$className::getHandler";
$handler = call_user_func($method, $sql);
$handlers[$handler->getTableName()] = $handler;
}
} }
} }
} }

@ -1,8 +1,8 @@
<?php <?php
namespace Configuration; namespace Core\Configuration;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
abstract class DatabaseScript { abstract class DatabaseScript {
public static abstract function createQueries(SQL $sql); public static abstract function createQueries(SQL $sql);

@ -1,15 +1,15 @@
<?php <?php
namespace Configuration\Patch; namespace Core\Configuration\Patch;
use Configuration\DatabaseScript; use Core\Configuration\DatabaseScript;
use Driver\SQL\Column\IntColumn; use Core\Driver\SQL\Column\IntColumn;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Query\CreateProcedure; use Core\Driver\SQL\Query\CreateProcedure;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
use Driver\SQL\Type\CurrentColumn; use Core\Driver\SQL\Type\CurrentColumn;
use Driver\SQL\Type\CurrentTable; use Core\Driver\SQL\Type\CurrentTable;
use Driver\SQL\Type\Trigger; use Core\Driver\SQL\Type\Trigger;
class EntityLog_2021_04_08 extends DatabaseScript { class EntityLog_2021_04_08 extends DatabaseScript {

@ -1,9 +1,9 @@
<?php <?php
namespace Configuration\Patch; namespace Core\Configuration\Patch;
use Configuration\DatabaseScript; use Core\Configuration\DatabaseScript;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class SystemLog_2022_03_30 extends DatabaseScript { class SystemLog_2022_03_30 extends DatabaseScript {

@ -4,11 +4,11 @@
* Do not change settings here, they are dynamically loaded from database. * Do not change settings here, they are dynamically loaded from database.
*/ */
namespace Configuration; namespace Core\Configuration;
use Driver\Logger\Logger; use Core\Driver\Logger\Logger;
use Driver\SQL\Query\Insert; use Core\Driver\SQL\Query\Insert;
use Objects\Context; use Core\Objects\Context;
class Settings { class Settings {
@ -18,8 +18,8 @@ class Settings {
// settings // settings
private string $siteName; private string $siteName;
private string $baseUrl; private string $baseUrl;
private string $jwtPublicKey; private ?string $jwtPublicKey;
private string $jwtSecretKey; private ?string $jwtSecretKey;
private string $jwtAlgorithm; private string $jwtAlgorithm;
private bool $registrationAllowed; private bool $registrationAllowed;
private bool $recaptchaEnabled; private bool $recaptchaEnabled;
@ -37,8 +37,13 @@ class Settings {
$this->logger = new Logger("Settings"); $this->logger = new Logger("Settings");
} }
public function getJwtPublicKey(): \Firebase\JWT\Key { public function getJwtPublicKey(bool $allowPrivate = true): ?\Firebase\JWT\Key {
return new \Firebase\JWT\Key($this->jwtPublicKey ?? $this->jwtSecretKey, $this->jwtAlgorithm); if (empty($this->jwtPublicKey)) {
// we might have a symmetric key, should we instead return the private key?
return $allowPrivate ? new \Firebase\JWT\Key($this->jwtSecretKey, $this->jwtAlgorithm) : null;
} else {
return new \Firebase\JWT\Key($this->jwtPublicKey, $this->jwtAlgorithm);
}
} }
public function getJwtSecretKey(): \Firebase\JWT\Key { public function getJwtSecretKey(): \Firebase\JWT\Key {
@ -109,18 +114,24 @@ class Settings {
return true; return true;
} }
public static function isJwtAlgorithmSupported(string $algorithm): bool {
return in_array(strtoupper($algorithm), ["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "EDDSA"]);
}
public function saveJwtKey(Context $context) { public function saveJwtKey(Context $context) {
$req = new \Api\Settings\Set($context); $req = new \Core\API\Settings\Set($context);
$req->execute(array("settings" => array( $req->execute(array("settings" => array(
"jwt_secret_key" => $this->jwtSecretKey, "jwt_secret_key" => $this->jwtSecretKey,
"jwt_public_key" => $this->jwtSecretKey, "jwt_public_key" => $this->jwtSecretKey,
"jwt_algorithm" => $this->jwtAlgorithm, "jwt_algorithm" => $this->jwtAlgorithm,
))); )));
return $req;
} }
public function loadFromDatabase(Context $context): bool { public function loadFromDatabase(Context $context): bool {
$this->logger = new Logger("Settings", $context->getSQL()); $this->logger = new Logger("Settings", $context->getSQL());
$req = new \Api\Settings\Get($context); $req = new \Core\API\Settings\Get($context);
$success = $req->execute(); $success = $req->execute();
if ($success) { if ($success) {
@ -203,4 +214,8 @@ class Settings {
public function getDomain(): string { public function getDomain(): string {
return parse_url($this->getBaseUrl(), PHP_URL_HOST); return parse_url($this->getBaseUrl(), PHP_URL_HOST);
} }
public function getLogger(): Logger {
return $this->logger;
}
} }

@ -1,10 +1,10 @@
<?php <?php
namespace Documents; namespace Core\Documents;
use Elements\TemplateDocument; use Core\Elements\TemplateDocument;
use Objects\Router\Router; use Core\Objects\Router\Router;
class Account extends TemplateDocument { class Account extends TemplateDocument {
@ -25,7 +25,7 @@ class Account extends TemplateDocument {
if ($this->getTemplateName() === "account/reset_password.twig") { if ($this->getTemplateName() === "account/reset_password.twig") {
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) { if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) {
$this->parameters["view"]["token"] = $_GET["token"]; $this->parameters["view"]["token"] = $_GET["token"];
$req = new \Api\User\CheckToken($this->getContext()); $req = new \Core\API\User\CheckToken($this->getContext());
$this->parameters["view"]["success"] = $req->execute(array("token" => $_GET["token"])); $this->parameters["view"]["success"] = $req->execute(array("token" => $_GET["token"]));
if ($this->parameters["view"]["success"]) { if ($this->parameters["view"]["success"]) {
if (strcmp($req->getResult()["token"]["type"], "password_reset") !== 0) { if (strcmp($req->getResult()["token"]["type"], "password_reset") !== 0) {
@ -48,7 +48,7 @@ class Account extends TemplateDocument {
} else if ($this->getTemplateName() === "account/accept_invite.twig") { } else if ($this->getTemplateName() === "account/accept_invite.twig") {
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) { if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_GET["token"])) {
$this->parameters["view"]["token"] = $_GET["token"]; $this->parameters["view"]["token"] = $_GET["token"];
$req = new \Api\User\CheckToken($this->getContext()); $req = new \Core\API\User\CheckToken($this->getContext());
$this->parameters["view"]["success"] = $req->execute(array("token" => $_GET["token"])); $this->parameters["view"]["success"] = $req->execute(array("token" => $_GET["token"]));
if ($this->parameters["view"]["success"]) { if ($this->parameters["view"]["success"]) {
if (strcmp($req->getResult()["token"]["type"], "invite") !== 0) { if (strcmp($req->getResult()["token"]["type"], "invite") !== 0) {

@ -1,9 +1,9 @@
<?php <?php
namespace Documents; namespace Core\Documents;
use Elements\TemplateDocument; use Core\Elements\TemplateDocument;
use Objects\Router\Router; use Core\Objects\Router\Router;
class Admin extends TemplateDocument { class Admin extends TemplateDocument {
public function __construct(Router $router) { public function __construct(Router $router) {

@ -1,11 +1,11 @@
<?php <?php
namespace Documents; namespace Core\Documents;
use Elements\EmptyHead; use Core\Elements\EmptyHead;
use Elements\HtmlDocument; use Core\Elements\HtmlDocument;
use Elements\SimpleBody; use Core\Elements\SimpleBody;
use Objects\Router\Router; use Core\Objects\Router\Router;
class Info extends HtmlDocument { class Info extends HtmlDocument {
public function __construct(Router $router) { public function __construct(Router $router) {

@ -1,11 +1,11 @@
<?php <?php
namespace Documents { namespace Core\Documents {
use Documents\Install\InstallBody; use Documents\Install\InstallBody;
use Documents\Install\InstallHead; use Documents\Install\InstallHead;
use Elements\HtmlDocument; use Core\Elements\HtmlDocument;
use Objects\Router\Router; use Core\Objects\Router\Router;
class Install extends HtmlDocument { class Install extends HtmlDocument {
public function __construct(Router $router) { public function __construct(Router $router) {
@ -17,19 +17,19 @@ namespace Documents {
namespace Documents\Install { namespace Documents\Install {
use Configuration\Configuration; use Core\Configuration\Configuration;
use Configuration\CreateDatabase; use Core\Configuration\CreateDatabase;
use Driver\SQL\Query\Commit; use Core\Driver\SQL\Query\Commit;
use Driver\SQL\Query\RollBack; use Core\Driver\SQL\Query\RollBack;
use Driver\SQL\Query\StartTransaction; use Core\Driver\SQL\Query\StartTransaction;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
use Elements\Body; use Core\Elements\Body;
use Elements\Head; use Core\Elements\Head;
use Elements\Link; use Core\Elements\Link;
use Elements\Script; use Core\Elements\Script;
use External\PHPMailer\Exception; use Core\External\PHPMailer\Exception;
use External\PHPMailer\PHPMailer; use Core\External\PHPMailer\PHPMailer;
use Objects\ConnectionData; use Core\Objects\ConnectionData;
class InstallHead extends Head { class InstallHead extends Head {
@ -131,9 +131,9 @@ namespace Documents\Install {
private function getExternalDirectory(bool $absolute = true): string { private function getExternalDirectory(bool $absolute = true): string {
if ($absolute) { if ($absolute) {
return implode(DIRECTORY_SEPARATOR, [WEBROOT, "core", "External"]);; return implode(DIRECTORY_SEPARATOR, [WEBROOT, "Core", "External"]);
} else { } else {
return implode(DIRECTORY_SEPARATOR, ["core", "External"]); return implode(DIRECTORY_SEPARATOR, ["Core", "External"]);
} }
} }
@ -185,7 +185,7 @@ namespace Documents\Install {
} }
if ($step === self::ADD_MAIL_SERVICE) { if ($step === self::ADD_MAIL_SERVICE) {
$req = new \Api\Settings\Get($context); $req = new \Core\API\Settings\Get($context);
$success = $req->execute(array("key" => "^mail_enabled$")); $success = $req->execute(array("key" => "^mail_enabled$"));
if (!$success) { if (!$success) {
$this->errorString = $req->getLastError(); $this->errorString = $req->getLastError();
@ -193,12 +193,12 @@ namespace Documents\Install {
} else if (isset($req->getResult()["settings"]["mail_enabled"])) { } else if (isset($req->getResult()["settings"]["mail_enabled"])) {
$step = self::FINISH_INSTALLATION; $step = self::FINISH_INSTALLATION;
$req = new \Api\Settings\Set($context); $req = new \Core\API\Settings\Set($context);
$success = $req->execute(array("settings" => array("installation_completed" => "1"))); $success = $req->execute(array("settings" => array("installation_completed" => "1")));
if (!$success) { if (!$success) {
$this->errorString = $req->getLastError(); $this->errorString = $req->getLastError();
} else { } else {
$req = new \Api\Notifications\Create($context); $req = new \Core\API\Notifications\Create($context);
$req->execute(array( $req->execute(array(
"title" => "Welcome", "title" => "Welcome",
"message" => "Your Web-base was successfully installed. Check out the admin dashboard. Have fun!", "message" => "Your Web-base was successfully installed. Check out the admin dashboard. Have fun!",
@ -369,7 +369,7 @@ namespace Documents\Install {
if ($success) { if ($success) {
$context = $this->getDocument()->getContext(); $context = $this->getDocument()->getContext();
$config = $context->getConfig(); $config = $context->getConfig();
if (Configuration::create("Database", $connectionData) === false) { if (Configuration::create(\Site\Configuration\Database::class, $connectionData) === false) {
$success = false; $success = false;
$msg = "Unable to write database file"; $msg = "Unable to write database file";
} else { } else {
@ -378,7 +378,7 @@ namespace Documents\Install {
$success = false; $success = false;
$msg = "Unable to verify database connection after installation"; $msg = "Unable to verify database connection after installation";
} else { } else {
$req = new \Api\Routes\GenerateCache($context); $req = new \Core\API\Routes\GenerateCache($context);
if (!$req->execute()) { if (!$req->execute()) {
$success = false; $success = false;
$msg = "Unable to write route file: " . $req->getLastError(); $msg = "Unable to write route file: " . $req->getLastError();
@ -430,7 +430,7 @@ namespace Documents\Install {
$msg = "Please fill out the following inputs:<br>" . $msg = "Please fill out the following inputs:<br>" .
$this->createUnorderedList($missingInputs); $this->createUnorderedList($missingInputs);
} else { } else {
$req = new \Api\User\Create($context); $req = new \Core\API\User\Create($context);
$success = $req->execute(array( $success = $req->execute(array(
'username' => $username, 'username' => $username,
'email' => $email, 'email' => $email,
@ -462,7 +462,7 @@ namespace Documents\Install {
} }
if ($this->getParameter("skip") === "true") { if ($this->getParameter("skip") === "true") {
$req = new \Api\Settings\Set($context); $req = new \Core\API\Settings\Set($context);
$success = $req->execute(array("settings" => array("mail_enabled" => "0"))); $success = $req->execute(array("settings" => array("mail_enabled" => "0")));
$msg = $req->getLastError(); $msg = $req->getLastError();
} else { } else {
@ -528,7 +528,7 @@ namespace Documents\Install {
} }
if ($success) { if ($success) {
$req = new \Api\Settings\Set($context); $req = new \Core\API\Settings\Set($context);
$success = $req->execute(array("settings" => array( $success = $req->execute(array("settings" => array(
"mail_enabled" => "1", "mail_enabled" => "1",
"mail_host" => "$address", "mail_host" => "$address",

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\Logger; namespace Core\Driver\Logger;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class Logger { class Logger {
@ -53,9 +53,9 @@ class Logger {
$message .= "\n" . $this->getStackTrace(); $message .= "\n" . $this->getStackTrace();
} }
$this->lastMessage = $message;
$this->lastLevel = $severity;
if ($this->unitTestMode) { if ($this->unitTestMode) {
$this->lastMessage = $message;
$this->lastLevel = $severity;
return; return;
} }
@ -109,14 +109,6 @@ class Logger {
return self::$INSTANCE; return self::$INSTANCE;
} }
/**
* Calling this method will prevent the logger from persisting log messages (writing to database/file),
* and allow to access the last logged message via #getLastMessage() and #getLastLevel()
*/
public function unitTestMode() {
$this->unitTestMode = true;
}
public function getLastMessage(): ?string { public function getLastMessage(): ?string {
return $this->lastMessage; return $this->lastMessage;
} }
@ -124,4 +116,11 @@ class Logger {
public function getLastLevel(): ?string { public function getLastLevel(): ?string {
return $this->lastLevel; return $this->lastLevel;
} }
/**
* Calling this method will prevent the logger from persisting log messages (writing to database/file),
*/
public function unitTestMode() {
$this->unitTestMode = true;
}
} }

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class BigIntColumn extends IntColumn { class BigIntColumn extends IntColumn {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class BoolColumn extends Column { class BoolColumn extends Column {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
use Driver\SQL\Expression\Expression; use Core\Driver\SQL\Expression\Expression;
class Column extends Expression { class Column extends Expression {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class DateTimeColumn extends Column { class DateTimeColumn extends Column {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class DoubleColumn extends NumericColumn { class DoubleColumn extends NumericColumn {
public function __construct(string $name, bool $nullable, $defaultValue = NULL, ?int $totalDigits = null, ?int $decimalDigits = null) { public function __construct(string $name, bool $nullable, $defaultValue = NULL, ?int $totalDigits = null, ?int $decimalDigits = null) {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class EnumColumn extends Column { class EnumColumn extends Column {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class FloatColumn extends NumericColumn { class FloatColumn extends NumericColumn {
public function __construct(string $name, bool $nullable, $defaultValue = NULL, ?int $totalDigits = null, ?int $decimalDigits = null) { public function __construct(string $name, bool $nullable, $defaultValue = NULL, ?int $totalDigits = null, ?int $decimalDigits = null) {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class IntColumn extends Column { class IntColumn extends Column {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class JsonColumn extends Column { class JsonColumn extends Column {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
class NumericColumn extends Column { class NumericColumn extends Column {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class SerialColumn extends Column { class SerialColumn extends Column {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Column; namespace Core\Driver\SQL\Column;
class StringColumn extends Column { class StringColumn extends Column {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
class Compare extends Condition { class Compare extends Condition {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
class CondAnd extends Condition { class CondAnd extends Condition {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
class CondBool extends Condition { class CondBool extends Condition {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
class CondIn extends Condition { class CondIn extends Condition {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
abstract class CondKeyword extends Condition { abstract class CondKeyword extends Condition {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
class CondLike extends CondKeyword { class CondLike extends CondKeyword {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
class CondNot extends Condition { class CondNot extends Condition {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
class CondNull extends Condition { class CondNull extends Condition {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
class CondOr extends Condition { class CondOr extends Condition {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
class CondRegex extends CondKeyword { class CondRegex extends CondKeyword {

@ -0,0 +1,9 @@
<?php
namespace Core\Driver\SQL\Condition;
use Core\Driver\SQL\Expression\Expression;
abstract class Condition extends Expression {
}

@ -1,10 +1,10 @@
<?php <?php
namespace Driver\SQL\Condition; namespace Core\Driver\SQL\Condition;
use Driver\SQL\Query\Select; use Core\Driver\SQL\Query\Select;
class Exists extends Condition class Exists extends Condition
{ {

@ -0,0 +1,18 @@
<?php
namespace Core\Driver\SQL\Constraint;
abstract class Constraint {
private array $columnNames;
private ?string $name;
public function __construct($columnNames, ?string $constraintName = NULL) {
$this->columnNames = (!is_array($columnNames) ? array($columnNames) : $columnNames);
$this->name = $constraintName;
}
public function getColumnNames(): array { return $this->columnNames; }
public function getName(): ?string { return $this->name; }
public function setName(string $name) { $this->name = $name; }
}

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Constraint; namespace Core\Driver\SQL\Constraint;
use Driver\SQL\Strategy\Strategy; use Core\Driver\SQL\Strategy\Strategy;
class ForeignKey extends Constraint { class ForeignKey extends Constraint {
@ -10,8 +10,8 @@ class ForeignKey extends Constraint {
private string $referencedColumn; private string $referencedColumn;
private ?Strategy $strategy; private ?Strategy $strategy;
public function __construct(string $name, string $refTable, string $refColumn, ?Strategy $strategy = NULL) { public function __construct(string $columnName, string $refTable, string $refColumn, ?Strategy $strategy = NULL) {
parent::__construct($name); parent::__construct($columnName);
$this->referencedTable = $refTable; $this->referencedTable = $refTable;
$this->referencedColumn = $refColumn; $this->referencedColumn = $refColumn;
$this->strategy = $strategy; $this->strategy = $strategy;

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Constraint; namespace Core\Driver\SQL\Constraint;
class PrimaryKey extends Constraint { class PrimaryKey extends Constraint {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Constraint; namespace Core\Driver\SQL\Constraint;
class Unique extends Constraint { class Unique extends Constraint {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Expression; namespace Core\Driver\SQL\Expression;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
# TODO: change confusing class inheritance here # TODO: change confusing class inheritance here
class Add extends Compare { class Add extends Compare {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Expression; namespace Core\Driver\SQL\Expression;
use Driver\SQL\Condition\Condition; use Core\Driver\SQL\Condition\Condition;
class CaseWhen extends Expression { class CaseWhen extends Expression {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Expression; namespace Core\Driver\SQL\Expression;
class CurrentTimeStamp extends Expression { class CurrentTimeStamp extends Expression {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Expression; namespace Core\Driver\SQL\Expression;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class DateAdd extends Expression { class DateAdd extends Expression {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Expression; namespace Core\Driver\SQL\Expression;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class DateSub extends Expression { class DateSub extends Expression {

@ -0,0 +1,9 @@
<?php
namespace Core\Driver\SQL\Expression;
use Core\Driver\SQL\SQL;
abstract class Expression {
}

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Expression; namespace Core\Driver\SQL\Expression;
class JsonArrayAgg extends Expression { class JsonArrayAgg extends Expression {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Expression; namespace Core\Driver\SQL\Expression;
class Sum extends Expression { class Sum extends Expression {

@ -1,9 +1,9 @@
<?php <?php
namespace Driver\SQL; namespace Core\Driver\SQL;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
class Join { class Join {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL; namespace Core\Driver\SQL;
use Driver\SQL\Expression\Expression; use Core\Driver\SQL\Expression\Expression;
class Keyword extends Expression { class Keyword extends Expression {

@ -1,34 +1,34 @@
<?php <?php
namespace Driver\SQL; namespace Core\Driver\SQL;
use \Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use DateTime; use DateTime;
use \Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use \Driver\SQL\Column\IntColumn; use Core\Driver\SQL\Column\IntColumn;
use Driver\SQL\Column\NumericColumn; use Core\Driver\SQL\Column\NumericColumn;
use \Driver\SQL\Column\SerialColumn; use Core\Driver\SQL\Column\SerialColumn;
use \Driver\SQL\Column\StringColumn; use Core\Driver\SQL\Column\StringColumn;
use \Driver\SQL\Column\EnumColumn; use Core\Driver\SQL\Column\EnumColumn;
use \Driver\SQL\Column\DateTimeColumn; use Core\Driver\SQL\Column\DateTimeColumn;
use Driver\SQL\Column\BoolColumn; use Core\Driver\SQL\Column\BoolColumn;
use Driver\SQL\Column\JsonColumn; use Core\Driver\SQL\Column\JsonColumn;
use Driver\SQL\Expression\Add; use Core\Driver\SQL\Expression\Add;
use Driver\SQL\Expression\CurrentTimeStamp; use Core\Driver\SQL\Expression\CurrentTimeStamp;
use Driver\SQL\Expression\DateAdd; use Core\Driver\SQL\Expression\DateAdd;
use Driver\SQL\Expression\DateSub; use Core\Driver\SQL\Expression\DateSub;
use Driver\SQL\Expression\Expression; use Core\Driver\SQL\Expression\Expression;
use Driver\SQL\Expression\JsonArrayAgg; use Core\Driver\SQL\Expression\JsonArrayAgg;
use Driver\SQL\Query\CreateProcedure; use Core\Driver\SQL\Query\CreateProcedure;
use Driver\SQL\Query\CreateTrigger; use Core\Driver\SQL\Query\CreateTrigger;
use Driver\SQL\Query\Query; use Core\Driver\SQL\Query\Query;
use Driver\SQL\Strategy\Strategy; use Core\Driver\SQL\Strategy\Strategy;
use \Driver\SQL\Strategy\UpdateStrategy; use Core\Driver\SQL\Strategy\UpdateStrategy;
use Driver\SQL\Type\CurrentColumn; use Core\Driver\SQL\Type\CurrentColumn;
use Driver\SQL\Type\CurrentTable; use Core\Driver\SQL\Type\CurrentTable;
use Driver\SQL\Type\Trigger; use Core\Driver\SQL\Type\Trigger;
class MySQL extends SQL { class MySQL extends SQL {

@ -1,35 +1,35 @@
<?php <?php
namespace Driver\SQL; namespace Core\Driver\SQL;
use \Api\Parameter\Parameter; use Core\API\Parameter\Parameter;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use \Driver\SQL\Column\IntColumn; use Core\Driver\SQL\Column\IntColumn;
use Driver\SQL\Column\NumericColumn; use Core\Driver\SQL\Column\NumericColumn;
use \Driver\SQL\Column\SerialColumn; use Core\Driver\SQL\Column\SerialColumn;
use \Driver\SQL\Column\StringColumn; use Core\Driver\SQL\Column\StringColumn;
use \Driver\SQL\Column\EnumColumn; use Core\Driver\SQL\Column\EnumColumn;
use \Driver\SQL\Column\DateTimeColumn; use Core\Driver\SQL\Column\DateTimeColumn;
use Driver\SQL\Column\BoolColumn; use Core\Driver\SQL\Column\BoolColumn;
use Driver\SQL\Column\JsonColumn; use Core\Driver\SQL\Column\JsonColumn;
use Driver\SQL\Condition\CondRegex; use Core\Driver\SQL\Condition\CondRegex;
use Driver\SQL\Expression\Add; use Core\Driver\SQL\Expression\Add;
use Driver\SQL\Expression\CurrentTimeStamp; use Core\Driver\SQL\Expression\CurrentTimeStamp;
use Driver\SQL\Expression\DateAdd; use Core\Driver\SQL\Expression\DateAdd;
use Driver\SQL\Expression\DateSub; use Core\Driver\SQL\Expression\DateSub;
use Driver\SQL\Expression\Expression; use Core\Driver\SQL\Expression\Expression;
use Driver\SQL\Expression\JsonArrayAgg; use Core\Driver\SQL\Expression\JsonArrayAgg;
use Driver\SQL\Query\CreateProcedure; use Core\Driver\SQL\Query\CreateProcedure;
use Driver\SQL\Query\CreateTrigger; use Core\Driver\SQL\Query\CreateTrigger;
use Driver\SQL\Query\Insert; use Core\Driver\SQL\Query\Insert;
use Driver\SQL\Query\Query; use Core\Driver\SQL\Query\Query;
use Driver\SQL\Strategy\Strategy; use Core\Driver\SQL\Strategy\Strategy;
use Driver\SQL\Strategy\UpdateStrategy; use Core\Driver\SQL\Strategy\UpdateStrategy;
use Driver\SQL\Type\CurrentColumn; use Core\Driver\SQL\Type\CurrentColumn;
use Driver\SQL\Type\CurrentTable; use Core\Driver\SQL\Type\CurrentTable;
use Driver\SQL\Type\Trigger; use Core\Driver\SQL\Type\Trigger;
class PostgreSQL extends SQL { class PostgreSQL extends SQL {

@ -1,14 +1,14 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Column\EnumColumn; use Core\Driver\SQL\Column\EnumColumn;
use Driver\SQL\Constraint\Constraint; use Core\Driver\SQL\Constraint\Constraint;
use Driver\SQL\Constraint\ForeignKey; use Core\Driver\SQL\Constraint\ForeignKey;
use Driver\SQL\Constraint\PrimaryKey; use Core\Driver\SQL\Constraint\PrimaryKey;
use Driver\SQL\PostgreSQL; use Core\Driver\SQL\PostgreSQL;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class AlterTable extends Query { class AlterTable extends Query {
@ -107,10 +107,14 @@ class AlterTable extends Query {
if ($action === "DROP") { if ($action === "DROP") {
if ($constraint instanceof PrimaryKey) { if ($constraint instanceof PrimaryKey) {
$query .= "PRIMARY KEY"; $query .= "PRIMARY KEY";
} else if ($constraint instanceof ForeignKey) { } else {
// TODO: how can we pass the constraint name here? $constraintName = $constraint->getName();
$this->sql->setLastError("DROP CONSTRAINT foreign key is not supported yet."); if ($constraintName) {
return null; $query .= "CONSTRAINT " . $this->sql->columnName($constraintName);
} else {
$this->sql->setLastError("Cannot DROP CONSTRAINT without a constraint name.");
return null;
}
} }
} else if ($action === "ADD") { } else if ($action === "ADD") {
$query .= "CONSTRAINT "; $query .= "CONSTRAINT ";

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class Commit extends Query { class Commit extends Query {
public function __construct(SQL $sql) { public function __construct(SQL $sql) {

@ -1,10 +1,10 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class CreateProcedure extends Query { class CreateProcedure extends Query {

@ -1,26 +1,26 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\Column\BigIntColumn; use Core\Driver\SQL\Column\BigIntColumn;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Column\DoubleColumn; use Core\Driver\SQL\Column\DoubleColumn;
use Driver\SQL\Column\FloatColumn; use Core\Driver\SQL\Column\FloatColumn;
use Driver\SQL\Column\NumericColumn; use Core\Driver\SQL\Column\NumericColumn;
use Driver\SQL\Column\SerialColumn; use Core\Driver\SQL\Column\SerialColumn;
use Driver\SQL\Column\StringColumn; use Core\Driver\SQL\Column\StringColumn;
use Driver\SQL\Column\IntColumn; use Core\Driver\SQL\Column\IntColumn;
use Driver\SQL\Column\DateTimeColumn; use Core\Driver\SQL\Column\DateTimeColumn;
use Driver\SQL\Column\EnumColumn; use Core\Driver\SQL\Column\EnumColumn;
use Driver\SQL\Column\BoolColumn; use Core\Driver\SQL\Column\BoolColumn;
use Driver\SQL\Column\JsonColumn; use Core\Driver\SQL\Column\JsonColumn;
use Driver\SQL\Constraint\Constraint; use Core\Driver\SQL\Constraint\Constraint;
use Driver\SQL\Constraint\PrimaryKey; use Core\Driver\SQL\Constraint\PrimaryKey;
use Driver\SQL\Constraint\Unique; use Core\Driver\SQL\Constraint\Unique;
use Driver\SQL\Constraint\ForeignKey; use Core\Driver\SQL\Constraint\ForeignKey;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
use Driver\SQL\Strategy\Strategy; use Core\Driver\SQL\Strategy\Strategy;
class CreateTable extends Query { class CreateTable extends Query {
@ -103,7 +103,9 @@ class CreateTable extends Query {
} }
public function primaryKey(...$names): CreateTable { public function primaryKey(...$names): CreateTable {
$this->constraints[] = new PrimaryKey($names); $pk = new PrimaryKey($names);
$pk->setName(strtolower("pk_{$this->tableName}"));
$this->constraints[] = $pk;
return $this; return $this;
} }
@ -112,8 +114,10 @@ class CreateTable extends Query {
return $this; return $this;
} }
public function foreignKey(string $name, string $refTable, string $refColumn, ?Strategy $strategy = NULL): CreateTable { public function foreignKey(string $column, string $refTable, string $refColumn, ?Strategy $strategy = NULL): CreateTable {
$this->constraints[] = new ForeignKey($name, $refTable, $refColumn, $strategy); $fk = new ForeignKey($column, $refTable, $refColumn, $strategy);
$fk->setName(strtolower("fk_{$this->tableName}_${refTable}_${refColumn}"));
$this->constraints[] = $fk;
return $this; return $this;
} }

@ -1,9 +1,9 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Api\User\Create; use Core\API\User\Create;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class CreateTrigger extends Query { class CreateTrigger extends Query {

@ -1,9 +1,9 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\Condition\CondOr; use Core\Driver\SQL\Condition\CondOr;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class Delete extends Query { class Delete extends Query {

@ -1,9 +1,9 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class Drop extends Query { class Drop extends Query {

@ -1,9 +1,9 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
use Driver\SQL\Strategy\Strategy; use Core\Driver\SQL\Strategy\Strategy;
class Insert extends Query { class Insert extends Query {

@ -1,9 +1,9 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\Expression\Expression; use Core\Driver\SQL\Expression\Expression;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
abstract class Query extends Expression { abstract class Query extends Expression {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class RollBack extends Query { class RollBack extends Query {
public function __construct(SQL $sql) { public function __construct(SQL $sql) {

@ -1,11 +1,11 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\Condition\CondOr; use Core\Driver\SQL\Condition\CondOr;
use Driver\SQL\Expression\JsonArrayAgg; use Core\Driver\SQL\Expression\JsonArrayAgg;
use Driver\SQL\Join; use Core\Driver\SQL\Join;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class Select extends Query { class Select extends Query {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class StartTransaction extends Query { class StartTransaction extends Query {
public function __construct(SQL $sql) { public function __construct(SQL $sql) {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class Truncate extends Query { class Truncate extends Query {

@ -1,9 +1,9 @@
<?php <?php
namespace Driver\SQL\Query; namespace Core\Driver\SQL\Query;
use Driver\SQL\Condition\CondOr; use Core\Driver\SQL\Condition\CondOr;
use Driver\SQL\SQL; use Core\Driver\SQL\SQL;
class Update extends Query { class Update extends Query {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL; namespace Core\Driver\SQL;
abstract class RowIterator implements \Iterator { abstract class RowIterator implements \Iterator {

@ -1,43 +1,43 @@
<?php <?php
namespace Driver\SQL; namespace Core\Driver\SQL;
use Driver\Logger\Logger; use Core\Driver\Logger\Logger;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare; use Core\Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondAnd; use Core\Driver\SQL\Condition\CondAnd;
use Driver\SQL\Condition\CondBool; use Core\Driver\SQL\Condition\CondBool;
use Driver\SQL\Condition\CondIn; use Core\Driver\SQL\Condition\CondIn;
use Driver\SQL\Condition\Condition; use Core\Driver\SQL\Condition\Condition;
use Driver\SQL\Condition\CondKeyword; use Core\Driver\SQL\Condition\CondKeyword;
use Driver\SQL\Condition\CondNot; use Core\Driver\SQL\Condition\CondNot;
use Driver\Sql\Condition\CondNull; use Core\Driver\Sql\Condition\CondNull;
use Driver\SQL\Condition\CondOr; use Core\Driver\SQL\Condition\CondOr;
use Driver\SQL\Condition\Exists; use Core\Driver\SQL\Condition\Exists;
use Driver\SQL\Constraint\Constraint; use Core\Driver\SQL\Constraint\Constraint;
use Driver\SQL\Constraint\Unique; use Core\Driver\SQL\Constraint\Unique;
use Driver\SQL\Constraint\PrimaryKey; use Core\Driver\SQL\Constraint\PrimaryKey;
use Driver\SQL\Constraint\ForeignKey; use Core\Driver\SQL\Constraint\ForeignKey;
use Driver\SQL\Expression\CaseWhen; use Core\Driver\SQL\Expression\CaseWhen;
use Driver\SQL\Expression\CurrentTimeStamp; use Core\Driver\SQL\Expression\CurrentTimeStamp;
use Driver\SQL\Expression\Expression; use Core\Driver\SQL\Expression\Expression;
use Driver\SQL\Expression\Sum; use Core\Driver\SQL\Expression\Sum;
use Driver\SQL\Query\AlterTable; use Core\Driver\SQL\Query\AlterTable;
use Driver\SQL\Query\CreateProcedure; use Core\Driver\SQL\Query\CreateProcedure;
use Driver\SQL\Query\CreateTable; use Core\Driver\SQL\Query\CreateTable;
use Driver\SQL\Query\CreateTrigger; use Core\Driver\SQL\Query\CreateTrigger;
use Driver\SQL\Query\Delete; use Core\Driver\SQL\Query\Delete;
use Driver\SQL\Query\Drop; use Core\Driver\SQL\Query\Drop;
use Driver\SQL\Query\Insert; use Core\Driver\SQL\Query\Insert;
use Driver\SQL\Query\Query; use Core\Driver\SQL\Query\Query;
use Driver\SQL\Query\Select; use Core\Driver\SQL\Query\Select;
use Driver\SQL\Query\Truncate; use Core\Driver\SQL\Query\Truncate;
use Driver\SQL\Query\Update; use Core\Driver\SQL\Query\Update;
use Driver\SQL\Strategy\CascadeStrategy; use Core\Driver\SQL\Strategy\CascadeStrategy;
use Driver\SQL\Strategy\SetDefaultStrategy; use Core\Driver\SQL\Strategy\SetDefaultStrategy;
use Driver\SQL\Strategy\SetNullStrategy; use Core\Driver\SQL\Strategy\SetNullStrategy;
use Driver\SQL\Strategy\Strategy; use Core\Driver\SQL\Strategy\Strategy;
use Objects\ConnectionData; use Core\Objects\ConnectionData;
abstract class SQL { abstract class SQL {
@ -190,6 +190,7 @@ abstract class SQL {
public function getConstraintDefinition(Constraint $constraint): ?string { public function getConstraintDefinition(Constraint $constraint): ?string {
$columnName = $this->columnName($constraint->getColumnNames()); $columnName = $this->columnName($constraint->getColumnNames());
if ($constraint instanceof PrimaryKey) { if ($constraint instanceof PrimaryKey) {
return "PRIMARY KEY ($columnName)"; return "PRIMARY KEY ($columnName)";
} else if ($constraint instanceof Unique) { } else if ($constraint instanceof Unique) {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Strategy; namespace Core\Driver\SQL\Strategy;
class CascadeStrategy extends Strategy { class CascadeStrategy extends Strategy {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Strategy; namespace Core\Driver\SQL\Strategy;
class SetDefaultStrategy extends Strategy { class SetDefaultStrategy extends Strategy {

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Strategy; namespace Core\Driver\SQL\Strategy;
class SetNullStrategy extends Strategy { class SetNullStrategy extends Strategy {

@ -0,0 +1,7 @@
<?php
namespace Core\Driver\SQL\Strategy;
abstract class Strategy {
}

@ -1,6 +1,6 @@
<?php <?php
namespace Driver\SQL\Strategy; namespace Core\Driver\SQL\Strategy;
class UpdateStrategy extends Strategy { class UpdateStrategy extends Strategy {

@ -1,10 +1,10 @@
<?php <?php
namespace Driver\SQL\Type; namespace Core\Driver\SQL\Type;
use Driver\SQL\Column\Column; use Core\Driver\SQL\Column\Column;
class CurrentColumn extends Column { class CurrentColumn extends Column {

@ -1,8 +1,8 @@
<?php <?php
namespace Driver\SQL\Type; namespace Core\Driver\SQL\Type;
use Driver\SQL\Column\StringColumn; use Core\Driver\SQL\Column\StringColumn;
class CurrentTable extends StringColumn { class CurrentTable extends StringColumn {
public function __construct() { public function __construct() {

Some files were not shown because too many files have changed in this diff Show More