/lib/LP/utility.php
PHP | 65 lines | 54 code | 11 blank | 0 comment | 6 complexity | 59c2559694aec6450709c9605d708900 MD5 | raw file
Possible License(s): MIT, LGPL-2.1
- <?php
- if(!defined('AMP_DEBUG_SQL') ) define('AMP_DEBUG_SQL', isset($_GET['lp_debug']) && $_GET['lp_debug']);
- function bail($msg = ''){
- if(is_array($msg)) $msg = array_dump($msg);
- $html = '';
- $html .= '
- <h2 style="margin-bottom:2px;">ERROR MESSAGE</h2>'.$msg.'<br>
- <h2 style="margin-bottom:6px;">BACKTRACE</h2>
- '.backtrace().'
- ';
- echo $html;
- trigger_error(strip_tags($msg));
- exit();
- }
- function backtrace(){
- $trace = debug_backtrace();
- array_shift($trace);
- $html = '';
- foreach( $trace as $t){
- $file = 'FILE: '.$t['file'];
- $line = 'LINE: '.$t['line'];
- isset($t['class']) ? $function = $t['class'].'->'.$t['function']
- : $function = $t['function'];
- $function = 'FUNCTION: '. $function;
- $html .= "
- $file <br>
- $line <br>
- $function <br><br>
- ";
- }
- return $html;
- }
- class AMP {
- static function array_filter_by_keys( $filter, $data){
- if(!$data) return array();
- $filtered_array = array_intersect_key( $data, array_flip($filter));
- return $filtered_array ? $filtered_array
- : array();
- }
-
- static function camelcase( $value ) {
- return str_replace( ' ', '', ucwords( str_replace( '_', ' ', $value )));
- }
- static function get_column_names( $db, $table_name ) {
- static $table_defs;
- if (isset($table_defs[$table_name] )) return $table_defs[$table_name];
- $table_defs[$table_name] = $db->MetaColumnNames($table_name);
- return $table_defs[$table_name];
- }
-
- static function debug_sql( $sql_statement, $source_object = 'sql' ) {
- if(!AMP_DEBUG_SQL) return;
- print $source_object . ":<BR>\n". $sql_statement . "<P>";
- trigger_error( $source_object . " debug: ". $sql_statement );
- }
- }