Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jun 26, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.php
More file actions
Latest commit
105 lines (85 loc) · 2.29 KB
/
Copy pathhelpers.php
File metadata and controls
105 lines (85 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
if (! defined('EXECUTION_ALLOWED')) {
exit('Unauthorized access denied.');
}
useLeague\Plates\Engine;
useMedoo\Medoo;
usePHPMailer\PHPMailer\PHPMailer;
functioncreate_mailer(): PHPMailer
{
$mailer = newPHPMailer(true);
$mailer->isSMTP();
$mailer->Host = SMTP_HOST;
$mailer->Port = SMTP_PORT;
if (SMTP_USERNAME && SMTP_PASSWORD) {
$mailer->SMTPAuth = true;
$mailer->Username = SMTP_USERNAME;
$mailer->Password = SMTP_PASSWORD;
}
$mailer->SMTPDebug = defined('DEBUG_ENABLED');
$mailer->SMTPSecure = SMTP_ENCRYPTION;
return$mailer;
}
functionget_or_create_db(): Medoo
{
static$database;
if (empty($database)) {
$database = newMedoo([
'type' => 'mysql',
'host' => DB_HOST,
'port' => DB_PORT,
'username' => DB_USERNAME,
'password' => DB_PASSWORD,
'database' => DB_NAME,
]);
}
return$database;
}
functionmigrate_database(): array
{
$db = get_or_create_db();
$sql = <<<SQL
CREATE TABLE IF NOT EXISTS `migrations` (
`name` VARCHAR(255),
PRIMARY KEY (`name`)
) ENGINE=InnoDB;
SQL;
$db->exec($sql);
$migrations = [];
foreach (newDirectoryIterator(__DIR__.'/migrations') as$file) {
$filename = $file->getFilename();
if (strpos($filename, '.') !== 0) {
$migrations[] = $filename;
}
}
sort($migrations);
$existing = array_column($db->select('migrations', ['name']), 'name');
$missing = [];
foreach ($migrationsas$migration) {
if (in_array($migration, $existing)) {
continue;
}
$sql = file_get_contents(__DIR__.'/migrations/'.$migration);
$db->exec($sql);
$db->insert('migrations', ['name' => $migration]);
$missing[] = $migration;
}
return$missing;
}
functionrender_template(string$name, array$data = []): string
{
$engine = newEngine(__DIR__.'/templates');
return$engine->render($name, $data);
}
/**
* @param array|object $data
*/
functionrespond_with_json($data): void
{
header('content-type: application/json');
echojson_encode($data, JSON_PRETTY_PRINT);
}
functionrespond_with_template(string$name, array$data = []): void
{
echorender_template($name, $data);
}