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