blob: 994e9bc22ae5fdb66751fc61da9a928645708105 [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
5function &get_instance()
6{
Pascal Krietefe372e32011-04-21 00:59:45 -04007 $test = CI_TestCase::instance();
8 $instance = $test->ci_instance();
9 return $instance;
Pascal Kriete69c97a72011-04-20 21:44:54 -040010}
11
Pascal Kriete69c97a72011-04-20 21:44:54 -040012// --------------------------------------------------------------------
13
Pascal Krietefe372e32011-04-21 00:59:45 -040014function &get_config() {
15 $test = CI_TestCase::instance();
16 $config = $test->ci_config_array();
17
18 return $config;
19}
Pascal Kriete69c97a72011-04-20 21:44:54 -040020
21function config_item($item)
22{
Pascal Krietefe372e32011-04-21 00:59:45 -040023 $test = CI_TestCase::instance();
24 return $test->ci_config_item($item);
Pascal Kriete69c97a72011-04-20 21:44:54 -040025}
26
27// --------------------------------------------------------------------
28
29function 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 Krietefe372e32011-04-21 00:59:45 -040036 $test = CI_TestCase::instance();
Pascal Kriete69c97a72011-04-20 21:44:54 -040037
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
54function 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
82function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
83{
84 throw new Exception('CI Error: '.$message);
85}
86
87function show_404($page = '', $log_error = TRUE)
88{
89 throw new Exception('CI Error: 404');
90}
91
92function _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
101function is_php($version = '5.0.0')
102{
103 return ! (version_compare(PHP_VERSION, $version) < 0);
104}
105
106function is_really_writable($file)
107{
108 return is_writable($file);
109}
110
111function is_loaded()
112{
113 throw new Exception('Bad Isolation: mock up environment');
114}
115
116function log_message($level = 'error', $message, $php_error = FALSE)
117{
118 return TRUE;
119}
120
121function set_status_header($code = 200, $text = '')
122{
123 return TRUE;
124}
125
126// EOF