-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
80 lines (67 loc) · 1.59 KB
/
index.php
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
<?php
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
/*
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('logs/log.log', Logger::WARNING));
// add records to the log
$log->addWarning('Foo');
$log->addError('Bar');
*/
// Handle request
$request = Request::createFromGlobals();
// Connection to DB
$config = new Configuration();
$connectionParams = array(
'dbname' => 'db',
'user' => 'root',
'password' => 'usbw',
'host' => 'localhost',
'port' => 3307,
'driver' => 'pdo_mysql',
);
$conn = DriverManager::getConnection($connectionParams, $config);
function path($path = '')
{
global $request;
return $request->server->get('SCRIPT_NAME') . $path;
}
function url($path = '')
{
global $request;
return $request->getSchemeAndHttpHost() . path($path);
}
switch ($request->server->get('PATH_INFO')) {
case '':
if ($request->query->getInt('id')) {
require_once 'post.php';
} else {
require_once 'posts.php';
}
break;
case '/admin/post':
if ($request->query->getInt('id')) {
require_once 'admin-post.php';
} else {
require_once 'admin-posts.php';
}
break;
case '/admin/post/new':
require_once 'admin-post.php';
break;
case '/admin/post/delete':
$conn->delete('posts', [
'id' => $request->query->getInt('id'),
]);
header('Location: ' . path('/admin/post'));
exit;
break;
default:
header('HTTP/1.0 404 Not Found');
require '404.php';
}