-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
executable file
·209 lines (191 loc) · 5.25 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
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
<?php
if ( ! file_exists('config.php'))
{
echo 'Configuration file not found. Please copy config.dist.php to config.php and edit the values therein.';
exit(1);
}
require 'config.php';
define('EXT', '.php');
define('DOCROOT', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
/*
* Path to application data
*/
if ( ! defined('APPPATH'))
{
define('APPPATH', DOCROOT.'application'.DIRECTORY_SEPARATOR);
}
if ( ! is_dir(APPPATH))
{
// Create directory, after the precedent of Kohana_Core::init();
mkdir(APPPATH, 0755, TRUE) OR die('Unable to make directory '.APPPATH);
chmod(APPPATH, 0755);
}
define('MODPATH', DOCROOT.'modules'.DIRECTORY_SEPARATOR);
define('SYSPATH', DOCROOT.'vendor'.DIRECTORY_SEPARATOR.'kohana'.DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR);
if ( ! defined('KOHANA_BASE_URL')) define('KOHANA_BASE_URL', '/kohana_webdb/');
if (substr(KOHANA_BASE_URL, -1) != '/')
{
echo 'KOHANA_BASE_URL must have trailing slash';
exit(1);
}
if ( ! defined('KOHANA_ENVIRONMENT')) define('KOHANA_ENVIRONMENT', 'production');
if ( ! defined('KOHANA_COOKIE_SALT') OR KOHANA_COOKIE_SALT=='')
{
echo 'Please define KOHANA_COOKIE_SALT in config.php';
exit(1);
}
/*
* Set locale and language
*/
if (!defined('KOHANA_LANG')) define('KOHANA_LANG', 'en-au');
if (!defined('KOHANA_LOCALE')) define('KOHANA_LOCALE', 'en_US.utf-8');
setlocale(LC_ALL, KOHANA_LOCALE);
/*
* Load and configure Kohana Core
*/
if (!defined('KOHANA_START_TIME')) define('KOHANA_START_TIME', microtime(TRUE));
if (!defined('KOHANA_START_MEMORY')) define('KOHANA_START_MEMORY', memory_get_usage());
require SYSPATH . 'classes/Kohana/Core'.EXT;
require SYSPATH . 'classes/Kohana'.EXT;
require DOCROOT . 'vendor/autoload.php';
spl_autoload_register(array('Kohana', 'auto_load'));
ini_set('unserialize_callback_func', 'spl_autoload_call');
I18n::lang(KOHANA_LANG);
Kohana::$environment = constant('Kohana::'.strtoupper(KOHANA_ENVIRONMENT));
/*
* Try to create log directory.
*/
$cache_dir = APPPATH.'cache';
if ( ! file_exists($cache_dir))
{
// Create directory, after the precedent of Kohana_Core::init();
mkdir($cache_dir, 0755, TRUE) OR die('Unable to make directory '.$cache_dir);
chmod($cache_dir, 0755);
}
/**
* Shutdown for CLI, can be removed when http://dev.kohanaframework.org/issues/4537 is resolved.
*/
if (PHP_SAPI == 'cli')
{
register_shutdown_function(function()
{
if (Kohana::$errors AND $error = error_get_last() AND in_array($error['type'], Kohana::$shutdown_errors))
{
exit(1);
}
});
}
/*
* Kohana initialisation.
*/
Kohana::init(array(
'base_url' => KOHANA_BASE_URL,
'index_file' => FALSE,
'cache_dir' => $cache_dir,
'profile' => Kohana::$environment != Kohana::PRODUCTION,
'errors' => Kohana::$environment != Kohana::PRODUCTION,
'caching' => Kohana::$environment == Kohana::PRODUCTION,
));
/*
* Try to create log directory.
*/
$log_dir = APPPATH.'logs';
if (!file_exists($log_dir))
{
// Create directory, after the precedent of Kohana_Core::init();
mkdir($log_dir, 0755, TRUE);
chmod($log_dir, 0755);
}
Kohana::$log->attach(new Log_File($log_dir));
unset($log_dir);
/*
*
*/
Kohana::$config->attach(new Config_File);
Cookie::$salt = KOHANA_COOKIE_SALT;
/*
* Load all required modules.
*/
$required_modules = array(
'auth' => MODPATH.'auth',
'cache' => MODPATH.'cache',
'database' => MODPATH.'database',
'pagination' => MODPATH.'pagination',
'minion' => MODPATH.'minion',
'menu' => MODPATH.'menu',
'media' => DOCROOT.'vendor/zeelot/kohana-media',
'tasks-cache' => DOCROOT.'vendor/kohana-minion/tasks-cache',
);
foreach ($modules as $mod)
{
if (is_dir($mod))
{
$required_modules[basename ($mod)] = $mod;
}
}
Kohana::modules($required_modules);
unset($modules, $required_modules);
/**
* Routes.
*/
Route::set('login', 'login')->defaults(array(
'controller' => 'User',
'action' => 'login',
));
Route::set('logout', 'logout')->defaults(array(
'controller' => 'User',
'action' => 'logout',
));
Route::set('profile', 'profile')->defaults(array(
'controller'=>'User',
'action' => 'profile',
));
Route::set('default', '(<action>(/<dbname>(/<tablename>(/<id>))))')
->defaults(array(
'controller' => 'WebDB',
'action' => 'index',
'dbname' => NULL,
'tablename' => NULL,
'id' => NULL
));
/**
* Site title is defined after config and modules have had a chance at at.
*/
if (!defined('SITE_TITLE')) define('SITE_TITLE', 'WebDB');
/**
* Execute the request.
*/
if (PHP_SAPI == 'cli')
{
/**
* Include the Unit Test module and leave the rest to PHPunit.
*/
if (substr(basename($_SERVER['PHP_SELF']), 0, 7) == 'phpunit')
{
// Disable output buffering
if (($ob_len = ob_get_length()) !== FALSE)
{
// flush_end on an empty buffer causes headers to be sent. Only flush if needed.
if ($ob_len > 0) ob_end_flush();
else ob_end_clean();
}
Kohana::modules(Kohana::modules() + array('unittest' => MODPATH.'unittest'));
//Database::$default = 'testing';
return; // Execution will be continued by phpunit
}
/*
* Execute minion if this is a command line request.
*/
set_exception_handler(array('Minion_Exception', 'handler'));
Minion_Task::factory(Minion_CLI::options())->execute();
}
else
{
/*
* Otherwise, execute the main request.
*/
echo Request::factory(TRUE, array(), FALSE)
->execute()
->send_headers(TRUE)
->body();
}