-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
89 lines (67 loc) · 2.18 KB
/
Copy pathindex.php
File metadata and controls
89 lines (67 loc) · 2.18 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
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', true);
require __DIR__ . '/vendor/autoload.php';
// Load environment variables
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
// Setup layouts and app URL
const LAYOUTS = __DIR__ . '/src/Layouts/';
use Google\Client;
use PortfolioApp\Controllers\AdminController;
use PortfolioApp\Controllers\GoogleLoginController;
use PortfolioApp\Controllers\UserController;
use PortfolioApp\Models\User;
use Psr\Container\ContainerInterface;
$container = new DI\Container();
$container->set(PDO::class, function () {
// Set up PDO connection to your database
if($_ENV['DATABASE'] === 'mysql') {
$dsn = 'mysql:host=' . $_ENV['DB_HOST'] . ';dbname=' . $_ENV['DB_NAME'];
$username = $_ENV['DB_USER'];
$password = $_ENV['DB_PASSWORD'];
try {
return new PDO($dsn, $username, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
} else if($_ENV['DATABASE'] === "sqlite") {
$dsn = 'sqlite:database/'.$_ENV['DB_NAME'];
try {
return new PDO($dsn);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
}
});
$container->set(User::class, function (ContainerInterface $c) {
return new User($c->get(PDO::class), '','','');
});
$container->set(Client::class, function () {
return new Client();
});
$container->set(GoogleLoginController::class, function (ContainerInterface $c) {
return new GoogleLoginController(
$c->get(User::class),
$c->get(Client::class)
);
});
$container->get(UserController::class);
$container->get(GoogleLoginController::class);
//$container->get(AdminController::class);
// Retrieve router and dispatch request
$router = require './src/routes.php';
$router->dispatch($_SERVER['REQUEST_URI'], $container);
function logToFile($value): void
{
// Specify the path to the log file
$logFile = __DIR__ . '/error_log.txt';
// Get the type of the variable
$type = gettype($value);
// Prepare the log message
$message = date('Y-m-d H:i:s') . ' - Type: ' . $type . ', Value: ' . print_r($value, true) . PHP_EOL;
// Append the message to the log file
file_put_contents($logFile, $message, FILE_APPEND);
}