blob: a655ee1dbefff4574d493e7c05f331a0f14c3f2d [file] [log] [blame]
Pascal Kriete69c97a72011-04-20 21:44:54 -04001<?php
2
3// Set up the global CI functions in their most minimal core representation
4
Taufan Adityab2e10b72012-05-27 15:31:53 +07005if ( ! function_exists('get_instance'))
Pascal Kriete69c97a72011-04-20 21:44:54 -04006{
Andrey Andreevf243ce12012-06-09 23:34:21 +03007 function &get_instance()
Taufan Adityab2e10b72012-05-27 15:31:53 +07008 {
9 $test = CI_TestCase::instance();
Andrey Andreev36de42e2012-06-10 13:55:55 +030010 $test = $test->ci_instance();
11 return $test;
Taufan Adityab2e10b72012-05-27 15:31:53 +070012 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040013}
14
Pascal Kriete69c97a72011-04-20 21:44:54 -040015// --------------------------------------------------------------------
16
Taufan Adityab2e10b72012-05-27 15:31:53 +070017if ( ! function_exists('get_config'))
18{
Andrey Andreevf243ce12012-06-09 23:34:21 +030019 function &get_config()
20 {
Taufan Adityab2e10b72012-05-27 15:31:53 +070021 $test = CI_TestCase::instance();
Andrey Andreev62fd52d2012-06-10 07:11:41 +030022 $config = $test->ci_get_config();
23 return $config;
Taufan Adityab2e10b72012-05-27 15:31:53 +070024 }
25}
26
27if ( ! function_exists('config_item'))
28{
29 function config_item($item)
30 {
31 $config =& get_config();
Andrey Andreevf243ce12012-06-09 23:34:21 +030032
Taufan Adityab2e10b72012-05-27 15:31:53 +070033 if ( ! isset($config[$item]))
34 {
35 return FALSE;
36 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030037
Taufan Adityab2e10b72012-05-27 15:31:53 +070038 return $config[$item];
Pascal Kriete88b29632011-04-21 01:21:55 -040039 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040040}
41
42// --------------------------------------------------------------------
43
Taufan Adityab2e10b72012-05-27 15:31:53 +070044if ( ! function_exists('load_class'))
Pascal Kriete69c97a72011-04-20 21:44:54 -040045{
Taufan Adityab2e10b72012-05-27 15:31:53 +070046 function load_class($class, $directory = 'libraries', $prefix = 'CI_')
Pascal Kriete69c97a72011-04-20 21:44:54 -040047 {
Alex Bilbied6d11502012-06-02 11:12:55 +010048 if ($directory !== 'core' OR $prefix !== 'CI_')
Taufan Adityab2e10b72012-05-27 15:31:53 +070049 {
50 throw new Exception('Not Implemented: Non-core load_class()');
51 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030052
Taufan Adityab2e10b72012-05-27 15:31:53 +070053 $test = CI_TestCase::instance();
Andrey Andreevf243ce12012-06-09 23:34:21 +030054
Taufan Adityab2e10b72012-05-27 15:31:53 +070055 $obj =& $test->ci_core_class($class);
Andrey Andreevf243ce12012-06-09 23:34:21 +030056
Taufan Adityab2e10b72012-05-27 15:31:53 +070057 if (is_string($obj))
58 {
Andrey Andreevf243ce12012-06-09 23:34:21 +030059 throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class);
Taufan Adityab2e10b72012-05-27 15:31:53 +070060 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030061
Taufan Adityab2e10b72012-05-27 15:31:53 +070062 return $obj;
Pascal Kriete69c97a72011-04-20 21:44:54 -040063 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040064}
65
66// This is sort of meh. Should probably be mocked up with
67// controllable output, so that we can test some of our
68// security code. The function itself will be tested in the
69// bootstrap testsuite.
70// --------------------------------------------------------------------
71
Taufan Adityab2e10b72012-05-27 15:31:53 +070072if ( ! function_exists('remove_invisible_characters'))
Pascal Kriete69c97a72011-04-20 21:44:54 -040073{
Taufan Adityab2e10b72012-05-27 15:31:53 +070074 function remove_invisible_characters($str, $url_encoded = TRUE)
Pascal Kriete69c97a72011-04-20 21:44:54 -040075 {
Taufan Adityab2e10b72012-05-27 15:31:53 +070076 $non_displayables = array();
Andrey Andreevf243ce12012-06-09 23:34:21 +030077
Taufan Adityab2e10b72012-05-27 15:31:53 +070078 // every control character except newline (dec 10)
79 // carriage return (dec 13), and horizontal tab (dec 09)
Andrey Andreevf243ce12012-06-09 23:34:21 +030080
Taufan Adityab2e10b72012-05-27 15:31:53 +070081 if ($url_encoded)
82 {
83 $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
84 $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
85 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030086
Taufan Adityab2e10b72012-05-27 15:31:53 +070087 $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
Pascal Kriete69c97a72011-04-20 21:44:54 -040088
Taufan Adityab2e10b72012-05-27 15:31:53 +070089 do
90 {
91 $str = preg_replace($non_displayables, '', $str, -1, $count);
92 }
93 while ($count);
Pascal Kriete69c97a72011-04-20 21:44:54 -040094
Taufan Adityab2e10b72012-05-27 15:31:53 +070095 return $str;
96 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040097}
98
99
100// Clean up error messages
101// --------------------------------------------------------------------
102
Taufan Adityab2e10b72012-05-27 15:31:53 +0700103if ( ! function_exists('show_error'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400104{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700105 function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
106 {
107 throw new RuntimeException('CI Error: '.$message);
108 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400109}
110
Taufan Adityab2e10b72012-05-27 15:31:53 +0700111if ( ! function_exists('show_404'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400112{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700113 function show_404($page = '', $log_error = TRUE)
114 {
115 throw new RuntimeException('CI Error: 404');
116 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400117}
118
Taufan Adityab2e10b72012-05-27 15:31:53 +0700119if ( ! function_exists('_exception_handler'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400120{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700121 function _exception_handler($severity, $message, $filepath, $line)
122 {
123 throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
124 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400125}
126
127
128// We assume a few things about our environment ...
129// --------------------------------------------------------------------
130
Taufan Adityab2e10b72012-05-27 15:31:53 +0700131if ( ! function_exists('is_php'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400132{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700133 function is_php($version = '5.0.0')
134 {
135 return ! (version_compare(PHP_VERSION, $version) < 0);
136 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400137}
138
Taufan Adityab2e10b72012-05-27 15:31:53 +0700139if ( ! function_exists('is_really_writable'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400140{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700141 function is_really_writable($file)
142 {
143 return is_writable($file);
144 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400145}
146
Taufan Adityab2e10b72012-05-27 15:31:53 +0700147if ( ! function_exists('is_loaded'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400148{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700149 function is_loaded()
150 {
151 throw new Exception('Bad Isolation: mock up environment');
152 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400153}
154
Taufan Adityab2e10b72012-05-27 15:31:53 +0700155if ( ! function_exists('log_message'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400156{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700157 function log_message($level = 'error', $message, $php_error = FALSE)
158 {
159 return TRUE;
160 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400161}
162
Taufan Adityab2e10b72012-05-27 15:31:53 +0700163if ( ! function_exists('set_status_header'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400164{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700165 function set_status_header($code = 200, $text = '')
166 {
167 return TRUE;
168 }
Andrey Andreevf243ce12012-06-09 23:34:21 +0300169}