blob: 4a832587df594537b6010ebc2df8bd2c0e1e4947 [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();
Pascal Kriete88b29632011-04-21 01:21:55 -040016 $config = $test->ci_get_config();
Pascal Krietefe372e32011-04-21 00:59:45 -040017
18 return $config;
19}
Pascal Kriete69c97a72011-04-20 21:44:54 -040020
21function config_item($item)
22{
Pascal Kriete88b29632011-04-21 01:21:55 -040023 $config =& get_config();
24
25 if ( ! isset($config[$item]))
26 {
27 return FALSE;
28 }
29
30 return $config[$item];
Pascal Kriete69c97a72011-04-20 21:44:54 -040031}
32
33// --------------------------------------------------------------------
34
35function 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 Krietefe372e32011-04-21 00:59:45 -040042 $test = CI_TestCase::instance();
Pascal Kriete69c97a72011-04-20 21:44:54 -040043
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
60function 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
88function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
89{
Hamza Bhatti7729faa2012-03-10 13:07:05 +040090 throw new RuntimeException('CI Error: '.$message);
Pascal Kriete69c97a72011-04-20 21:44:54 -040091}
92
93function show_404($page = '', $log_error = TRUE)
94{
Hamza Bhatti7729faa2012-03-10 13:07:05 +040095 throw new RuntimeException('CI Error: 404');
Pascal Kriete69c97a72011-04-20 21:44:54 -040096}
97
98function _exception_handler($severity, $message, $filepath, $line)
99{
Hamza Bhatti7729faa2012-03-10 13:07:05 +0400100 throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
Pascal Kriete69c97a72011-04-20 21:44:54 -0400101}
102
103
104// We assume a few things about our environment ...
105// --------------------------------------------------------------------
106
107function is_php($version = '5.0.0')
108{
109 return ! (version_compare(PHP_VERSION, $version) < 0);
110}
111
112function is_really_writable($file)
113{
114 return is_writable($file);
115}
116
117function is_loaded()
118{
119 throw new Exception('Bad Isolation: mock up environment');
120}
121
122function log_message($level = 'error', $message, $php_error = FALSE)
123{
124 return TRUE;
125}
126
127function set_status_header($code = 200, $text = '')
128{
129 return TRUE;
130}
131
Hamza Bhatti7729faa2012-03-10 13:07:05 +0400132// EOF