-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathindex.php
51 lines (44 loc) · 1.56 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
<?php
include ("./loader.php");
$GLOBALS["prefix"] = basename(__DIR__);
$GLOBALS['project_root'] = __DIR__;
$router = new AltoRouter();
// map homepage
$router->map( 'GET', '/[i:year]/', function($year) {
require __DIR__ . '/main.php';
});
// map all talks page
$router->map( 'GET', '/[i:year]/talks', function($year) {
$arrSpeakers = getAllSpeakerData(__DIR__)["speakers"];
require __DIR__ . '/templates/talks.php';
});
// map talk details page
$router->map( 'GET', '/[i:year]/talks/[*:speaker]', function($year, $speaker) {
$speakerData = getSpeakerDataByDirName($speaker);
if (!$speakerData) {
header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
echo "Запрашиваемая страница не найдена";
} else {
require __DIR__ . '/templates/talk.php';
}
});
// map workshop details page
$router->map( 'GET', '/[i:year]/workshops/[*:speaker]', function($year, $speaker) {
$speakerData = getSpeakerDataByDirName($speaker);
if (!$speakerData) {
header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
echo "Запрашиваемая страница не найдена ";
} else {
require __DIR__ . '/templates/workshop.php';
}
});
// match current request url
$match = $router->match();
// call closure or throw 404 status
if( $match && is_callable( $match['target'] ) ) {
call_user_func_array( $match['target'], $match['params'] );
} else {
// print $_SERVER['REQUEST_URI'];
// no route was matched
header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}