This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
/
Bootstrap.php
executable file
·96 lines (73 loc) · 2.44 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
<?php
/**
* Bootstrap
*
* This file contains initialization code run immediately after system startup.
* Setup i18n and l10n handling, configure system, prepare event hooks.
*
* @package MicroMVC
* @author David Pennington
* @copyright (c) 2010 MicroMVC Framework
* @license http://micromvc.com/license
********************************** 80 Columns *********************************
*/
// System Start Time
define('START_TIME', microtime(true));
// System Start Memory
define('START_MEMORY_USAGE', memory_get_usage());
if( ! class_exists('Locale', false)) {
die('You must install the <a href="http://php.net/manual/en/book.intl.php">PHP INTL</a> extension.');
}
// Extension of all PHP files
define('EXT', '.php');
// Directory separator (Unix-Style works on all OS)
define('DS', '/');
// Absolute path to the system folder
define('SP', realpath(__DIR__). DS);
// 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));
require(SP . 'vendor/autoload' . EXT);
// Include common system functions
require(SP . 'Common' . EXT);
\Micro\View::$directory = SP . 'View/';
\Micro\Cookie::$settings = config()->cookie;
// Register events
foreach(config()->events as $event => $class)
{
event($event, NULL, $class);
}
/*
if(preg_match_all('/[\-a-z]{2,}/i', getenv('HTTP_ACCEPT_LANGUAGE'), $locales))
{
$locales = $locales[0];
}
*/
// Get locale from user agent
if(isset($_COOKIE['lang']))
{
$preference = $_COOKIE['lang'];
}
else
{
$preference = Locale::acceptFromHttp(getenv('HTTP_ACCEPT_LANGUAGE'));
}
// Match preferred language to those available, defaulting to generic English
$locale = Locale::lookup(config()->languages, $preference, false, 'en');
// Default Locale
Locale::setDefault($locale);
setlocale(LC_ALL, $locale . '.utf-8');
//putenv("LC_ALL", $locale);
// Default timezone of server
date_default_timezone_set('UTC');
// iconv encoding
iconv_set_encoding("internal_encoding", "UTF-8");
// multibyte encoding
mb_internal_encoding('UTF-8');
// Enable global error handling
set_error_handler(array('\Micro\Error', 'handler'));
register_shutdown_function(array('\Micro\Error', 'fatal'));