forked from sergey-platonov/cpp-russia-2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
49 lines (42 loc) · 1.41 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
<?php
include ("loader.php");
$router = new AltoRouter();
// map homepage
$router->map( 'GET', '/', function() {
$arrSpeakers = getAllSpeakerData();
require __DIR__ . '/main.php';
});
// map all talks page
$router->map( 'GET', '/talks', function() {
$arrSpeakers = getAllSpeakerData();
require __DIR__ . '/templates/talks.php';
});
// map talk details page
$router->map( 'GET', '/talks/[*:speaker]', function($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', '/workshops/[*:speaker]', function($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 {
// no route was matched
header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}