-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
83 lines (67 loc) · 2.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
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
<?php
require_once __DIR__ . '/vendor/php-mvc-project/php-mvc/src/index.php';
require_once __DIR__ . '/config/bootstrap.php';
use PhpMvc\AppBuilder;
use PhpMvc\FileCacheProvider;
// config
AppBuilder::useNamespace('TodoList');
// AppBuilder::useCache(new FileCacheProvider());
AppBuilder::useSession();
// custom handlers
AppBuilder::use(function($appContext) {
$appContext->addPreSend(function(PhpMvc\ActionContext $actionContext) {
if (stripos($actionContext->getHttpContext()->getRequest()->rawUrl(), '/error/') === false) {
$response = $actionContext->getHttpContext()->getResponse();
$statusCode = $response->getStatusCode();
if ($statusCode === 404) {
$response->addHeader(
'Location',
'/error/404?' . http_build_query(array('url' => $actionContext->getHttpContext()->getRequest()->rawUrl()))
);
}
}
});
$appContext->addErrorHandler(function(PhpMvc\ErrorHandlerEventArgs $errorHandlerEventArgs) use ($appContext) {
$errorHandlerEventArgs->setHandled(true);
$httpContext = $appContext->getConfig('httpContext');
$response = $httpContext->getResponse();
$response->addHeader(
'Location',
'/error/500?' .
http_build_query(array(
'message' => $errorHandlerEventArgs->getMessage(),
'url' => $httpContext->getRequest()->rawUrl())
)
);
$response->end();
});
});
// routes
AppBuilder::routes(function($routes) {
$routes->ignore('favicon.ico');
$routes->ignore('content/{*file}');
$routes->ignore('{*allphp}', array('allphp' => '.*\.php'));
$routes->add('error', 'error/{code}', array(
'controller' => 'error',
'action' => 'index'
));
$routes->add('editGroup', 'groups/edit/{id}', array(
'controller' => 'groups',
'action' => 'edit'
), array(
'id' => '\d+'
));
$routes->add('newGroup', 'groups/new', array(
'controller' => 'groups',
'action' => 'edit'
));
$routes->add('newTask', 'tasks/new', array(
'controller' => 'tasks',
'action' => 'edit'
));
$routes->add('default', '{controller=Home}/{action=index}/{id?}');
});
// custom settings
AppBuilder::set('cookies_salt', 'hmF06iNcGw7AI7EyieqOe37uvj0Jp2Ho');
// build app
AppBuilder::build();