Add -> add project
This commit is contained in:
13
app/core/db.php
Normal file
13
app/core/db.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$config = require __DIR__ . '/../config/config.php';
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
"mysql:host={$config['db']['host']};dbname={$config['db']['name']};charset=utf8mb4",
|
||||
$config['db']['user'],
|
||||
$config['db']['pass'],
|
||||
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
die('Database connection error');
|
||||
}
|
||||
return $pdo;
|
||||
13
app/core/redis.php
Normal file
13
app/core/redis.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
function redisClient()
|
||||
{
|
||||
static $redis = null;
|
||||
if ($redis === null) {
|
||||
$config = require __DIR__ . '/../config/config.php';
|
||||
|
||||
$redis = new Redis();
|
||||
$redis->connect($config['redis']['host'], $config['redis']['port']);
|
||||
}
|
||||
return $redis;
|
||||
}
|
||||
15
app/core/security.php
Normal file
15
app/core/security.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
function encryptText($text, $key) {
|
||||
$iv = random_bytes(16);
|
||||
$cipher = openssl_encrypt($text, 'AES-256-CBC', $key, 0, $iv);
|
||||
return [
|
||||
'cipher' => $cipher,
|
||||
'iv' => base64_encode($iv)
|
||||
];
|
||||
}
|
||||
function decryptText($cipher, $iv, $key) {
|
||||
return openssl_decrypt($cipher, 'AES-256-CBC', $key, 0, base64_decode($iv));
|
||||
}
|
||||
function generateId() {
|
||||
return bin2hex(random_bytes(16));
|
||||
}
|
||||
Reference in New Issue
Block a user