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
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

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

@ -1,8 +1,8 @@
<?php
namespace Api {
namespace Core\API {
use Objects\Context;
use Core\Objects\Context;
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 {
$request = new \Api\Mail\Send($this->context);
$request = new \Core\API\Mail\Send($this->context);
$this->success = $request->execute(array(
"subject" => $subject,
"body" => $message,
@ -34,17 +34,17 @@ namespace Api {
}
}
namespace Api\Contact {
namespace Core\API\Contact {
use Api\ContactAPI;
use Api\Parameter\Parameter;
use Api\Parameter\StringType;
use Api\VerifyCaptcha;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondNot;
use Driver\SQL\Expression\CaseWhen;
use Driver\SQL\Expression\Sum;
use Objects\Context;
use Core\API\ContactAPI;
use Core\API\Parameter\Parameter;
use Core\API\Parameter\StringType;
use Core\API\VerifyCaptcha;
use Core\Driver\SQL\Condition\Compare;
use Core\Driver\SQL\Condition\CondNot;
use Core\Driver\SQL\Expression\CaseWhen;
use Core\Driver\SQL\Expression\Sum;
use Core\Objects\Context;
class Request extends ContactAPI {

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

@ -1,8 +1,8 @@
<?php
namespace Api {
namespace Core\API {
use Objects\Context;
use Core\Objects\Context;
abstract class LanguageAPI extends Request {
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 Api\Parameter\Parameter;
use Api\Parameter\StringType;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondOr;
use Objects\Context;
use Objects\DatabaseEntity\Language;
use Core\API\LanguageAPI;
use Core\API\Parameter\Parameter;
use Core\API\Parameter\StringType;
use Core\Driver\SQL\Condition\Compare;
use Core\Driver\SQL\Condition\CondOr;
use Core\Objects\Context;
use Core\Objects\DatabaseEntity\Language;
class Get extends LanguageAPI {

@ -1,8 +1,8 @@
<?php
namespace Api {
namespace Core\API {
use Objects\Context;
use Core\Objects\Context;
abstract class LogsAPI extends Request {
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 Api\Parameter\Parameter;
use Api\Parameter\StringType;
use Driver\Logger\Logger;
use Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondIn;
use Objects\Context;
use Objects\DatabaseEntity\SystemLog;
use Core\API\LogsAPI;
use Core\API\Parameter\Parameter;
use Core\API\Parameter\StringType;
use Core\Driver\Logger\Logger;
use Core\Driver\SQL\Column\Column;
use Core\Driver\SQL\Condition\Compare;
use Core\Driver\SQL\Condition\CondIn;
use Core\Objects\Context;
use Core\Objects\DatabaseEntity\SystemLog;
class Get extends LogsAPI {
@ -82,7 +82,7 @@ namespace Api\Logs {
}
// 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) {
$index = 1;
foreach (scandir($logPath) as $fileName) {

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

@ -1,8 +1,8 @@
<?php
namespace Api {
namespace Core\API {
use Objects\Context;
use Core\Objects\Context;
abstract class NewsAPI extends Request {
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 Api\Parameter\Parameter;
use Api\Parameter\StringType;
use Driver\SQL\Condition\Compare;
use Objects\Context;
use Objects\DatabaseEntity\News;
use Core\API\NewsAPI;
use Core\API\Parameter\Parameter;
use Core\API\Parameter\StringType;
use Core\Driver\SQL\Condition\Compare;
use Core\Objects\Context;
use Core\Objects\DatabaseEntity\News;
class Get extends NewsAPI {

@ -1,8 +1,8 @@
<?php
namespace Api {
namespace Core\API {
use Objects\Context;
use Core\Objects\Context;
abstract class NotificationsAPI extends Request {
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 Api\Parameter\Parameter;
use Api\Parameter\StringType;
use Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondIn;
use Driver\SQL\Query\Select;
use Objects\Context;
use Objects\DatabaseEntity\Group;
use Objects\DatabaseEntity\Notification;
use Objects\DatabaseEntity\User;
use Core\API\NotificationsAPI;
use Core\API\Parameter\Parameter;
use Core\API\Parameter\StringType;
use Core\Driver\SQL\Column\Column;
use Core\Driver\SQL\Condition\Compare;
use Core\Driver\SQL\Condition\CondIn;
use Core\Driver\SQL\Query\Select;
use Core\Objects\Context;
use Core\Objects\DatabaseEntity\Group;
use Core\Objects\DatabaseEntity\Notification;
use Core\Objects\DatabaseEntity\User;
class Create extends NotificationsAPI {

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

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

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

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

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

@ -1,15 +1,15 @@
<?php
namespace Api {
namespace Core\API {
use Api\Routes\GenerateCache;
use Driver\SQL\Condition\Compare;
use Objects\Context;
use Core\API\Routes\GenerateCache;
use Core\Driver\SQL\Condition\Compare;
use Core\Objects\Context;
abstract class RoutesAPI extends Request {
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;
@ -61,18 +61,18 @@ namespace Api {
}
}
namespace Api\Routes {
namespace Core\API\Routes {
use Api\Parameter\Parameter;
use Api\Parameter\StringType;
use Api\RoutesAPI;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondBool;
use Objects\Context;
use Objects\Router\DocumentRoute;
use Objects\Router\RedirectRoute;
use Objects\Router\Router;
use Objects\Router\StaticFileRoute;
use Core\API\Parameter\Parameter;
use Core\API\Parameter\StringType;
use Core\API\RoutesAPI;
use Core\Driver\SQL\Condition\Compare;
use Core\Driver\SQL\Condition\CondBool;
use Core\Objects\Context;
use Core\Objects\Router\DocumentRoute;
use Core\Objects\Router\RedirectRoute;
use Core\Objects\Router\Router;
use Core\Objects\Router\StaticFileRoute;
class Fetch extends RoutesAPI {

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

@ -1,8 +1,8 @@
<?php
namespace Api {
namespace Core\API {
use Objects\Context;
use Core\Objects\Context;
abstract class SettingsAPI extends Request {
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 Api\Parameter\StringType;
use Api\SettingsAPI;
use Driver\SQL\Column\Column;
use Driver\SQL\Condition\CondBool;
use Driver\SQL\Condition\CondIn;
use Driver\SQL\Condition\CondNot;
use Driver\SQL\Condition\CondRegex;
use Driver\SQL\Strategy\UpdateStrategy;
use Objects\Context;
use Core\API\Parameter\Parameter;
use Core\API\Parameter\StringType;
use Core\API\SettingsAPI;
use Core\Configuration\Settings;
use Core\Driver\SQL\Column\Column;
use Core\Driver\SQL\Condition\CondBool;
use Core\Driver\SQL\Condition\CondIn;
use Core\Driver\SQL\Condition\CondNot;
use Core\Driver\SQL\Condition\CondRegex;
use Core\Driver\SQL\Strategy\UpdateStrategy;
use Core\Objects\Context;
class Get extends SettingsAPI {
@ -161,4 +162,33 @@ namespace Api\Settings {
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
namespace Api;
namespace Core\API;
use DateTime;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondBool;
use Objects\Context;
use Objects\DatabaseEntity\User;
use Core\Driver\SQL\Condition\Compare;
use Core\Driver\SQL\Condition\CondBool;
use Core\Objects\Context;
use Core\Objects\DatabaseEntity\User;
class Stats extends Request {
@ -38,7 +38,7 @@ class Stats extends Request {
}
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->lastError = $req->getLastError();
@ -71,7 +71,7 @@ class Stats extends Request {
public function _execute(): bool {
$userCount = $this->getUserCount();
$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->lastError = $req->getLastError();
if (!$this->success) {

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

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

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

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

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

@ -1,8 +1,8 @@
<?php
namespace Api {
namespace Core\API {
use Objects\Context;
use Core\Objects\Context;
abstract class VisitorsAPI extends Request {
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 Api\Parameter\StringType;
use Api\VisitorsAPI;
use Core\API\Parameter\Parameter;
use Core\API\Parameter\StringType;
use Core\API\VisitorsAPI;
use DateTime;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Expression\Add;
use Driver\SQL\Query\Select;
use Driver\SQL\Strategy\UpdateStrategy;
use Objects\Context;
use Core\Driver\SQL\Condition\Compare;
use Core\Driver\SQL\Expression\Add;
use Core\Driver\SQL\Query\Select;
use Core\Driver\SQL\Strategy\UpdateStrategy;
use Core\Objects\Context;
class ProcessVisit extends VisitorsAPI {
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
namespace Configuration;
namespace Core\Configuration;
use Objects\ConnectionData;
use Core\Objects\ConnectionData;
class Configuration {
const className = "\Site\Configuration\Database";
private ?ConnectionData $database;
private Settings $settings;
@ -13,12 +14,12 @@ class Configuration {
$this->database = null;
$this->settings = Settings::loadDefaults();
$class = \Configuration\Database::class;
$path = getClassPath($class, ".class");
$className = self::className;
$path = getClassPath($className, ".class");
if (file_exists($path) && is_readable($path)) {
include_once $path;
if (class_exists($class)) {
$this->database = new \Configuration\Database();
if (class_exists($className)) {
$this->database = new $className();
}
}
}
@ -32,7 +33,9 @@ class Configuration {
}
public static function create(string $className, $data) {
$path = getClassPath("\\Configuration\\$className");
$path = getClassPath($className);
$classNameShort = explode("\\", $className);
$classNameShort = end($classNameShort);
if ($data) {
if (is_string($data)) {
@ -40,9 +43,9 @@ class Configuration {
$code = intendCode(
"<?php
namespace Configuration;
namespace Core\Configuration;
class $className extends KeyData {
class $classNameShort extends KeyData {
public function __construct() {
parent::__construct($key);
@ -67,9 +70,9 @@ class Configuration {
$code = intendCode(
"<?php
namespace Configuration;
namespace Site\Configuration;
class $className extends \\$superClass {
class $classNameShort extends \\$superClass {
public function __construct() {
parent::__construct($host, $port, $login, $password);$properties
@ -95,7 +98,7 @@ class Configuration {
return true;
}
public function setDatabase(ConnectionData $connectionData) {
public function setDatabase(ConnectionData $connectionData): void {
$this->database = $connectionData;
}
}

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

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

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

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

@ -4,11 +4,11 @@
* Do not change settings here, they are dynamically loaded from database.
*/
namespace Configuration;
namespace Core\Configuration;
use Driver\Logger\Logger;
use Driver\SQL\Query\Insert;
use Objects\Context;
use Core\Driver\Logger\Logger;
use Core\Driver\SQL\Query\Insert;
use Core\Objects\Context;
class Settings {
@ -18,8 +18,8 @@ class Settings {
// settings
private string $siteName;
private string $baseUrl;
private string $jwtPublicKey;
private string $jwtSecretKey;
private ?string $jwtPublicKey;
private ?string $jwtSecretKey;
private string $jwtAlgorithm;
private bool $registrationAllowed;
private bool $recaptchaEnabled;
@ -37,8 +37,13 @@ class Settings {
$this->logger = new Logger("Settings");
}
public function getJwtPublicKey(): \Firebase\JWT\Key {
return new \Firebase\JWT\Key($this->jwtPublicKey ?? $this->jwtSecretKey, $this->jwtAlgorithm);
public function getJwtPublicKey(bool $allowPrivate = true): ?\Firebase\JWT\Key {
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 {
@ -109,18 +114,24 @@ class Settings {
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) {
$req = new \Api\Settings\Set($context);
$req = new \Core\API\Settings\Set($context);
$req->execute(array("settings" => array(
"jwt_secret_key" => $this->jwtSecretKey,
"jwt_public_key" => $this->jwtSecretKey,
"jwt_algorithm" => $this->jwtAlgorithm,
)));
return $req;
}
public function loadFromDatabase(Context $context): bool {
$this->logger = new Logger("Settings", $context->getSQL());
$req = new \Api\Settings\Get($context);
$req = new \Core\API\Settings\Get($context);
$success = $req->execute();
if ($success) {
@ -203,4 +214,8 @@ class Settings {
public function getDomain(): string {
return parse_url($this->getBaseUrl(), PHP_URL_HOST);
}
public function getLogger(): Logger {
return $this->logger;
}
}

@ -1,10 +1,10 @@
<?php
namespace Documents;
namespace Core\Documents;
use Elements\TemplateDocument;
use Objects\Router\Router;
use Core\Elements\TemplateDocument;
use Core\Objects\Router\Router;
class Account extends TemplateDocument {
@ -25,7 +25,7 @@ class Account extends TemplateDocument {
if ($this->getTemplateName() === "account/reset_password.twig") {
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_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"]));
if ($this->parameters["view"]["success"]) {
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") {
if (isset($_GET["token"]) && is_string($_GET["token"]) && !empty($_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"]));
if ($this->parameters["view"]["success"]) {
if (strcmp($req->getResult()["token"]["type"], "invite") !== 0) {

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

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

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

@ -1,8 +1,8 @@
<?php
namespace Driver\Logger;
namespace Core\Driver\Logger;
use Driver\SQL\SQL;
use Core\Driver\SQL\SQL;
class Logger {
@ -53,9 +53,9 @@ class Logger {
$message .= "\n" . $this->getStackTrace();
}
$this->lastMessage = $message;
$this->lastLevel = $severity;
if ($this->unitTestMode) {
$this->lastMessage = $message;
$this->lastLevel = $severity;
return;
}
@ -109,14 +109,6 @@ class Logger {
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 {
return $this->lastMessage;
}
@ -124,4 +116,11 @@ class Logger {
public function getLastLevel(): ?string {
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
namespace Driver\SQL\Column;
namespace Core\Driver\SQL\Column;
class BigIntColumn extends IntColumn {

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

@ -1,8 +1,8 @@
<?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 {

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

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

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

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

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

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

@ -1,8 +1,8 @@
<?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 {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,8 +1,8 @@
<?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
class Add extends Compare {

@ -1,8 +1,8 @@
<?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 {

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

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

@ -1,8 +1,8 @@
<?php
namespace Driver\SQL\Expression;
namespace Core\Driver\SQL\Expression;
use Driver\SQL\SQL;
use Core\Driver\SQL\SQL;
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
namespace Driver\SQL\Expression;
namespace Core\Driver\SQL\Expression;
class JsonArrayAgg extends Expression {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,10 +1,10 @@
<?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 {

@ -1,8 +1,8 @@
<?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 {
public function __construct() {

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