2 /*------------------------------------------------------------
3 * CarbonPHP framework (C) Tom Bell
4 * http://tombell.org.uk
5 *------------------------------------------------------------*/
7 if (!defined('CARBON_PATH'))
9 exit('Direct script access is not allowed.');
12 function & load_class($class_name, $instantiate = true)
14 static $class_objects = array();
16 if (isset($class_objects[$class_name]))
18 return $class_objects[$class_name];
21 if (file_exists(APP_PATH
. 'libraries/' . get_config_item('subclass_prefix') . $class_name . FILE_EXT
))
23 require(CARBON_PATH
. 'libraries/' . $class_name . FILE_EXT
);
24 require(APP_PATH
. 'libraries/' . get_config_item('subclass_prexfix') . $class_name . FILE_EXT
);
29 if (file_exists(APP_PATH
. 'libraries/' . $class_name . FILE_EXT
))
31 require(APP_PATH
. 'libraries/' . $class_name . FILE_EXT
);
36 require(CARBON_PATH
. 'libraries/' . $class_name . FILE_EXT
);
41 if ($instantiate == false)
43 $class_objects[$class_name] = true;
44 return $class_objects[$class_name];
47 if ($is_subclass == true)
49 $full_class_name = get_config_item('subclass_prefix') . $class_name;
50 $class_objects[$class_name] = new $full_class_name();
51 return $class_objects[$class_name];
54 $full_class_name = ($class_name != 'Controller') ?
'Carbon_' . $class_name : $class_name;
55 $class_objects[$class_name] = new $full_class_name();
56 return $class_objects[$class_name];
59 function & load_config()
61 static $carbon_config;
63 if (isset($carbon_config))
65 return $carbon_config[0];
68 if (!file_exists(APP_PATH
. 'config/config' . FILE_EXT
))
70 exit('The CarbonPHP configuration file does not exist: config' . FILE_EXT
);
73 require(APP_PATH
. 'config/config' . FILE_EXT
);
75 if (!isset($config) ||
!is_array($config))
77 exit('The CarbonPHP configuration file is incorrectly formatted: config' . FILE_EXT
);
80 $carbon_config[0] = $config;
81 return $carbon_config[0];
84 function get_config_item($config_item)
86 static $config_items = array();
88 if (isset($config_items[$config_item]))
90 return $config_items[$config_item];
93 $config =& load_config();
95 if (!isset($config[$config_item]))
100 $config_items[$config_item] = $config[$config_item];
101 return $config_items[$config_item];
104 function display_error($error_message)
106 $exception =& load_class('Exception');
107 echo $exception->display_error('An error has been encountered', $error_message);
111 function display_not_found($page = '')
113 $exception =& load_class('Exception');
114 $exception->display_not_found($page);
118 function log_message($level = 'error', $message, $php_error = false)
121 $config =& load_config();
123 if (get_config_item('logging_threshold') == 0)
128 $logging =& load_class('Logging');
129 $logging->write_log_message($level, $message, $php_error);
132 function exception_handler($severity, $message, $file_path, $line_number)
134 if ($severity == E_STRICT
)
139 $exception =& load_class('Exception');
141 if (($severity & error_reporting()) == $severity)
143 $exception->display_php_error($severity, $message, $file_path, $line_number);
146 $config =& load_config();
148 if (get_config_item('logging_threshold') == 0)
153 $exception->log_exception($severity, $message, $file_path, $line_number);