resolved #13, resolved #14, resolved #15

This commit is contained in:
Arsen Mirzaev Tatyano-Muradovich 2025-02-26 13:40:06 +07:00
parent 4eecb4c5ed
commit a62b5ad3e5
6 changed files with 22 additions and 67 deletions

View File

@ -21,25 +21,18 @@ use mirzaev\minimal\core as minimal,
*
* @package ${REPO_OWNER}\${REPO_NAME}\controllers
*
* @param session $$session Instance of the session
* @param language $$language Language
* @param response $$response Response
* @param array $$errors Registry of errors
*
* @method void __construct(minimal $$minimal, bool $$initialize) Constructor
* @method void __construct(minimal $$minimal) Constructor
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
* @author ${REPO_OWNER} <mail@domain.zone>
*/
class core extends controller
{
/**
* Session
*
* @var session|null $$session Instance of the session
*/
protected readonly session $$session;
/**
* Language
*
@ -65,8 +58,7 @@ class core extends controller
* @var array $$errors Registry of errors
*/
protected array $$errors = [
'session' => [],
'account' => []
'system' => []
];
/**
@ -77,50 +69,12 @@ class core extends controller
*
* @return void
*/
public function __construct(minimal $$core, bool $$initialize = true)
public function __construct(minimal $$core)
{
// Blocking requests from CloudFlare (better to write this blocking into nginx config file)
if (isset($$_SERVER['HTTP_USER_AGENT']) && $$_SERVER['HTTP_USER_AGENT'] === 'nginx-ssl early hints') return status::bruh->label;
// For the extends system
parent::__construct(core: $$core);
if ($$initialize) {
// Requestet initializing
// Initializing core of the models
new models();
// Initializing of the date until which the session will be active
$$expires = strtotime('+1 week');
// Initializing of default value of hash of the session
$$_COOKIE["session"] ??= null;
// Initializing of session
$$this->session = new session($$_COOKIE["session"], $$expires, $$this->errors['session']);
// Handle a problems with initializing a session
if (!empty($$this->errors['session'])) die;
else if ($$_COOKIE["session"] !== $$this->session->hash) {
// Hash of the session is changed (implies that the session has expired and recreated)
// Write a new hash of the session to cookies
setcookie(
'session',
$$this->session->hash,
[
'expires' => $$expires,
'path' => '/',
'secure' => true,
'httponly' => true,
'samesite' => 'strict'
]
);
}
// Initializing of preprocessor of views
$$this->view = new templater($$this->session);
}
}
}

View File

@ -21,6 +21,7 @@ use mirzaev\minimal\http\enumerations\content,
* @method null index() Main page
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
* @author ${REPO_OWNER} <mail@domain.zone>
*/
final class index extends core
@ -31,7 +32,7 @@ final class index extends core
* @var array $$errors Registry of errors
*/
protected array $$errors = [
'session' => []
'system' => []
];
/**

View File

@ -0,0 +1,3 @@
!.gitignore
*.baza
*.php

View File

@ -31,6 +31,9 @@ require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';
// Initializing path to the directory of the storage
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
// Initializing path to the databases directory
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');
// Initializing dependencies
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

View File

@ -5,8 +5,7 @@ declare(strict_types=1);
namespace ${REPO_OWNER}\${REPO_NAME}\views;
// Files of the project
use ${REPO_OWNER}\${REPO_NAME}\models\session,
${REPO_OWNER}\${REPO_NAME}\models\enumerations\language;
use ${REPO_OWNER}\${REPO_NAME}\models\enumerations\language;
// Framework for PHP
use mirzaev\minimal\controller;
@ -30,10 +29,11 @@ use ArrayAccess as array_access,
* @param twig $$twig Instance of the twig templater
* @param array $$variables Registry of view global variables
*
* @method void __construct(?session &$$session) Constructor
* @method void __construct() Constructor
* @method string|null render(string $$file, ?array $$variables) Render the HTML-document
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
* @author ${REPO_OWNER} <mail@domain.zone>
*/
final class templater extends controller implements array_access
@ -55,11 +55,9 @@ final class templater extends controller implements array_access
/**
* Constructor of an instance
*
* @param ?session $$session Instance of the session in ArangoDB
*
* @return void
*/
public function __construct(?session &$$session = null)
public function __construct()
{
// Initializing the Twig instance
$$this->twig = new twig(new FilesystemLoader(VIEWS));
@ -68,7 +66,6 @@ final class templater extends controller implements array_access
$$this->twig->addGlobal('theme', 'default');
$$this->twig->addGlobal('server', $$_SERVER);
$$this->twig->addGlobal('cookies', $$_COOKIE);
if (!empty($$session->status())) $$this->twig->addGlobal('session', $$session);
$$this->twig->addGlobal('language', $$language = $$session?->buffer['language'] ?? language::en);
}

View File

@ -1,10 +1,11 @@
{
"name": "${REPO_OWNER}/${REPO_NAME}",
"description": "${REPO_DESCRIPTION}",
"homepage": "https://git.mirzaev.sexy${REPO_LINK}",
"homepage": "https://git.svoboda.works${REPO_LINK}",
"type": "site",
"keywords": [
"minimal"
"minimal",
"baza"
],
"readme": "README.md",
"license": "WTFPL",
@ -17,21 +18,17 @@
}
],
"support": {
"wiki": "https://git.mirzaev.sexy${REPO_LINK}/wiki",
"issues": "https://git.mirzaev.sexy${REPO_LINK}/issues"
"wiki": "https://git.svoboda.works${REPO_LINK}/wiki",
"issues": "https://git.svoboda.works${REPO_LINK}/issues"
},
"require": {
"php": "^8.4",
"triagens/arangodb": "^3.8",
"mirzaev/minimal": "^3.4",
"mirzaev/arangodb": "^1.3",
"mirzaev/baza": "^3.3",
"twig/twig": "^3.10",
"twig/extra-bundle": "^3.7",
"twig/intl-extra": "^3.10"
},
"require-dev": {
"phpunit/phpunit": "~9.5"
},
"autoload": {
"psr-4": {
"${REPO_OWNER}\\${REPO_NAME}\\": "${REPO_OWNER}/${REPO_NAME}/system"