blob: 9eb6b0954277fea0eca3353399755b7d9ed371d6 [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
dchill427ecc5cd2012-10-12 16:25:51 -040042if ( ! function_exists('get_mimes'))
43{
44 /**
45 * Returns the MIME types array from config/mimes.php
46 *
47 * @return array
48 */
49 function &get_mimes()
50 {
51 static $_mimes = array();
52
53 if (empty($_mimes))
54 {
55 $path = realpath(PROJECT_BASE.'application/config/mimes.php');
56 if (is_file($path))
57 {
58 $_mimes = include($path);
59 }
60 }
61
62 return $_mimes;
63 }
64}
65
Pascal Kriete69c97a72011-04-20 21:44:54 -040066// --------------------------------------------------------------------
67
Taufan Adityab2e10b72012-05-27 15:31:53 +070068if ( ! function_exists('load_class'))
Pascal Kriete69c97a72011-04-20 21:44:54 -040069{
Taufan Adityab2e10b72012-05-27 15:31:53 +070070 function load_class($class, $directory = 'libraries', $prefix = 'CI_')
Pascal Kriete69c97a72011-04-20 21:44:54 -040071 {
Alex Bilbied6d11502012-06-02 11:12:55 +010072 if ($directory !== 'core' OR $prefix !== 'CI_')
Taufan Adityab2e10b72012-05-27 15:31:53 +070073 {
74 throw new Exception('Not Implemented: Non-core load_class()');
75 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030076
Taufan Adityab2e10b72012-05-27 15:31:53 +070077 $test = CI_TestCase::instance();
Andrey Andreevf243ce12012-06-09 23:34:21 +030078
Taufan Adityab2e10b72012-05-27 15:31:53 +070079 $obj =& $test->ci_core_class($class);
Andrey Andreevf243ce12012-06-09 23:34:21 +030080
Taufan Adityab2e10b72012-05-27 15:31:53 +070081 if (is_string($obj))
82 {
Andrey Andreevf243ce12012-06-09 23:34:21 +030083 throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class);
Taufan Adityab2e10b72012-05-27 15:31:53 +070084 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030085
Taufan Adityab2e10b72012-05-27 15:31:53 +070086 return $obj;
Pascal Kriete69c97a72011-04-20 21:44:54 -040087 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040088}
89
Pascal Kriete69c97a72011-04-20 21:44:54 -040090// Clean up error messages
91// --------------------------------------------------------------------
92
Taufan Adityab2e10b72012-05-27 15:31:53 +070093if ( ! function_exists('show_error'))
Pascal Kriete69c97a72011-04-20 21:44:54 -040094{
Taufan Adityab2e10b72012-05-27 15:31:53 +070095 function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
96 {
97 throw new RuntimeException('CI Error: '.$message);
98 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040099}
100
Taufan Adityab2e10b72012-05-27 15:31:53 +0700101if ( ! function_exists('show_404'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400102{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700103 function show_404($page = '', $log_error = TRUE)
104 {
105 throw new RuntimeException('CI Error: 404');
106 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400107}
108
Taufan Adityab2e10b72012-05-27 15:31:53 +0700109if ( ! function_exists('_exception_handler'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400110{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700111 function _exception_handler($severity, $message, $filepath, $line)
112 {
113 throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
114 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400115}
116
Pascal Kriete69c97a72011-04-20 21:44:54 -0400117// We assume a few things about our environment ...
118// --------------------------------------------------------------------
Taufan Adityab2e10b72012-05-27 15:31:53 +0700119if ( ! function_exists('is_loaded'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400120{
dchill424f42be52012-10-21 21:31:19 -0400121 function &is_loaded()
Taufan Adityab2e10b72012-05-27 15:31:53 +0700122 {
dchill424f42be52012-10-21 21:31:19 -0400123 $loaded = array();
124 return $loaded;
Taufan Adityab2e10b72012-05-27 15:31:53 +0700125 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400126}
127
Taufan Adityab2e10b72012-05-27 15:31:53 +0700128if ( ! function_exists('log_message'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400129{
Andrey Andreev838c9a92013-09-13 14:05:13 +0300130 function log_message($level, $message)
Taufan Adityab2e10b72012-05-27 15:31:53 +0700131 {
132 return TRUE;
133 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400134}
135
Taufan Adityab2e10b72012-05-27 15:31:53 +0700136if ( ! function_exists('set_status_header'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400137{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700138 function set_status_header($code = 200, $text = '')
139 {
140 return TRUE;
141 }
Andrey Andreevf964b162013-11-12 17:04:55 +0200142}
143
144if ( ! function_exists('is_cli'))
145{
146 // In order to test HTTP functionality, we need to lie about this
147 function is_cli()
148 {
149 return FALSE;
150 }
dchill424f42be52012-10-21 21:31:19 -0400151}