-
Notifications
You must be signed in to change notification settings - Fork 4
/
bootstrap.php
219 lines (184 loc) · 5.87 KB
/
bootstrap.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php defined('SYSPATH') or die('No direct script access.');
//-- Environment setup --------------------------------------------------------
/**
* Set the default time zone.
*
* @see http://kohanaframework.org/guide/using.configuration
* @see http://php.net/timezones
*/
date_default_timezone_set('Europe/London');
/**
* Set the default locale.
*
* @see http://kohanaframework.org/guide/using.configuration
* @see http://php.net/setlocale
*/
setlocale(LC_ALL, 'en_GB.utf-8');
/**
* Enable the Kohana auto-loader.
*
* @see http://kohanaframework.org/guide/using.autoloading
* @see http://php.net/spl_autoload_register
*/
spl_autoload_register(array('Kohana', 'auto_load'));
/**
* Enable the Kohana auto-loader for unserialization.
*
* @see http://php.net/spl_autoload_call
* @see http://php.net/manual/var.configuration.php#unserialize-callback-func
*/
ini_set('unserialize_callback_func', 'spl_autoload_call');
//-- Configuration and initialization -----------------------------------------
/**
* Set Kohana::$environment if $_ENV['KOHANA_ENV'] has been supplied.
*
*/
if (isset($_ENV['KOHANA_ENV']))
{
Kohana::$environment = $_ENV['KOHANA_ENV'];
}
/*
*check if ENV var has been defined in apache vhost
*/
else if (isset($_SERVER['KOHANA_ENV']))
{
Kohana::$environment = $_SERVER['KOHANA_ENV'];
}
/**
* Initialize Kohana, setting the default options.
*
* The following options are available:
*
* - string base_url path, and optionally domain, of your application NULL
* - string index_file name of your index file, usually "index.php" index.php
* - string charset internal character set used for input and output utf-8
* - string cache_dir set the internal cache directory APPPATH/cache
* - boolean errors enable or disable error handling TRUE
* - boolean profile enable or disable internal profiling TRUE
* - boolean caching enable or disable internal caching FALSE
*/
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
'profile' => Kohana::$environment !== Kohana::PRODUCTION,
'caching' => Kohana::$environment === Kohana::PRODUCTION,
'errors' => Kohana::$environment !== Kohana::PRODUCTION
));
/**
* Attach the file write to logging. Multiple writers are supported.
*/
Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs'));
/**
* Attach a file reader to config. Multiple readers are supported.
*/
Kohana::$config->attach(new Kohana_Config_File);
/**
* Enable modules. Modules are referenced by a relative or absolute path.
*/
Kohana::modules(array(
'admin' => MODPATH.'admin',
'base' => MODPATH.'base',
'database' => MODPATH.'database', // Database access
'orm' => MODPATH.'orm', // Object Relationship Mapping
'auth' => MODPATH.'auth', // Basic authentication
'oauth' => MODPATH.'oauth', // OAuth authentication
'media' => MODPATH.'media', // Media caching
'cache' => MODPATH.'cache', // Caching with multiple backends
'pagination' => MODPATH.'pagination',// Paging of results
'message' => MODPATH.'message',
'image' => MODPATH.'image', // Image manipulation
'imagemagick-driver' => MODPATH.'imagemagick-driver',
// 'userguide' => MODPATH.'userguide', // User guide and API documentation
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
// 'unittest' => MODPATH.'unittest', // Unit testing
));
/**
* Set the routes. Each route must have a minimum of a name, a URI and a set of
* defaults for the URI.
*/
if ( !Route::cache()){
/* User & Auth routes */
Route::set('user', 'user(/<action>)(/<id>)')
->defaults(array(
'directory' => 'auth',
'controller' => 'user',
'action' => 'index'
));
Route::set('auth-openid', 'openid(/<action>)(/<id>)')
->defaults(array(
'directory' => 'auth',
'controller' => 'openid',
'action' => 'index'
));
Route::set('auth-oauth', 'oauth/<controller>(/<action>)')
->defaults(array(
'directory' => 'auth/oauth',
'action' => 'index'
));
/* Error routes */
Route::set('403', '<error>', array('error' => '403'))
->defaults(array(
'controller' => 'error',
'action' => 'index'
));
Route::set('404', '<error>', array('error' => '404'))
->defaults(array(
'controller' => 'error',
'action' => 'index'
));
Route::set('500', '<error>', array('error' => '500'))
->defaults(array(
'controller' => 'error',
'action' => 'index'
));
/* Default route */
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'home',
'action' => 'index',
));
// Cache the routes in production
Route::cache(Kohana::$environment === Kohana::PRODUCTION);
}
if ( ! defined('SUPPRESS_REQUEST'))
{
/**
* Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
* If no source is specified, the URI will be automatically detected.
*/
$request = Request::instance();
try {
// Attempt to execute the response
$request->execute();
}
/* Catch errors */
catch (ReflectionException $e) {
Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e));
if ( Kohana::$environment === Kohana::DEVELOPMENT ) {
throw $e;
}
$request->response = Request::factory('404')->execute();
}
catch (Exception404 $e) {
Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e));
if ( Kohana::$environment === Kohana::DEVELOPMENT ) {
throw $e;
}
$request->response = Request::factory('404')->execute();
}
catch (Kohana_Request_Exception $e) {
Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e));
if ( Kohana::$environment === Kohana::DEVELOPMENT ) {
throw $e;
}
$request->response = Request::factory('404')->execute();
}
catch (Exception $e) {
Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e));
if ( Kohana::$environment === Kohana::DEVELOPMENT ) {
throw $e;
}
$request->response = Request::factory('500')->execute();
}
$request->response AND print $request->send_headers()->response;
}