forked from fahmiardi/slim-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
57 lines (49 loc) · 1.62 KB
/
Copy pathbootstrap.php
File metadata and controls
57 lines (49 loc) · 1.62 KB
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
<?php
// Load configuration file, affects local only:
@include(ROOT.'/config.php');
// Load Slim:
require(ROOT.'/common/Slim/Slim.php');
\Slim\Slim::registerAutoloader();
// Register an autoloader for slim-common's helpers
spl_autoload_register(function($className) {
$baseDir = __DIR__.DIRECTORY_SEPARATOR;
$className = ltrim($className, '\\');
$fileName = $baseDir;
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName .= str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, strtolower($className)) . '.php';
// error_log($fileName);
if (file_exists($fileName)) {
return require($fileName);
}
});
// Initialize Slim:
$app = new \Slim\Slim(array(
// Template path: default is /templates in the Root
'templates.path' => ROOT.'/templates',
// Logging: default is enabled; but log level controlled by LOG_LEVEL constant
'log.enabled' => true
));
// Load config management library:
require(ROOT.'/common/config.php');
// Set logging level:
$log = $app->getLog();
$log->setLevel(config('log.level', 0));
// Load default libraries:
require(ROOT.'/common/memcached.php');
require(ROOT.'/common/db.php');
require(ROOT.'/common/session.php');
// Setup the slim.after hook for printing DB log
$app->hook('slim.after', function() use ($app) {
foreach(ORM::get_query_log() as $entry) {
$app->getLog()->debug($entry);
}
});
// Add API functionality
if (config('use.api', false)) {
require(ROOT.'/common/api.php');
}