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 | |
| 5 | function &get_instance() |
| 6 | { |
Pascal Kriete | fe372e3 | 2011-04-21 00:59:45 -0400 | [diff] [blame] | 7 | $test = CI_TestCase::instance(); |
| 8 | $instance = $test->ci_instance(); |
| 9 | return $instance; |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 10 | } |
| 11 | |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 12 | // -------------------------------------------------------------------- |
| 13 | |
Pascal Kriete | fe372e3 | 2011-04-21 00:59:45 -0400 | [diff] [blame] | 14 | function &get_config() { |
| 15 | $test = CI_TestCase::instance(); |
Pascal Kriete | 88b2963 | 2011-04-21 01:21:55 -0400 | [diff] [blame] | 16 | $config = $test->ci_get_config(); |
Pascal Kriete | fe372e3 | 2011-04-21 00:59:45 -0400 | [diff] [blame] | 17 | |
| 18 | return $config; |
| 19 | } |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 20 | |
| 21 | function config_item($item) |
| 22 | { |
Pascal Kriete | 88b2963 | 2011-04-21 01:21:55 -0400 | [diff] [blame] | 23 | $config =& get_config(); |
| 24 | |
| 25 | if ( ! isset($config[$item])) |
| 26 | { |
| 27 | return FALSE; |
| 28 | } |
| 29 | |
| 30 | return $config[$item]; |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | // -------------------------------------------------------------------- |
| 34 | |
| 35 | function load_class($class, $directory = 'libraries', $prefix = 'CI_') |
| 36 | { |
| 37 | if ($directory != 'core' OR $prefix != 'CI_') |
| 38 | { |
| 39 | throw new Exception('Not Implemented: Non-core load_class()'); |
| 40 | } |
| 41 | |
Pascal Kriete | fe372e3 | 2011-04-21 00:59:45 -0400 | [diff] [blame] | 42 | $test = CI_TestCase::instance(); |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 43 | |
| 44 | $obj =& $test->ci_core_class($class); |
| 45 | |
| 46 | if (is_string($obj)) |
| 47 | { |
| 48 | throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class.''); |
| 49 | } |
| 50 | |
| 51 | return $obj; |
| 52 | } |
| 53 | |
| 54 | // This is sort of meh. Should probably be mocked up with |
| 55 | // controllable output, so that we can test some of our |
| 56 | // security code. The function itself will be tested in the |
| 57 | // bootstrap testsuite. |
| 58 | // -------------------------------------------------------------------- |
| 59 | |
| 60 | function remove_invisible_characters($str, $url_encoded = TRUE) |
| 61 | { |
| 62 | $non_displayables = array(); |
| 63 | |
| 64 | // every control character except newline (dec 10) |
| 65 | // carriage return (dec 13), and horizontal tab (dec 09) |
| 66 | |
| 67 | if ($url_encoded) |
| 68 | { |
| 69 | $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 |
| 70 | $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 |
| 71 | } |
| 72 | |
| 73 | $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 |
| 74 | |
| 75 | do |
| 76 | { |
| 77 | $str = preg_replace($non_displayables, '', $str, -1, $count); |
| 78 | } |
| 79 | while ($count); |
| 80 | |
| 81 | return $str; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | // Clean up error messages |
| 86 | // -------------------------------------------------------------------- |
| 87 | |
| 88 | function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') |
| 89 | { |
Hamza Bhatti | 7729faa | 2012-03-10 13:07:05 +0400 | [diff] [blame] | 90 | throw new RuntimeException('CI Error: '.$message); |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | function show_404($page = '', $log_error = TRUE) |
| 94 | { |
Hamza Bhatti | 7729faa | 2012-03-10 13:07:05 +0400 | [diff] [blame] | 95 | throw new RuntimeException('CI Error: 404'); |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | function _exception_handler($severity, $message, $filepath, $line) |
| 99 | { |
Hamza Bhatti | 7729faa | 2012-03-10 13:07:05 +0400 | [diff] [blame] | 100 | throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line); |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | // We assume a few things about our environment ... |
| 105 | // -------------------------------------------------------------------- |
| 106 | |
| 107 | function is_php($version = '5.0.0') |
| 108 | { |
| 109 | return ! (version_compare(PHP_VERSION, $version) < 0); |
| 110 | } |
| 111 | |
| 112 | function is_really_writable($file) |
| 113 | { |
| 114 | return is_writable($file); |
| 115 | } |
| 116 | |
| 117 | function is_loaded() |
| 118 | { |
| 119 | throw new Exception('Bad Isolation: mock up environment'); |
| 120 | } |
| 121 | |
| 122 | function log_message($level = 'error', $message, $php_error = FALSE) |
| 123 | { |
| 124 | return TRUE; |
| 125 | } |
| 126 | |
| 127 | function set_status_header($code = 200, $text = '') |
| 128 | { |
| 129 | return TRUE; |
| 130 | } |
| 131 | |
Hamza Bhatti | 7729faa | 2012-03-10 13:07:05 +0400 | [diff] [blame] | 132 | // EOF |