-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBootstrap.php
96 lines (75 loc) · 2.48 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
<?php
namespace Slim;
class Bootstrap
{
/**
* @const string
*/
const VERSION = '0.1.0';
// System Start Time
define('START_TIME', microtime(true));
// System Start Memory
define('START_MEMORY_USAGE', memory_get_usage());
// Is this an AJAX request?
define('AJAX_REQUEST', strtolower(getenv('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest');
// The current TLD address, scheme, and port
define('DOMAIN', (strtolower(getenv('HTTPS')) == 'on' ? 'https' : 'http') . '://'
. getenv('HTTP_HOST') . (($p = getenv('SERVER_PORT')) != 80 AND $p != 443 ? ":$p" : ''));
// The current site path
define('PATH', parse_url(getenv('REQUEST_URI'), PHP_URL_PATH));
// application environment
define('APP_ENV', getenv('SLIM_MODE') ? getenv('SLIM_MODE') : 'development');
// The application root path
define('APP_ROOT_PATH', dirname(dirname(__FILE__)));
// iconv encoding
iconv_set_encoding("internal_encoding", "UTF-8");
// multibyte encoding
mb_internal_encoding('UTF-8');
// Default timezone of server
date_default_timezone_set('Asia/Tokyo');
// erorr reporting
error_reporting(E_STRICT);
define('PHP_ACTIVERECORD_AUTOLOAD_PREPEND',false);
require 'vendor/autoload.php'; // composer autoloder
use \Core\Exception;
// Enable global error handling
set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext) {
throw new Exception\BaseException($errstr, $errno);
});
register_shutdown_function(function(){
$isError = false;
if ($e = error_get_last()){
switch($e['type']){
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_CORE_WARNING:
case E_COMPILE_ERROR:
case E_COMPILE_WARNING:
case E_STRICT:
$isError = true;
break;
}
}
if ($isError){
var_dump(error_get_last());
exit;
}
});
set_exception_handler(function($e) {
echo "Uncaught exception: " , $e->getMessage(), "\n";
});
// twig setting
require_once dirname(__FILE__) . '/vendor/slim/extras/Slim/Extras/Views/Extension/TwigAutoloader.php';
Extras\Views\Twig::$twigDirectory = dirname(__FILE__).'/vendor/twig/twig/lib/Twig';
Extras\Views\Twig::$twigOptions = array();
Extras\Views\Twig::$twigExtensions = array(
'Twig_Extensions_Slim',
'Core\Twig\Extensions\TwigUrlExtension',
'\Twig_Extensions_Extension_I18n',
'\Twig_Extensions_Extension_Text'
// '\Twig_Extensions_Extension_Intl'
);
Bootstrap\Middleware\ActiveRecord::$phpARDirectory = dirname(__FILE__).'/vendor/php-activerecord/php-activerecord';
Slim::registerAutoloader();
}