rewrite config files to JSON, refactor environment bootstrap #14

This commit is contained in:
ghost 2023-09-24 23:18:51 +03:00
parent e1054cd69e
commit 32c1bbe4a2
13 changed files with 127 additions and 300 deletions

View file

@ -85,7 +85,7 @@ class AppControllerIndex
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/common.css?%s',
WEBSITE_CSS_VERSION
CSS_VERSION
),
],
[
@ -93,7 +93,7 @@ class AppControllerIndex
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/framework.css?%s',
WEBSITE_CSS_VERSION
CSS_VERSION
),
],
]

View file

@ -38,7 +38,7 @@ class AppControllerResponse
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/common.css?%s',
WEBSITE_CSS_VERSION
CSS_VERSION
),
],
[
@ -46,7 +46,7 @@ class AppControllerResponse
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/framework.css?%s',
WEBSITE_CSS_VERSION
CSS_VERSION
),
],
]

View file

@ -92,7 +92,7 @@ class AppControllerWelcome
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/common.css?%s',
WEBSITE_CSS_VERSION
CSS_VERSION
),
],
[
@ -100,7 +100,7 @@ class AppControllerWelcome
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/framework.css?%s',
WEBSITE_CSS_VERSION
CSS_VERSION
),
],
]

View file

@ -1,17 +1,36 @@
<?php
class AppModelDatabase {
class AppModelDatabase
{
private PDO $_db;
private object $_debug;
public function __construct(string $host, int $port, string $database, string $username, string $password) {
public function __construct(object $config)
{
$this->_db = new PDO(
'mysql:dbname=' . $config->name . ';host=' . $config->host . ';port=' . $config->port . ';charset=utf8',
$config->user,
$config->password,
[
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
]
);
$this->_db = new PDO('mysql:dbname=' . $database . ';host=' . $host . ';port=' . $port . ';charset=utf8', $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
$this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->_db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$this->_db->setAttribute(PDO::ATTR_TIMEOUT, 600);
$this->_db->setAttribute(
PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION
);
$this->_db->setAttribute(
PDO::ATTR_DEFAULT_FETCH_MODE,
PDO::FETCH_OBJ
);
$this->_db->setAttribute(
PDO::ATTR_TIMEOUT,
600
);
$this->_debug = (object)
[
@ -38,23 +57,23 @@ class AppModelDatabase {
}
// Tools
public function beginTransaction() {
public function beginTransaction() : void
{
$this->_db->beginTransaction();
}
public function commit() {
public function commit() : void
{
$this->_db->commit();
}
public function rollBack() {
public function rollBack() : void
{
$this->_db->rollBack();
}
public function getDebug() {
public function getDebug() : object
{
return $this->_debug;
}