blob: 2e8265b15d6069dc2f5b4be1db0d98df8c6966e8 [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 {
Andrey Andreevd444d442014-10-06 00:00:08 +030035 return NULL;
Taufan Adityab2e10b72012-05-27 15:31:53 +070036 }
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
Andrey Andreevc26b9eb2014-02-24 11:31:36 +020068/*
Taufan Adityab2e10b72012-05-27 15:31:53 +070069if ( ! function_exists('load_class'))
Pascal Kriete69c97a72011-04-20 21:44:54 -040070{
Taufan Adityab2e10b72012-05-27 15:31:53 +070071 function load_class($class, $directory = 'libraries', $prefix = 'CI_')
Pascal Kriete69c97a72011-04-20 21:44:54 -040072 {
Alex Bilbied6d11502012-06-02 11:12:55 +010073 if ($directory !== 'core' OR $prefix !== 'CI_')
Taufan Adityab2e10b72012-05-27 15:31:53 +070074 {
75 throw new Exception('Not Implemented: Non-core load_class()');
76 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030077
Taufan Adityab2e10b72012-05-27 15:31:53 +070078 $test = CI_TestCase::instance();
Andrey Andreevf243ce12012-06-09 23:34:21 +030079
Taufan Adityab2e10b72012-05-27 15:31:53 +070080 $obj =& $test->ci_core_class($class);
Andrey Andreevf243ce12012-06-09 23:34:21 +030081
Taufan Adityab2e10b72012-05-27 15:31:53 +070082 if (is_string($obj))
83 {
Andrey Andreevf243ce12012-06-09 23:34:21 +030084 throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class);
Taufan Adityab2e10b72012-05-27 15:31:53 +070085 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030086
Taufan Adityab2e10b72012-05-27 15:31:53 +070087 return $obj;
Pascal Kriete69c97a72011-04-20 21:44:54 -040088 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040089}
Andrey Andreevc26b9eb2014-02-24 11:31:36 +020090*/
Pascal Kriete69c97a72011-04-20 21:44:54 -040091
Pascal Kriete69c97a72011-04-20 21:44:54 -040092// Clean up error messages
93// --------------------------------------------------------------------
94
Taufan Adityab2e10b72012-05-27 15:31:53 +070095if ( ! function_exists('show_error'))
Pascal Kriete69c97a72011-04-20 21:44:54 -040096{
Taufan Adityab2e10b72012-05-27 15:31:53 +070097 function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
98 {
99 throw new RuntimeException('CI Error: '.$message);
100 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400101}
102
Taufan Adityab2e10b72012-05-27 15:31:53 +0700103if ( ! function_exists('show_404'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400104{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700105 function show_404($page = '', $log_error = TRUE)
106 {
107 throw new RuntimeException('CI Error: 404');
108 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400109}
110
Taufan Adityab2e10b72012-05-27 15:31:53 +0700111if ( ! function_exists('_exception_handler'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400112{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700113 function _exception_handler($severity, $message, $filepath, $line)
114 {
115 throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
116 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400117}
118
Pascal Kriete69c97a72011-04-20 21:44:54 -0400119// We assume a few things about our environment ...
120// --------------------------------------------------------------------
Taufan Adityab2e10b72012-05-27 15:31:53 +0700121if ( ! function_exists('is_loaded'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400122{
dchill424f42be52012-10-21 21:31:19 -0400123 function &is_loaded()
Taufan Adityab2e10b72012-05-27 15:31:53 +0700124 {
dchill424f42be52012-10-21 21:31:19 -0400125 $loaded = array();
126 return $loaded;
Taufan Adityab2e10b72012-05-27 15:31:53 +0700127 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400128}
129
Taufan Adityab2e10b72012-05-27 15:31:53 +0700130if ( ! function_exists('log_message'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400131{
Andrey Andreev838c9a92013-09-13 14:05:13 +0300132 function log_message($level, $message)
Taufan Adityab2e10b72012-05-27 15:31:53 +0700133 {
134 return TRUE;
135 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400136}
137
Taufan Adityab2e10b72012-05-27 15:31:53 +0700138if ( ! function_exists('set_status_header'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400139{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700140 function set_status_header($code = 200, $text = '')
141 {
142 return TRUE;
143 }
Andrey Andreevf964b162013-11-12 17:04:55 +0200144}
145
146if ( ! function_exists('is_cli'))
147{
148 // In order to test HTTP functionality, we need to lie about this
149 function is_cli()
150 {
151 return FALSE;
152 }
dchill424f42be52012-10-21 21:31:19 -0400153}