Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | // Set up the global CI functions in their most minimal core representation |
| 4 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 5 | if ( ! function_exists('get_instance')) |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 6 | { |
Andrey Andreev | f243ce1 | 2012-06-09 23:34:21 +0300 | [diff] [blame] | 7 | function &get_instance() |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 8 | { |
| 9 | $test = CI_TestCase::instance(); |
Andrey Andreev | 36de42e | 2012-06-10 13:55:55 +0300 | [diff] [blame] | 10 | $test = $test->ci_instance(); |
| 11 | return $test; |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 12 | } |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 13 | } |
| 14 | |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 15 | // -------------------------------------------------------------------- |
| 16 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 17 | if ( ! function_exists('get_config')) |
| 18 | { |
Andrey Andreev | f243ce1 | 2012-06-09 23:34:21 +0300 | [diff] [blame] | 19 | function &get_config() |
| 20 | { |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 21 | $test = CI_TestCase::instance(); |
Andrey Andreev | 62fd52d | 2012-06-10 07:11:41 +0300 | [diff] [blame] | 22 | $config = $test->ci_get_config(); |
| 23 | return $config; |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 24 | } |
| 25 | } |
| 26 | |
| 27 | if ( ! function_exists('config_item')) |
| 28 | { |
| 29 | function config_item($item) |
| 30 | { |
| 31 | $config =& get_config(); |
Andrey Andreev | f243ce1 | 2012-06-09 23:34:21 +0300 | [diff] [blame] | 32 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 33 | if ( ! isset($config[$item])) |
| 34 | { |
| 35 | return FALSE; |
| 36 | } |
Andrey Andreev | f243ce1 | 2012-06-09 23:34:21 +0300 | [diff] [blame] | 37 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 38 | return $config[$item]; |
Pascal Kriete | 88b2963 | 2011-04-21 01:21:55 -0400 | [diff] [blame] | 39 | } |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 40 | } |
| 41 | |
dchill42 | 7ecc5cd | 2012-10-12 16:25:51 -0400 | [diff] [blame] | 42 | if ( ! function_exists('get_mimes')) |
| 43 | { |
| 44 | /** |
| 45 | * Returns the MIME types array from config/mimes.php |
| 46 | * |
| 47 | * @return array |
| 48 | */ |
| 49 | function &get_mimes() |
| 50 | { |
| 51 | static $_mimes = array(); |
| 52 | |
| 53 | if (empty($_mimes)) |
| 54 | { |
| 55 | $path = realpath(PROJECT_BASE.'application/config/mimes.php'); |
| 56 | if (is_file($path)) |
| 57 | { |
| 58 | $_mimes = include($path); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return $_mimes; |
| 63 | } |
| 64 | } |
| 65 | |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 66 | // -------------------------------------------------------------------- |
| 67 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 68 | if ( ! function_exists('load_class')) |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 69 | { |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 70 | function load_class($class, $directory = 'libraries', $prefix = 'CI_') |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 71 | { |
Alex Bilbie | d6d1150 | 2012-06-02 11:12:55 +0100 | [diff] [blame] | 72 | if ($directory !== 'core' OR $prefix !== 'CI_') |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 73 | { |
| 74 | throw new Exception('Not Implemented: Non-core load_class()'); |
| 75 | } |
Andrey Andreev | f243ce1 | 2012-06-09 23:34:21 +0300 | [diff] [blame] | 76 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 77 | $test = CI_TestCase::instance(); |
Andrey Andreev | f243ce1 | 2012-06-09 23:34:21 +0300 | [diff] [blame] | 78 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 79 | $obj =& $test->ci_core_class($class); |
Andrey Andreev | f243ce1 | 2012-06-09 23:34:21 +0300 | [diff] [blame] | 80 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 81 | if (is_string($obj)) |
| 82 | { |
Andrey Andreev | f243ce1 | 2012-06-09 23:34:21 +0300 | [diff] [blame] | 83 | throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class); |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 84 | } |
Andrey Andreev | f243ce1 | 2012-06-09 23:34:21 +0300 | [diff] [blame] | 85 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 86 | return $obj; |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 87 | } |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 88 | } |
| 89 | |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 90 | // Clean up error messages |
| 91 | // -------------------------------------------------------------------- |
| 92 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 93 | if ( ! function_exists('show_error')) |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 94 | { |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 95 | function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') |
| 96 | { |
| 97 | throw new RuntimeException('CI Error: '.$message); |
| 98 | } |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 99 | } |
| 100 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 101 | if ( ! function_exists('show_404')) |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 102 | { |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 103 | function show_404($page = '', $log_error = TRUE) |
| 104 | { |
| 105 | throw new RuntimeException('CI Error: 404'); |
| 106 | } |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 109 | if ( ! function_exists('_exception_handler')) |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 110 | { |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 111 | function _exception_handler($severity, $message, $filepath, $line) |
| 112 | { |
| 113 | throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line); |
| 114 | } |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 117 | // We assume a few things about our environment ... |
| 118 | // -------------------------------------------------------------------- |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 119 | if ( ! function_exists('is_loaded')) |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 120 | { |
dchill42 | 4f42be5 | 2012-10-21 21:31:19 -0400 | [diff] [blame] | 121 | function &is_loaded() |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 122 | { |
dchill42 | 4f42be5 | 2012-10-21 21:31:19 -0400 | [diff] [blame] | 123 | $loaded = array(); |
| 124 | return $loaded; |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 125 | } |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 128 | if ( ! function_exists('log_message')) |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 129 | { |
Andrey Andreev | 838c9a9 | 2013-09-13 14:05:13 +0300 | [diff] [blame] | 130 | function log_message($level, $message) |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 131 | { |
| 132 | return TRUE; |
| 133 | } |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 136 | if ( ! function_exists('set_status_header')) |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 137 | { |
Taufan Aditya | b2e10b7 | 2012-05-27 15:31:53 +0700 | [diff] [blame] | 138 | function set_status_header($code = 200, $text = '') |
| 139 | { |
| 140 | return TRUE; |
| 141 | } |
Andrey Andreev | f964b16 | 2013-11-12 17:04:55 +0200 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | if ( ! function_exists('is_cli')) |
| 145 | { |
| 146 | // In order to test HTTP functionality, we need to lie about this |
| 147 | function is_cli() |
| 148 | { |
| 149 | return FALSE; |
| 150 | } |
dchill42 | 4f42be5 | 2012-10-21 21:31:19 -0400 | [diff] [blame] | 151 | } |