-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCoreIgniter.php
117 lines (99 loc) · 3.7 KB
/
CoreIgniter.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Custom exception for CoreIgniter
*/
class CoreIgniterException extends Exception {}
/**
* CoreIgniter class
*
* Creates a CodeIgniter instance without overhead like URL processing, etc.
* Suitable for accessing session or another native CodeIgniter's resources
* in the same manner as using $this variable.
*/
class CoreIgniter
{
/**
* Version of the library
*/
const VERSION = '1.5';
/**
* Internal storage of CodeIgniter super object instance
*
* @static
* @access protected
*/
protected static $instance;
/**
* Initializes the CodeIgniter super object instance
*
* @static
* @access public
* @param string $basepath Absolute path to CodeIgniter system folder
* @param string $apppath Absolute path to CodeIgniter application folder
* @param string $environment Optional environment of the CodeIgniter instance
* @param string $assign_to_config Optional config from index.php if it is used
* @throws CoreIgniterException if the instance is already initialized or unreachable paths provided
* @return object CodeIgniter instance
*/
public static function init($basepath, $apppath, $environment = null, $assign_to_config = array())
{
if (self::$instance) {
throw new CoreIgniterException('Codeigniter instance is already initialized');
}
if (!is_dir($basepath)) {
throw new CoreIgniterException('Supplied base path is not a directory');
} else {
$basepath = rtrim($basepath, '/').'/';
}
if (!is_dir($apppath)) {
throw new CoreIgniterException('Supplied application path is not a directory');
} else {
$apppath = rtrim($apppath, '/').'/';
}
define('BASEPATH', $basepath);
define('APPPATH', $apppath);
define('EXT', '.php');
define('ENVIRONMENT', $environment ? $environment : 'development');
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');
}
$GLOBALS['CFG'] =& load_class('Config', 'core');
$GLOBALS['CFG']->_assign_to_config($assign_to_config);
$GLOBALS['UNI'] =& load_class('Utf8', 'core');
if (file_exists($basepath.'core/Security.php')) {
$GLOBALS['SEC'] =& load_class('Security', 'core');
}
load_class('Input', 'core');
load_class('Lang', 'core');
require(BASEPATH.'core/Controller.php');
function &get_instance() {
return CI_Controller::get_instance();
}
if (file_exists(APPPATH.'core/'.$GLOBALS['CFG']->config['subclass_prefix'].'Controller.php')) {
require APPPATH.'core/'.$GLOBALS['CFG']->config['subclass_prefix'].'Controller.php';
$class = $GLOBALS['CFG']->config['subclass_prefix'].'Controller';
} else {
$class = 'CI_Controller';
}
self::$instance = new $class();
return self::$instance;
}
/**
* Getter for the CodeIgniter instance object
*
* @static
* @access public
* @throws CoreIgniterException if the instance is not yet initialized
* @return object CI instance
*/
public static function instance()
{
if (!self::$instance) {
throw new CoreIgniterException('CodeIgniter instance is not initialized yet');
}
return self::$instance;
}
}