-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci_instance.php
85 lines (69 loc) · 2.52 KB
/
ci_instance.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
<?php
/**
* Part of Cli for CodeIgniter
*
* @author Kenji Suzuki <https://github.com/kenjis>
* @license MIT License
* @copyright 2015 Kenji Suzuki
* @link https://github.com/kenjis/codeigniter-cli
*
* Based on http://codeinphp.github.io/post/codeigniter-tip-accessing-codeigniter-instance-outside/
* Thanks!
*/
$cwd = getcwd();
chdir(__DIR__);
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
$system_path = 'vendor/codeigniter/framework/system';
$application_folder = 'application';
$doc_root = 'public';
if (realpath($system_path) !== false) {
$system_path = realpath($system_path) . '/';
}
$system_path = rtrim($system_path, '/') . '/';
define('BASEPATH', str_replace("\\", "/", $system_path));
define('FCPATH', $doc_root . '/');
define('APPPATH', $application_folder . '/');
define('VIEWPATH', $application_folder . '/views/');
require(BASEPATH . 'core/Common.php');
if (file_exists(APPPATH . 'config/' . ENVIRONMENT . '/constants.php')) {
require(APPPATH . 'config/' . ENVIRONMENT . '/constants.php');
} else {
require(APPPATH . 'config/constants.php');
}
$charset = strtoupper(config_item('charset'));
ini_set('default_charset', $charset);
if (extension_loaded('mbstring')) {
define('MB_ENABLED', TRUE);
// mbstring.internal_encoding is deprecated starting with PHP 5.6
// and it's usage triggers E_DEPRECATED messages.
@ini_set('mbstring.internal_encoding', $charset);
// This is required for mb_convert_encoding() to strip invalid characters.
// That's utilized by CI_Utf8, but it's also done for consistency with iconv.
mb_substitute_character('none');
} else {
define('MB_ENABLED', FALSE);
}
// There's an ICONV_IMPL constant, but the PHP manual says that using
// iconv's predefined constants is "strongly discouraged".
if (extension_loaded('iconv')) {
define('ICONV_ENABLED', TRUE);
// iconv.internal_encoding is deprecated starting with PHP 5.6
// and it's usage triggers E_DEPRECATED messages.
@ini_set('iconv.internal_encoding', $charset);
} else {
define('ICONV_ENABLED', FALSE);
}
$GLOBALS['CFG'] = & load_class('Config', 'core');
$GLOBALS['UNI'] = & load_class('Utf8', 'core');
$GLOBALS['SEC'] = & load_class('Security', 'core');
load_class('Loader', 'core');
load_class('Router', 'core');
load_class('Input', 'core');
load_class('Lang', 'core');
require(BASEPATH . 'core/Controller.php');
function &get_instance()
{
return CI_Controller::get_instance();
}
chdir($cwd);
return new CI_Controller();