-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
145 lines (117 loc) · 4.51 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
// use aoutoload (recommended)
require_once getcwd() . '/vendor/autoload.php';
// or include the required files
// require_once getcwd() . '/vendor/php-mvc-project/php-mvc/src/index.php';
use PhpMvc\AppBuilder;
// IMPORTANT: specify the root namespace of your application and check code
AppBuilder::useNamespace('RootNamespaceOfYourApp');
// you can change the root path of your application (usually not required)
// AppBuilder::useBasePath(getcwd());
// enable session usage
AppBuilder::useSession();
/*
// you can add any headers that will be sent in response to client requests:
AppBuilder::useHeaders(array(
'X-Powerd-By' => 'PHP',
'X-Author' => '%username%')
);
*/
/*
// by default all validators are included, you can disable unnecessary validators:
AppBuilder::useValidation(array(
// checks the request parameters for dangerous combinations of characters, such as: <, # &
// if you disable this validator, then requests will not be checked
'crossSiteScripting' => false,
// checks the name of the action so that it does not begin with the characters __
// this check prohibits calling public constructors and other magic methods
// for example: /home/__construct
'actionName' => false,
// checks the POST request token if the token was placed on the form
// this allows to filter requests from stupid bots
'antiForgeryToken' => false)
);
*/
// you can enable caching
// for example, FileCacheProvider
// you can use any cache provider or create your own with the interface PhpMvc\CacheProvider
// AppBuilder::useCache(new PhpMvc\FileCacheProvider());
// custom handlers
AppBuilder::useAppContext(function(PhpMvc\AppContext $appContext) {
/*
// pre-init application handler
$appContext->addPreInit(function(PhpMvc\ActionContext $actionContext) {
// $httpContext = $actionContext->getHttpContext();
});
*/
/*
// init application handler
$appContext->addInit(function(PhpMvc\ActionContext $actionContext) {
});
*/
/*
// init handler of the action context of the current request
$appContext->addActionContextInit(function(PhpMvc\ActionContext $actionContext) {
});
*/
/*
// pre-send output handler
$appContext->addPreSend(function(PhpMvc\ActionContext $actionContext) {
// $httpContext = $actionContext->getHttpContext();
});
*/
/*
// partial output handler
$appContext->addFlush(function(PhpMvc\ActionContext $actionContext, $eventArgs) {
});
*/
/*
// end output handler
$appContext->addEnd(function(PhpMvc\ActionContext $actionContext) {
});
*/
/*
// application error handler
$appContext->addErrorHandler(function(PhpMvc\ErrorHandlerEventArgs $errorHandlerEventArgs) use ($appContext) {
// $errorHandlerEventArgs->setHandled(true);
// $httpContext = $appContext->getConfig('httpContext');
});
*/
});
// routes
AppBuilder::routes(function(PhpMvc\RouteProvider $routes) {
// the higher the rule in the list (the earlier the rule was added), the higher the priority in the search for a match
// in templates you can use any valid characters in the URL
// use curly braces to denote the elements of the route
// each element must contain a name
// for example:
// {controller}/{action}
// {action}/{controller}
// {elementName_1}/{elementName_2}/{elementName_N}
// get-{username=anonymous}/send-message/{text}
// after the element name, you can specify a default value in the template:
// {controller=home}
// if the path element is optional, then the question (?) symbol is followed by the name:
// {id?}
// catch-to-all:
// content/{*file}
// ignore paths
$routes->ignore('favicon.ico');
$routes->ignore('content/{*file}');
// default route
$routes->add('default', '{controller=home}/{action=index}/{id?}');
});
// custom settings
// AppBuilder::set('key_1', 'value_1');
// AppBuilder::set('key_2', 'value_2');
// AppBuilder::set('key_N', 'value_N');
// to get the settings use:
// $value = AppBuilder::get('key_1');
// for experts: the default route provider is PhpMvc\DefaultRouteProvider
// you can make your own provider based on the PhpMvc\RouteProvider interface
// or use a solution from third parties
// AppBuilder::useRouter(new PhpMvc\DefaultRouteProvider());
// for experts: you can make and use your own PhpMvc\HttpContext implementation based on the PhpMvc\HttpContextBase class
// AppBuilder::useHttpContext(new PhpMvc\HttpContext());
// build app
AppBuilder::build();