ci_instance.php ➔ get_instance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Part of Cli for CodeIgniter
4
 *
5
 * @author     Kenji Suzuki <https://github.com/kenjis>
6
 * @license    MIT License
7
 * @copyright  2015 Kenji Suzuki
8
 * @link       https://github.com/kenjis/codeigniter-cli
9
 *
10
 * Based on http://codeinphp.github.io/post/codeigniter-tip-accessing-codeigniter-instance-outside/
11
 * Thanks!
12
 */
13
14
$cwd = getcwd();
15
chdir(__DIR__);
16
17
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
18
19
$system_path        = 'vendor/codeigniter/framework/system';
20
$application_folder = 'application';
21
$doc_root           = 'public';
22
23
if (realpath($system_path) !== false) {
24
    $system_path = realpath($system_path) . '/';
25
}
26
$system_path = rtrim($system_path, '/') . '/';
27
28
define('BASEPATH', str_replace("\\", "/", $system_path));
29
define('FCPATH', $doc_root . '/');
30
define('APPPATH', $application_folder . '/');
31
define('VIEWPATH', $application_folder . '/views/');
32
33
require(BASEPATH . 'core/Common.php');
34
35
if (file_exists(APPPATH . 'config/' . ENVIRONMENT . '/constants.php')) {
36
    require(APPPATH . 'config/' . ENVIRONMENT . '/constants.php');
37
} else {
38
    require(APPPATH . 'config/constants.php');
39
}
40
41
$charset = strtoupper(config_item('charset'));
42
ini_set('default_charset', $charset);
43
44
if (extension_loaded('mbstring')) {
45
    define('MB_ENABLED', TRUE);
46
    // mbstring.internal_encoding is deprecated starting with PHP 5.6
47
    // and it's usage triggers E_DEPRECATED messages.
48
    @ini_set('mbstring.internal_encoding', $charset);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
49
    // This is required for mb_convert_encoding() to strip invalid characters.
50
    // That's utilized by CI_Utf8, but it's also done for consistency with iconv.
51
    mb_substitute_character('none');
52
} else {
53
    define('MB_ENABLED', FALSE);
54
}
55
56
// There's an ICONV_IMPL constant, but the PHP manual says that using
57
// iconv's predefined constants is "strongly discouraged".
58
if (extension_loaded('iconv')) {
59
    define('ICONV_ENABLED', TRUE);
60
    // iconv.internal_encoding is deprecated starting with PHP 5.6
61
    // and it's usage triggers E_DEPRECATED messages.
62
    @ini_set('iconv.internal_encoding', $charset);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
63
} else {
64
    define('ICONV_ENABLED', FALSE);
65
}
66
67
$GLOBALS['CFG'] = & load_class('Config', 'core');
68
$GLOBALS['UNI'] = & load_class('Utf8', 'core');
69
$GLOBALS['SEC'] = & load_class('Security', 'core');
70
71
load_class('Loader', 'core');
72
load_class('Router', 'core');
73
load_class('Input', 'core');
74
load_class('Lang', 'core');
75
76
require(BASEPATH . 'core/Controller.php');
77
78
function &get_instance()
79
{
80
    return CI_Controller::get_instance();
81
}
82
83
chdir($cwd);
84
85
return new CI_Controller();
86