48 Commits
Author SHA1 Message Date
bence 8a1820275d Merge pull request 'iterate in $data until fields for empty relation are over' (#22) from bugfix/fix-model-loading-when-left-join-is-empty into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #22
2023-05-28 15:48:31 +02:00
bence da2801560d iterate in $data until fields for empty relation are over
soko-web/pipeline/pr-master This commit looks good
2023-05-28 15:47:35 +02:00
bence dd855a6d6b Merge pull request 'fix the case when relation is set to null' (#21) from bugfix/fix-when-relation-is-set-to-null into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #21
2023-05-28 15:47:27 +02:00
bence 25548176bb fix the case when relation is set to null
soko-web/pipeline/pr-master This commit looks good
2023-05-28 15:46:13 +02:00
bence f31b801c03 Merge pull request 'generated unique slug should be part of diff' (#20) from bugfix/generated-unique-slug-should-be-part-of-diff into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #20
2023-05-28 15:45:58 +02:00
bence 346b1a0ca9 generated unique slug should be part of diff
soko-web/pipeline/pr-master This commit looks good
2023-05-28 15:45:19 +02:00
bence 6fdd25ae4b Merge pull request 'MAPG-238 include view with @include' (#19) from feature/MAPG-238-include-possibility-for-templating-engine into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #19
2023-05-28 15:45:10 +02:00
bence 754a23706a MAPG-238 include view with @include
soko-web/pipeline/pr-master This commit looks good
2023-05-27 10:56:20 +02:00
bence 78f891fbff Merge pull request 'feature/slug-handling' (#18) from feature/slug-handling into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #18
2023-05-07 01:52:34 +02:00
bence 6989e1dcf3 call static instead of self in Model
soko-web/pipeline/pr-master This commit looks good
2023-05-07 01:51:20 +02:00
bence 1288a33ff6 handle slugs in persistent data manager 2023-05-07 01:51:20 +02:00
bence a5bfc61db8 add class that handles model with slug 2023-05-07 01:51:20 +02:00
bence 9637ebc52b install cocur/slugify 2023-05-06 22:59:49 +02:00
bence 585d469b69 Merge pull request 'use the correct table alias in joins 'on clause'' (#17) from bugfix/fix-multiple-level-join-table-alias into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #17
2023-05-02 18:06:33 +02:00
bence a17db2c79c use the correct table alias in joins 'on clause'
soko-web/pipeline/pr-master This commit looks good
2023-05-02 18:04:35 +02:00
bence fd286c9cff Merge pull request 'check session validity by DatabaseSessionHandler' (#16) from feature/sessions-should-expire into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #16
2023-05-02 12:55:47 +02:00
bence 72fc78220f check session validity by DatabaseSessionHandler
soko-web/pipeline/pr-master This commit looks good
2023-05-02 12:37:31 +02:00
bence 0da1d00c3d Merge pull request 'feature/implement-separate-remember-me' (#15) from feature/implement-separate-remember-me into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #15
2023-05-02 12:08:16 +02:00
bence c57d1d40d4 fixup! remove unnecessary "pass by reference" variables from Request
soko-web/pipeline/pr-master This commit looks good
2023-05-02 12:02:30 +02:00
bence 6a35344210 pass Session object to Request
soko-web/pipeline/pr-master There was a failure building this commit
2023-05-02 11:47:08 +02:00
bence 9ade08d8bd session handler should receive table name in the constructor 2023-05-02 10:52:22 +02:00
bence a982be6645 remove unnecessary "pass by reference" variables from Request 2023-05-02 10:36:04 +02:00
bence 219b42f995 Merge pull request 'feature/use-the-same-table-in-multiple-joins' (#14) from feature/use-the-same-table-in-multiple-joins into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #14
2023-05-01 19:08:22 +02:00
bence 70a9e492e3 make left joins really work
soko-web/pipeline/pr-master This commit looks good
2023-05-01 18:56:36 +02:00
bence e9bfe4e4ad use the table name is column names if table is not specified 2023-05-01 18:56:36 +02:00
bence cf329a20e5 make it possible to use the same table in multiple joins 2023-05-01 18:56:36 +02:00
bence 88a2a99527 Merge pull request 'feature/withrelations-should-contain-names-instead-of-types' (#13) from feature/withrelations-should-contain-names-instead-of-types into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #13
2023-04-30 20:20:27 +02:00
bence e37ea7c09c make PersistentDataManager::$fillWithData private
soko-web/pipeline/pr-master This commit looks good
2023-04-30 19:21:04 +02:00
bence ad7ea0de9d withRelations in methods of PersistentDataManager should contain relation names instead of types 2023-04-30 19:19:00 +02:00
bence 445774e59a Merge pull request 'make auditlogger optional in persistent data manager' (#12) from bugfix/make-auditlogger-optional into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #12
2023-04-20 00:24:31 +02:00
bence 7650b33cd2 make auditlogger optional in persistent data manager
soko-web/pipeline/pr-master This commit looks good
2023-04-20 00:23:14 +02:00
bence 5e0579463c Merge pull request 'feature/get-rid-of-container-usage' (#11) from feature/get-rid-of-container-usage into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #11
2023-04-19 23:35:03 +02:00
bence 4fe463fcc5 do not use app container in classes
soko-web/pipeline/pr-master This commit looks good
2023-04-19 23:26:24 +02:00
bence 0f87a9c6e3 add interfaces for route and route collection 2023-04-19 22:15:49 +02:00
bence 3893ed2231 Merge pull request 'feature/audit-logger' (#7) from feature/audit-logger into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #7
2023-04-18 23:17:08 +02:00
bence 2c18f74f97 add/modify template for audit logger
soko-web/pipeline/pr-master This commit looks good
2023-04-18 23:15:06 +02:00
bence 831433f9d8 implement audit logger 2023-04-18 23:15:06 +02:00
bence aa31c857c7 Merge pull request 'fix archive in pipeline' (#10) from bugfix/fix-archive-in-pipeline into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #10
2023-04-18 23:13:59 +02:00
bence 73272fa6e5 fix archive in pipeline
soko-web/pipeline/pr-master This commit looks good
2023-04-18 23:13:11 +02:00
bence 0b047b0bcc Merge pull request 'feature/database-transactions' (#9) from feature/database-transactions into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #9
2023-04-18 23:07:18 +02:00
bence ad7b8c3eda handle errors and exceptions in controllers
soko-web/pipeline/pr-master This commit looks good
2023-04-18 22:43:21 +02:00
bence 51801d4228 execute every db command in a transaction in controllers 2023-04-18 22:22:02 +02:00
bence 644197fae8 Merge pull request 'turn on mysqli exceptions' (#8) from feature/enable-mysqli-exceptions into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #8
2023-04-17 20:45:53 +02:00
bence f43121769b turn on mysqli exceptions
soko-web/pipeline/pr-master This commit looks good
2023-04-17 20:42:22 +02:00
bence 948b36c80d Merge pull request 'add generic HttpResponse' (#6) from feature/create-generic-class-for-http-response into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #6
2023-04-16 20:52:06 +02:00
bence 635b68ab46 add generic HttpResponse
soko-web/pipeline/pr-master This commit looks good
2023-04-16 20:46:16 +02:00
bence 8df2e64872 Merge pull request 'unify url handling for routes and redirect' (#5) from feature/unify-url-handling into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #5
2023-04-16 20:45:23 +02:00
bence 427426bebe unify url handling for routes and redirect
soko-web/pipeline/pr-master This commit looks good
2023-04-16 20:33:22 +02:00
29 changed files with 790 additions and 246 deletions

No files matched your search

Vendored
+3 -3
View File
@@ -32,7 +32,7 @@ pipeline {
sh 'vendor/bin/phpunit --log-junit unit_test_results.xml --testdox tests'
}
post {
success {
always {
archiveArtifacts 'unit_test_results.xml'
}
}
@@ -47,10 +47,10 @@ pipeline {
}
}
steps {
sh 'php vendor/bin/phpstan analyse -c phpstan.neon --error-format=prettyJson > static_code_analysis_results.json'
sh 'php -d memory_limit=1G vendor/bin/phpstan analyse -c phpstan.neon --error-format=prettyJson > static_code_analysis_results.json'
}
post {
success {
always {
archiveArtifacts 'static_code_analysis_results.json'
}
}
+2 -1
View File
@@ -6,7 +6,8 @@
"require": {
"vlucas/phpdotenv": "^5.5",
"symfony/console": "^5.4",
"phpmailer/phpmailer": "^6.8"
"phpmailer/phpmailer": "^6.8",
"cocur/slugify": "^4.3"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
Generated
+75 -1
View File
@@ -4,8 +4,82 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "079e8a8443fdc25cbe3b03322494b73b",
"content-hash": "d873b245eaaf660d70c21e06ee4bcf0a",
"packages": [
{
"name": "cocur/slugify",
"version": "v4.3.0",
"source": {
"type": "git",
"url": "https://github.com/cocur/slugify.git",
"reference": "652234ef5f1be844a2ae1c36ad1b4c88b05160f9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/cocur/slugify/zipball/652234ef5f1be844a2ae1c36ad1b4c88b05160f9",
"reference": "652234ef5f1be844a2ae1c36ad1b4c88b05160f9",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0"
},
"conflict": {
"symfony/config": "<3.4 || >=4,<4.3",
"symfony/dependency-injection": "<3.4 || >=4,<4.3",
"symfony/http-kernel": "<3.4 || >=4,<4.3",
"twig/twig": "<2.12.1"
},
"require-dev": {
"laravel/framework": "^5.0|^6.0|^7.0|^8.0",
"latte/latte": "~2.2",
"league/container": "^2.2.0",
"mikey179/vfsstream": "~1.6.8",
"mockery/mockery": "^1.3",
"nette/di": "~2.4",
"pimple/pimple": "~1.1",
"plumphp/plum": "~0.1",
"symfony/config": "^3.4 || ^4.3 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^3.4 || ^4.3 || ^5.0 || ^6.0",
"symfony/http-kernel": "^3.4 || ^4.3 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0",
"twig/twig": "^2.12.1 || ~3.0",
"zendframework/zend-modulemanager": "~2.2",
"zendframework/zend-servicemanager": "~2.2",
"zendframework/zend-view": "~2.2"
},
"type": "library",
"autoload": {
"psr-4": {
"Cocur\\Slugify\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Florian Eckerstorfer",
"email": "florian@eckerstorfer.co",
"homepage": "https://florian.ec"
},
{
"name": "Ivo Bathke",
"email": "ivo.bathke@gmail.com"
}
],
"description": "Converts a string into a slug.",
"keywords": [
"slug",
"slugify"
],
"support": {
"issues": "https://github.com/cocur/slugify/issues",
"source": "https://github.com/cocur/slugify/tree/v4.3.0"
},
"time": "2022-12-07T19:48:48+00:00"
},
{
"name": "graham-campbell/result-type",
"version": "v1.1.1",
-8
View File
@@ -3,11 +3,3 @@
require 'vendor/autoload.php';
const ROOT = __DIR__;
class Container
{
static SokoWeb\Interfaces\Database\IConnection $dbConnection;
static SokoWeb\Routing\RouteCollection $routeCollection;
static SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler;
static SokoWeb\Interfaces\Request\IRequest $request;
}
+75
View File
@@ -0,0 +1,75 @@
<?php namespace SokoWeb\Database;
use SokoWeb\Interfaces\Database\IAuditLogger;
use SokoWeb\Interfaces\Database\IConnection;
abstract class AuditLoggerBase implements IAuditLogger
{
const LOG_TYPE_INSERT = 'insert';
const LOG_TYPE_UPDATE = 'update';
const LOG_TYPE_DELETE = 'delete';
private IConnection $connection;
private string $logTable;
public function __construct(IConnection $connection, string $logTable)
{
$this->connection = $connection;
$this->logTable = $logTable;
}
public function logInsert(string $localTable, $localId): void
{
$data = [
'local_table' => $localTable,
'local_id' => $localId,
'type' => static::LOG_TYPE_INSERT,
'modifier_id' => $this->getModifierId(),
];
$query = 'INSERT INTO ' . Utils::backtick($this->logTable) . ' SET ' . Utils::generateColumnsWithBinding(array_keys($data));
$stmt = $this->connection->prepare($query);
$stmt->execute($data);
}
public function logUpdate(string $localTable, $localId, array $diff): void
{
$data = [
'local_table' => $localTable,
'local_id' => $localId,
'type' => static::LOG_TYPE_UPDATE,
'modifier_id' => $this->getModifierId(),
'column' => null,
'old' => null,
'new' => null,
];
$query = 'INSERT INTO ' . Utils::backtick($this->logTable) . ' SET ' . Utils::generateColumnsWithBinding(array_keys($data));
$stmt = $this->connection->prepare($query);
foreach ($diff as $name => $values) {
$data['column'] = $name;
$data['old'] = $values['old'];
$data['new'] = $values['new'];
$stmt->execute($data);
}
}
public function logDelete(string $localTable, $localId, array $attributes): void
{
$data = [
'local_table' => $localTable,
'local_id' => $localId,
'type' => static::LOG_TYPE_DELETE,
'modifier_id' => $this->getModifierId(),
'old' => $attributes,
];
$query = 'INSERT INTO ' . Utils::backtick($this->logTable) . ' SET ' . Utils::generateColumnsWithBinding(array_keys($data));
$stmt = $this->connection->prepare($query);
$stmt->execute($data);
}
abstract protected function getModifierId();
}
+10 -30
View File
@@ -19,15 +19,9 @@ class Connection implements IConnection
$socket = (string) ini_get('mysqli.default_socket');
}
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$this->connection = new mysqli($host, $user, $password, $db, $port, $socket);
if ($this->connection->connect_error) {
throw new \Exception('Connection failed: ' . $this->connection->connect_error);
}
if (!$this->connection->set_charset('utf8mb4')) {
throw new \Exception($this->connection->error);
}
$this->connection->set_charset('utf8mb4');
}
public function __destruct()
@@ -37,30 +31,24 @@ class Connection implements IConnection
public function startTransaction(): void
{
if (!$this->connection->autocommit(false)) {
throw new \Exception($this->connection->error);
}
$this->connection->autocommit(false);
}
public function commit(): void
{
if (!$this->connection->commit() || !$this->connection->autocommit(true)) {
throw new \Exception($this->connection->error);
}
$this->connection->commit();
$this->connection->autocommit(true);
}
public function rollback(): void
{
if (!$this->connection->rollback() || !$this->connection->autocommit(true)) {
throw new \Exception($this->connection->error);
}
$this->connection->rollback();
$this->connection->autocommit(true);
}
public function query(string $query): ?IResultSet
{
if (!($result = $this->connection->query($query))) {
throw new \Exception($this->connection->error . '. Query: ' . $query);
}
$result = $this->connection->query($query);
if ($result !== true) {
return new ResultSet($result);
@@ -71,9 +59,7 @@ class Connection implements IConnection
public function multiQuery(string $query): array
{
if (!$this->connection->multi_query($query)) {
throw new \Exception($this->connection->error . '. Query: ' . $query);
}
$this->connection->multi_query($query);
$ret = [];
do {
@@ -86,18 +72,12 @@ class Connection implements IConnection
$this->connection->more_results();
} while ($this->connection->next_result());
if ($this->connection->error) {
throw new \Exception($this->connection->error . '. Query: ' . $query);
}
return $ret;
}
public function prepare(string $query): IStatement
{
if (!($stmt = $this->connection->prepare($query))) {
throw new \Exception($this->connection->error . '. Query: ' . $query);
}
$stmt = $this->connection->prepare($query);
return new Statement($stmt);
}
+59 -11
View File
@@ -2,6 +2,8 @@
use SokoWeb\Interfaces\Database\IConnection;
use SokoWeb\Database\Utils;
use SokoWeb\Interfaces\Database\IAuditLogger;
use SokoWeb\Interfaces\Database\IResultSet;
class Modify
{
@@ -9,6 +11,8 @@ class Modify
private string $table;
private ?IAuditLogger $auditLogger;
private string $idName = 'id';
private array $attributes = [];
@@ -17,10 +21,13 @@ class Modify
private bool $autoIncrement = true;
public function __construct(IConnection $connection, string $table)
private ?array $diff = null;
public function __construct(IConnection $connection, string $table, ?IAuditLogger $auditLogger = null)
{
$this->connection = $connection;
$this->table = $table;
$this->auditLogger = $auditLogger;
}
public function setIdName(string $idName): Modify
@@ -65,6 +72,13 @@ class Modify
return $this;
}
public function setDiff(array $diff): Modify
{
$this->diff = $diff;
return $this;
}
public function getId()
{
return $this->attributes[$this->idName];
@@ -89,6 +103,10 @@ class Modify
$stmt = $this->connection->prepare($query);
$stmt->execute([$this->idName => $this->attributes[$this->idName]]);
if ($this->auditLogger !== null) {
$this->auditLogger->logDelete($this->table, $this->attributes[$this->idName], $this->attributes);
}
}
private function insert(): void
@@ -99,7 +117,7 @@ class Modify
$this->attributes[$this->idName] = $this->generateKey();
}
$set = $this->generateColumnsWithBinding(array_keys($this->attributes));
$set = Utils::generateColumnsWithBinding(array_keys($this->attributes));
$query = 'INSERT INTO ' . Utils::backtick($this->table) . ' SET ' . $set;
@@ -109,32 +127,62 @@ class Modify
if ($this->autoIncrement) {
$this->attributes[$this->idName] = $this->connection->lastId();
}
if ($this->auditLogger !== null) {
$this->auditLogger->logInsert($this->table, $this->attributes[$this->idName]);
}
}
private function update(): void
{
if ($this->auditLogger !== null) {
$this->generateDiff();
if (count($this->diff) === 0) {
return;
}
}
$attributes = $this->attributes;
unset($attributes[$this->idName]);
$set = $this->generateColumnsWithBinding(array_keys($attributes));
$set = Utils::generateColumnsWithBinding(array_keys($attributes));
$query = 'UPDATE ' . Utils::backtick($this->table) . ' SET ' . $set . ' WHERE ' . Utils::backtick($this->idName) . '=?';
$stmt = $this->connection->prepare($query);
$stmt->execute(array_merge($attributes, [$this->idName => $this->attributes[$this->idName]]));
}
public static function generateColumnsWithBinding(array $columns): string
{
array_walk($columns, function(&$value, $key) {
$value = Utils::backtick($value) . '=?';
});
return implode(',', $columns);
if ($this->auditLogger !== null) {
$this->auditLogger->logUpdate($this->table, $this->attributes[$this->idName], $this->diff);
}
}
private function generateKey(): string
{
return substr(hash('sha256', serialize($this->attributes) . random_bytes(5) . microtime()), 0, 7);
}
private function generateDiff(): void
{
if (isset($this->diff)) {
return;
}
$this->diff = [];
$original = $this->readFromDb(array_keys($this->attributes));
foreach ($original as $key => $value) {
if ($value !== $this->attributes[$key]) {
$this->diff[$key] = ['old' => $value, 'new' => $this->attributes[$key]];
}
}
}
private function readFromDb($columns): array
{
return (new Select($this->connection, $this->table))
->columns($columns)
->where($this->idName, '=', $this->attributes[$this->idName])
->execute()
->fetch(IResultSet::FETCH_ASSOC);
}
}
+12 -20
View File
@@ -276,13 +276,12 @@ class Select
return [(string) $table, $params];
}
if ($table instanceof Select)
{
if ($table instanceof Select) {
return $table->generateQuery();
}
if (isset($this->tableAliases[$table])) {
$queryString = ($defineAlias ? Utils::backtick($this->tableAliases[$table]) . ' ' . Utils::backtick($table) : Utils::backtick($table));
$queryString = $defineAlias ? Utils::backtick($this->tableAliases[$table]) . ' ' . Utils::backtick($table) : Utils::backtick($table);
return [$queryString, $params];
}
@@ -295,24 +294,17 @@ class Select
return (string) $column;
}
if (is_array($column)) {
$out = '';
if ($column[0]) {
list($tableName, $params) = $this->generateTable($column[0]);
$out .= $tableName . '.';
}
$out .= Utils::backtick($column[1]);
if (!empty($column[2])) {
$out .= ' ' . Utils::backtick($column[2]);
}
return $out;
} else {
return Utils::backtick($column);
if (!is_array($column)) {
$column = [$this->table, $column];
}
list($tableName, $params) = $this->generateTable($column[0]);
$out = $tableName . '.' . Utils::backtick($column[1]);
if (!empty($column[2])) {
$out .= ' ' . Utils::backtick($column[2]);
}
return $out;
}
private function generateColumns(): string
+9
View File
@@ -5,4 +5,13 @@ class Utils {
{
return '`' . $name . '`';
}
public static function generateColumnsWithBinding(array $columns): string
{
array_walk($columns, function(&$value, $key) {
$value = static::backtick($value) . '=?';
});
return implode(',', $columns);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php namespace SokoWeb\Interfaces\Database;
interface IAuditLogger
{
public function logInsert(string $localTable, $localId): void;
public function logUpdate(string $localTable, $localId, array $diff): void;
public function logDelete(string $localTable, $localId, array $attributes): void;
}
@@ -0,0 +1,22 @@
<?php namespace SokoWeb\Interfaces\PersistentData;
use Generator;
use SokoWeb\Database\Query\Select;
use SokoWeb\PersistentData\Model\Model;
interface IPersistentDataManager
{
public function selectFromDb(Select $select, string $type, bool $useRelations = false, array $withRelations = []);
public function selectMultipleFromDb(Select $select, string $type, bool $useRelations = false, array $withRelations = []): Generator;
public function selectFromDbById($id, string $type, bool $useRelations = false, array $withRelations = []);
public function selectFromDbBySlug(string $slug, string $type, bool $useRelations = false, array $withRelations = []);
public function loadRelationsFromDb(Model $model, bool $recursive = false, array $withRelations = []): void;
public function saveToDb(Model $model): void;
public function deleteFromDb(Model $model): void;
}
+1 -1
View File
@@ -4,7 +4,7 @@ use SokoWeb\Interfaces\Authentication\IUser;
interface IRequest
{
public function setParsedRouteParams(array &$routeParams): void;
public function setParsedRouteParams(array $routeParams): void;
public function getBase(): string;
+1 -1
View File
@@ -6,7 +6,7 @@ interface IRedirect
const TEMPORARY = 2;
public function getUrl(): string;
public function getTarget(): string;
public function getHttpCode(): int;
}
+12
View File
@@ -0,0 +1,12 @@
<?php namespace SokoWeb\Interfaces\Routing;
interface IRoute
{
public function getId(): string;
public function getHandler(): array;
public function generateLink(array $parameters = []): string;
public function testAgainst(array $path): ?array;
}
@@ -0,0 +1,16 @@
<?php namespace SokoWeb\Interfaces\Routing;
use Closure;
interface IRouteCollection
{
public function get(string $id, string $pattern, array $handler): void;
public function post(string $id, string $pattern, array $handler): void;
public function group(string $pattern, Closure $group): void;
public function getRoute(string $id): ?IRoute;
public function match(string $method, string $uri): ?array;
}
+1 -1
View File
@@ -41,7 +41,7 @@ abstract class Model
{
$array = [];
foreach (self::getFields() as $key) {
foreach (static::getFields() as $key) {
$method = 'get' . str_replace('_', '', ucwords($key, '_'));
if (method_exists($this, $method)) {
@@ -0,0 +1,32 @@
<?php namespace SokoWeb\PersistentData\Model;
use Cocur\Slugify\Slugify;
abstract class ModelWithSlug extends Model
{
protected static string $slugSource;
protected ?string $slug = null;
public static function getFields(): array
{
return array_merge(['id', 'slug'], static::$fields);
}
public function setSlug(?string $slug): void
{
$this->slug = $slug;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function generateSlug(): string
{
$slugSourceGetMethod = 'get' . str_replace('_', '', ucwords(static::$slugSource, '_'));
$this->slug = Slugify::create()->slugify($this->$slugSourceGetMethod());
return $this->slug;
}
}
+214 -136
View File
@@ -3,11 +3,27 @@
use Generator;
use SokoWeb\Database\Query\Modify;
use SokoWeb\Database\Query\Select;
use SokoWeb\Interfaces\Database\IConnection;
use SokoWeb\Interfaces\Database\IAuditLogger;
use SokoWeb\Interfaces\Database\IResultSet;
use SokoWeb\Interfaces\PersistentData\IPersistentDataManager;
use SokoWeb\PersistentData\Model\Model;
use SokoWeb\PersistentData\Model\ModelWithSlug;
class PersistentDataManager
class PersistentDataManager implements IPersistentDataManager
{
const SLUG_MAX_LENGTH = 255;
private IConnection $dbConnection;
private ?IAuditLogger $auditLogger;
public function __construct(IConnection $dbConnection, ?IAuditLogger $auditLogger = null)
{
$this->dbConnection = $dbConnection;
$this->auditLogger = $auditLogger;
}
public function selectFromDb(Select $select, string $type, bool $useRelations = false, array $withRelations = [])
{
$select = $this->createSelect($select, $type, $useRelations, $withRelations);
@@ -37,19 +53,197 @@ class PersistentDataManager
}
}
public function selectFromDbById($id, string $type, bool $useRelations = false)
public function selectFromDbById($id, string $type, bool $useRelations = false, array $withRelations = [])
{
$select = new Select(\Container::$dbConnection);
$select = new Select($this->dbConnection);
$select->whereId($id);
return $this->selectFromDb($select, $type, $useRelations);
return $this->selectFromDb($select, $type, $useRelations, $withRelations);
}
public function fillWithData(array &$data, Model $model, array $withRelations = [], ?string $modelKey = null): void
public function selectFromDbBySlug(string $slug, string $type, bool $useRelations = false, array $withRelations = [])
{
$select = new Select($this->dbConnection);
$select->where('slug', '=', $slug);
return $this->selectFromDb($select, $type, $useRelations, $withRelations);
}
public function loadRelationsFromDb(Model $model, bool $recursive = false, array $withRelations = []): void
{
$relations = $model::getRelations();
if (count($withRelations)) {
$relations = array_intersect($relations, $withRelations);
$relations = array_intersect_key($relations, array_flip($withRelations));
}
foreach ($relations as $relation => $relationType) {
$camel = str_replace('_', '', ucwords($relation, '_'));
$methodGet = 'get' . $camel . 'Id';
$methodSet = 'set' . $camel;
$relationId = $model->$methodGet();
if ($relationId !== null) {
$relationModel = $this->selectFromDbById($relationId, $relationType, $recursive, $withRelations);
$model->$methodSet($relationModel);
}
}
}
public function saveToDb(Model $model): void
{
$this->syncRelations($model);
$modified = $model->toArray();
$id = $model->getId();
$modify = new Modify($this->dbConnection, $model::getTable(), $this->auditLogger);
if ($id !== null) {
$original = $model->getSnapshot();
$diff = [];
foreach ($original as $key => $value) {
if ($value === $modified[$key]) {
unset($modified[$key]);
} else {
$diff[$key] = ['old' => $value, 'new' => $modified[$key]];
}
}
if (count($modified) > 0) {
if ($model instanceof ModelWithSlug && isset($modified['slug'])) {
$diff['slug']['new'] = $modified['slug'] = $this->generateUniqueSlug($model, $modified['slug']);
}
$modify->setId($id);
$modify->setDiff($diff);
$modify->fill($modified);
$modify->save();
}
} else {
if ($model instanceof ModelWithSlug) {
$slug = $model->generateSlug();
$modified['slug'] = $this->generateUniqueSlug($model, $slug);
}
$modify->fill($modified);
$modify->save();
$model->setId($modify->getId());
}
$model->saveSnapshot();
}
public function deleteFromDb(Model $model): void
{
$modify = new Modify($this->dbConnection, $model::getTable(), $this->auditLogger);
$modify->setId($model->getId());
$modify->fill($model->toArray());
$modify->delete();
$model->setId(null);
$model->resetSnapshot();
}
private function generateUniqueSlug(ModelWithSlug $model, string $notUniqueSlug): string
{
$numbered = 1;
do {
if ($numbered > 1) {
$slug = substr($notUniqueSlug, 0, static::SLUG_MAX_LENGTH - (strlen((string)$numbered) + 1));
$slug = $notUniqueSlug . '_' . (string)$numbered;
} else {
$slug = substr($notUniqueSlug, 0, static::SLUG_MAX_LENGTH);
}
$select = new Select($this->dbConnection, $model::getTable());
$select->where('slug', '=', $slug);
$numbered++;
} while ($select->count() != 0);
$model->setSlug($slug);
return $slug;
}
private function createSelect(Select $select, string $type, bool $useRelations = false, array $withRelations = []): Select
{
$table = call_user_func([$type, 'getTable']);
$fields = call_user_func([$type, 'getFields']);
$columns = [];
foreach ($fields as $field) {
$columns[] = [$table, $field];
}
$select->from($table);
if ($useRelations) {
$relations = call_user_func([$type, 'getRelations']);
if (count($withRelations)) {
$relations = array_intersect_key($relations, array_flip($withRelations));
}
$columns = array_merge($columns, $this->getRelationColumns($table, $relations, $withRelations));
$this->leftJoinRelations($select, $table, $table, $relations, $withRelations);
$select->columns($columns);
} else {
$select->columns($columns);
}
return $select;
}
private function getRelationColumns(string $table, array $relations, array $withRelations): array
{
$columns = [];
foreach ($relations as $relation => $relationType) {
$relationTableAlias = $table . '__' . $relation;
$relationTable = call_user_func([$relationType, 'getTable']);
foreach (call_user_func([$relationType, 'getFields']) as $relationField) {
$columns[] = [$relationTableAlias, $relationField, $relation . '__' . $relationField];
}
$relationsOfRelation = call_user_func([$relationType, 'getRelations']);
if (count($withRelations)) {
$relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations));
}
$columns = array_merge($columns, $this->getRelationColumns($relationTable, $relationsOfRelation, $withRelations));
}
return $columns;
}
private function leftJoinRelations(Select $select, string $table, string $tableAlias, array $relations, array $withRelations): void
{
foreach ($relations as $relation => $relationType) {
$relationTableAlias = $table . '__' . $relation;
$relationTable = call_user_func([$relationType, 'getTable']);
$select->setTableAliases([$relationTableAlias => $relationTable]);
$select->leftJoin($relationTableAlias, [$relationTableAlias, 'id'], '=', [$tableAlias, $relation . '_id']);
$relationsOfRelation = call_user_func([$relationType, 'getRelations']);
if (count($withRelations)) {
$relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations));
}
$this->leftJoinRelations($select, $relationTable, $relationTableAlias, $relationsOfRelation, $withRelations);
}
}
private function fillWithData(array &$data, Model $model, array $withRelations = [], ?string $modelKey = null): void
{
$relations = $model::getRelations();
if (count($withRelations)) {
$relations = array_intersect_key($relations, array_flip($withRelations));
}
while (key($data)) {
@@ -76,12 +270,19 @@ class PersistentDataManager
next($data);
} else if (substr($key, 0, strlen($relation . '__')) === $relation . '__') {
$relationType = current($relations);
$relationModel = new $relationType();
$this->fillWithData($data, $relationModel, $withRelations, $relation);
if ($data[$relation . '__id'] !== null) {
$relationType = current($relations);
$relationModel = new $relationType();
$this->fillWithData($data, $relationModel, $withRelations, $relation);
$method = 'set' . str_replace('_', '', ucwords($relation, '_'));
$model->$method($relationModel);
$method = 'set' . str_replace('_', '', ucwords($relation, '_'));
$model->$method($relationModel);
} else {
while (substr($key, 0, strlen($relation . '__')) === $relation . '__') {
next($data);
$key = key($data);
}
}
next($relations);
} else {
@@ -92,131 +293,6 @@ class PersistentDataManager
$model->saveSnapshot();
}
public function loadRelationsFromDb(Model $model, bool $recursive): void
{
foreach ($model::getRelations() as $relation => $relationType) {
$camel = str_replace('_', '', ucwords($relation, '_'));
$methodGet = 'get' . $camel . 'Id';
$methodSet = 'set' . $camel;
$relationId = $model->$methodGet();
if ($relationId !== null) {
$relationModel = $this->selectFromDbById($relationId, $relationType, $recursive);
$model->$methodSet($relationModel);
}
}
}
public function saveToDb(Model $model): void
{
$this->syncRelations($model);
$modified = $model->toArray();
$id = $model->getId();
$modify = new Modify(\Container::$dbConnection, $model::getTable());
if ($id !== null) {
$original = $model->getSnapshot();
foreach ($original as $key => $value) {
if ($value === $modified[$key]) {
unset($modified[$key]);
}
}
if (count($modified) > 0) {
$modify->setId($id);
$modify->fill($modified);
$modify->save();
}
} else {
$modify->fill($modified);
$modify->save();
$model->setId($modify->getId());
}
$model->saveSnapshot();
}
public function deleteFromDb(Model $model): void
{
$modify = new Modify(\Container::$dbConnection, $model::getTable());
$modify->setId($model->getId());
$modify->delete();
$model->setId(null);
$model->resetSnapshot();
}
private function createSelect(Select $select, string $type, bool $useRelations = false, array $withRelations = []): Select
{
$table = call_user_func([$type, 'getTable']);
$fields = call_user_func([$type, 'getFields']);
$columns = [];
foreach ($fields as $field) {
$columns[] = [$table, $field];
}
$select->from($table);
if ($useRelations) {
$relations = call_user_func([$type, 'getRelations']);
if (count($withRelations)) {
$relations = array_intersect($relations, $withRelations);
}
$columns = array_merge($columns, $this->getRelationColumns($relations, $withRelations));
$this->leftJoinRelations($select, $table, $relations, $withRelations);
$select->columns($columns);
} else {
$select->columns($columns);
}
return $select;
}
private function getRelationColumns(array $relations, array $withRelations): array
{
$columns = [];
foreach ($relations as $relation => $relationType) {
$relationTable = call_user_func([$relationType, 'getTable']);
foreach (call_user_func([$relationType, 'getFields']) as $relationField) {
$columns[] = [$relationTable, $relationField, $relation . '__' . $relationField];
}
$nextOrderRelations = call_user_func([$relationType, 'getRelations']);
if (count($withRelations)) {
$nextOrderRelations = array_intersect($nextOrderRelations, $withRelations);
}
$columns = array_merge($columns, $this->getRelationColumns($nextOrderRelations, $withRelations));
}
return $columns;
}
private function leftJoinRelations(Select $select, string $table, array $relations, array $withRelations): void
{
foreach ($relations as $relation => $relationType) {
$relationTable = call_user_func([$relationType, 'getTable']);
$select->leftJoin($relationTable, [$relationTable, 'id'], '=', [$table, $relation . '_id']);
$nextOrderRelations = call_user_func([$relationType, 'getRelations']);
if (count($withRelations)) {
$nextOrderRelations = array_intersect($nextOrderRelations, $withRelations);
}
$this->leftJoinRelations($select, $relationTable, $nextOrderRelations, $withRelations);
}
}
private function syncRelations(Model $model): void
{
foreach ($model::getRelations() as $relation => $relationType) {
@@ -229,6 +305,8 @@ class PersistentDataManager
if ($relationModel !== null) {
$model->$methodSet($relationModel->getId());
} else {
$model->$methodSet(null);
}
}
}
+9 -9
View File
@@ -17,23 +17,23 @@ class Request implements IRequest
private array $headers;
private Session $session;
private ISession $session;
private ?IUser $user = null;
public function __construct(
string $base,
array &$get,
array &$post,
array $get,
array $post,
array $headers,
array &$session,
ISession $session,
IUserRepository $userRepository)
{
$this->base = $base;
$this->get = &$get;
$this->post = &$post;
$this->get = $get;
$this->post = $post;
$this->headers = $headers;
$this->session = new Session($session);
$this->session = $session;
$userId = $this->session->get('userId');
if ($userId !== null) {
@@ -41,9 +41,9 @@ class Request implements IRequest
}
}
public function setParsedRouteParams(array &$routeParams): void
public function setParsedRouteParams(array $routeParams): void
{
$this->routeParams = &$routeParams;
$this->routeParams = $routeParams;
}
public function getBase(): string
+154
View File
@@ -0,0 +1,154 @@
<?php namespace SokoWeb\Response;
use ErrorException;
use Exception;
use SokoWeb\Interfaces\Response\IRedirect;
use SokoWeb\Interfaces\Response\IContent;
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Authorization\ISecured;
use SokoWeb\Interfaces\Database\IConnection;
use SokoWeb\Interfaces\Request\IRequest;
use SokoWeb\Response\Redirect;
use SokoWeb\Response\HtmlContent;
use SokoWeb\Response\JsonContent;
use SokoWeb\Routing\RouteCollection;
class HttpResponse
{
private IRequest $request;
private IConnection $dbConnection;
private RouteCollection $routeCollection;
private array $appConfig;
private string $method;
private string $rawUrl;
private array $parsedUrl;
public function __construct(
IRequest $request,
IConnection $dbConnection,
RouteCollection $routeCollection,
array $appConfig,
string $requestMethod,
string $requestUrl
) {
set_error_handler([$this, 'exceptionsErrorHandler']);
$this->request = $request;
$this->dbConnection = $dbConnection;
$this->routeCollection = $routeCollection;
$this->appConfig = $appConfig;
$this->method = strtolower($requestMethod);
$this->parsedUrl = parse_url($requestUrl);
$this->rawUrl = $requestUrl;
}
public function exceptionsErrorHandler($severity, $message, $filename, $lineno)
{
throw new ErrorException($message, 0, $severity, $filename, $lineno);
}
public function render(): void
{
$match = $this->routeCollection->match($this->method, $this->parsedUrl['path']);
if ($match === null) {
$this->render404();
return;
}
list($route, $params) = $match;
$this->request->setParsedRouteParams($params);
$handler = $route->getHandler();
$controller = new $handler[0]();
if (
$controller instanceof IAuthenticationRequired &&
$controller->isAuthenticationRequired() &&
$this->request->user() === null
) {
$this->redirectToLogin();
return;
}
if (
$this->method === 'post' &&
!in_array($this->parsedUrl['path'], $this->appConfig['antiCsrfTokenExceptions']) &&
$this->request->post($this->appConfig['antiCsrfTokenName']) !== $this->request->session()->get($this->appConfig['antiCsrfTokenName'])
) {
$this->renderAntiCsrfError();
return;
}
if ($controller instanceof ISecured && !$controller->authorize()) {
$this->render404();
return;
}
$this->dbConnection->startTransaction();
try {
$response = call_user_func([$controller, $handler[1]]);
} catch (Exception $exception) {
$this->dbConnection->rollback();
$this->render500($exception);
return;
}
$this->dbConnection->commit();
if ($response instanceof IContent) {
header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8');
$response->render();
} elseif ($response instanceof IRedirect) {
header('Location: ' . $this->getRedirectUrl($response), true, $response->getHttpCode());
} else {
$this->render404();
}
}
private function redirectToLogin(): void
{
$this->request->session()->set('redirect_after_login', $this->rawUrl);
$response = new Redirect($this->routeCollection->getRoute($this->appConfig['loginRouteId'])->generateLink(), IRedirect::TEMPORARY);
header('Location: ' . $this->getRedirectUrl($response), true, $response->getHttpCode());
}
private function renderAntiCsrfError(): void
{
$content = new JsonContent($this->appConfig['antiCsrfTokenErrorResponse']);
header('Content-Type: text/html; charset=UTF-8', true, 403);
$content->render();
}
private function render404(): void
{
$content = new HtmlContent($this->appConfig['error404View']);
header('Content-Type: text/html; charset=UTF-8', true, 404);
$content->render();
}
private function render500(Exception $exception): void
{
if (empty($_ENV['DEV'])) {
$exceptionToPrint = null;
} else {
$exceptionToPrint = (string)$exception;
}
$content = new HtmlContent($this->appConfig['error500View'], ['exceptionToPrint' => $exceptionToPrint]);
header('Content-Type: text/html; charset=UTF-8', true, 500);
$content->render();
}
private function getRedirectUrl(IRedirect $redirect): string
{
$url = $redirect->getTarget();
if (preg_match('/^http(s)?/', $url) !== 1) {
$url = $this->request->getBase() . $url;
}
return $url;
}
}
+2 -8
View File
@@ -14,15 +14,9 @@ class Redirect implements IRedirect
$this->type = $type;
}
public function getUrl(): string
public function getTarget(): string
{
if (preg_match('/^http(s)?/', $this->target) === 1) {
$link = $this->target;
} else {
$link = \Container::$request->getBase() . '/' . $this->target;
}
return $link;
return $this->target;
}
public function getHttpCode(): int
+4 -2
View File
@@ -1,6 +1,8 @@
<?php namespace SokoWeb\Routing;
class Route
use SokoWeb\Interfaces\Routing\IRoute;
class Route implements IRoute
{
private string $id;
@@ -53,7 +55,7 @@ class Route
$query = count($queryParams) > 0 ? '?' . http_build_query($queryParams) : '';
return implode('/', $link) . $query;
return '/' . implode('/', $link) . $query;
}
public function testAgainst(array $path): ?array
+8 -5
View File
@@ -1,8 +1,10 @@
<?php namespace SokoWeb\Routing;
use Closure;
use SokoWeb\Interfaces\Routing\IRoute;
use SokoWeb\Interfaces\Routing\IRouteCollection;
class RouteCollection
class RouteCollection implements IRouteCollection
{
private array $routes = [];
@@ -32,7 +34,7 @@ class RouteCollection
array_pop($this->groupStack);
}
public function getRoute(string $id): ?Route
public function getRoute(string $id): ?IRoute
{
if (!isset($this->routes[$id])) {
return null;
@@ -41,9 +43,10 @@ class RouteCollection
return $this->routes[$id];
}
public function match(string $method, array $uri): ?array
public function match(string $method, string $uri): ?array
{
$groupNumber = count($uri);
$path = $uri === '/' ? [] : explode('/', ltrim($uri, '/'));
$groupNumber = count($path);
// response to HEAD request with the GET content
if ($method === 'head') {
@@ -55,7 +58,7 @@ class RouteCollection
}
foreach ($this->searchTable[$method][$groupNumber] as $route) {
if (($parameters = $route->testAgainst($uri)) !== null) {
if (($parameters = $route->testAgainst($path)) !== null) {
return [$route, $parameters];
}
}
+23 -6
View File
@@ -3,15 +3,29 @@
use DateTime;
use SokoWeb\Database\Query\Modify;
use SokoWeb\Database\Query\Select;
use SokoWeb\Interfaces\Database\IConnection;
use SokoWeb\Interfaces\Database\IResultSet;
use SokoWeb\Interfaces\Session\ISessionHandler;
class DatabaseSessionHandler implements ISessionHandler
{
private IConnection $dbConnection;
private string $table;
private DateTime $shouldBeNewerThan;
private bool $exists = false;
private bool $written = false;
public function __construct(IConnection $dbConnection, string $table, DateTime $shouldBeNewerThan)
{
$this->dbConnection = $dbConnection;
$this->table = $table;
$this->shouldBeNewerThan = $shouldBeNewerThan;
}
public function open($savePath, $sessionName): bool
{
return true;
@@ -24,24 +38,27 @@ class DatabaseSessionHandler implements ISessionHandler
public function read($id): string
{
$select = new Select(\Container::$dbConnection, 'sessions');
$select->columns(['data']);
$select = new Select($this->dbConnection, $this->table);
$select->columns(['data', 'updated']);
$select->whereId(substr($id, 0, 32));
$result = $select->execute()->fetch(IResultSet::FETCH_ASSOC);
if ($result === null) {
return '';
}
$this->exists = true;
if (new DateTime($result['updated']) < $this->shouldBeNewerThan) {
return '';
}
return $result['data'];
}
public function write($id, $data): bool
{
$modify = new Modify(\Container::$dbConnection, 'sessions');
$modify = new Modify($this->dbConnection, $this->table);
if ($this->exists) {
$modify->setId(substr($id, 0, 32));
@@ -60,7 +77,7 @@ class DatabaseSessionHandler implements ISessionHandler
public function destroy($id): bool
{
$modify = new Modify(\Container::$dbConnection, 'sessions');
$modify = new Modify($this->dbConnection, $this->table);
$modify->setId(substr($id, 0, 32));
$modify->delete();
@@ -93,7 +110,7 @@ class DatabaseSessionHandler implements ISessionHandler
return true;
}
$modify = new Modify(\Container::$dbConnection, 'sessions');
$modify = new Modify($this->dbConnection, $this->table);
$modify->setId(substr($id, 0, 32));
$modify->set('updated', (new DateTime())->format('Y-m-d H:i:s'));
+6 -1
View File
@@ -97,7 +97,12 @@ class Linker
fwrite($outputFileHandle, $extra[0]);
while (($line = fgets($inputFileHandle)) !== false) {
fwrite($outputFileHandle, $line);
if (preg_match('/^\s*@include\((.*)\)\s*$/', $line, $matches) === 1) {
$include = file_get_contents(ROOT . '/views/' . $matches[1] . '.php');
fwrite($outputFileHandle, $include);
} else {
fwrite($outputFileHandle, $line);
}
}
fwrite($outputFileHandle, $extra[1]);
+5 -1
View File
@@ -15,9 +15,13 @@ $dotenv->load();
class Container
{
static SokoWeb\Interfaces\Database\IConnection $dbConnection;
static SokoWeb\Routing\RouteCollection $routeCollection;
static SokoWeb\Interfaces\Database\IAuditLogger $auditLogger;
static SokoWeb\Interfaces\PersistentData\IPersistentDataManager $persistentDataManager;
static SokoWeb\Interfaces\Routing\IRouteCollection $routeCollection;
static SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler;
static SokoWeb\Interfaces\Request\IRequest $request;
}
Container::$dbConnection = new SokoWeb\Database\Mysql\Connection($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']);
Container::$auditLogger = new {app}\Database\AuditLogger(Container::$dbConnection, 'audit_log');
Container::$persistentDataManager = new SokoWeb\PersistentData\PersistentDataManager(Container::$dbConnection, Container::$auditLogger);
+13
View File
@@ -13,3 +13,16 @@ CREATE TABLE `users` (
UNIQUE KEY `email` (`email`),
UNIQUE KEY `google_sub` (`google_sub`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `audit_log` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`local_table` varchar(255) NOT NULL,
`local_id` int(10) unsigned NOT NULL,
`type` enum('insert','update','delete') NOT NULL,
`date` timestamp NOT NULL DEFAULT current_timestamp(),
`modifier_id` int(10) unsigned NULL,
`column` varchar(255) NULL,
`old` text NULL,
`new` text NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
@@ -0,0 +1,11 @@
<?php namespace {app}\Database;
use SokoWeb\Database\AuditLoggerBase;
class AuditLogger extends AuditLoggerBase
{
protected function getModifierId()
{
\Container::$request->user()->getUniqueId();
}
}
+1 -1
View File
@@ -14,7 +14,7 @@ Container::$routeCollection = new SokoWeb\Routing\RouteCollection();
Container::$routeCollection->get('index', '', [{app}\Controller\HomeController::class, 'getIndex']);
if (isset($_COOKIE['COOKIES_CONSENT'])) {
Container::$sessionHandler = new SokoWeb\Session\DatabaseSessionHandler();
Container::$sessionHandler = new SokoWeb\Session\DatabaseSessionHandler(Container::$dbConnection, 'sessions');
session_set_save_handler(Container::$sessionHandler, true);
session_start([