PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/LP/utility.php

https://github.com/radicaldesigns/jaguar
PHP | 65 lines | 54 code | 11 blank | 0 comment | 6 complexity | 59c2559694aec6450709c9605d708900 MD5 | raw file
Possible License(s): MIT, LGPL-2.1
  1. <?php
  2. if(!defined('AMP_DEBUG_SQL') ) define('AMP_DEBUG_SQL', isset($_GET['lp_debug']) && $_GET['lp_debug']);
  3. function bail($msg = ''){
  4. if(is_array($msg)) $msg = array_dump($msg);
  5. $html = '';
  6. $html .= '
  7. <h2 style="margin-bottom:2px;">ERROR MESSAGE</h2>'.$msg.'<br>
  8. <h2 style="margin-bottom:6px;">BACKTRACE</h2>
  9. '.backtrace().'
  10. ';
  11. echo $html;
  12. trigger_error(strip_tags($msg));
  13. exit();
  14. }
  15. function backtrace(){
  16. $trace = debug_backtrace();
  17. array_shift($trace);
  18. $html = '';
  19. foreach( $trace as $t){
  20. $file = 'FILE: '.$t['file'];
  21. $line = 'LINE: '.$t['line'];
  22. isset($t['class']) ? $function = $t['class'].'->'.$t['function']
  23. : $function = $t['function'];
  24. $function = 'FUNCTION: '. $function;
  25. $html .= "
  26. $file <br>
  27. $line <br>
  28. $function <br><br>
  29. ";
  30. }
  31. return $html;
  32. }
  33. class AMP {
  34. static function array_filter_by_keys( $filter, $data){
  35. if(!$data) return array();
  36. $filtered_array = array_intersect_key( $data, array_flip($filter));
  37. return $filtered_array ? $filtered_array
  38. : array();
  39. }
  40. static function camelcase( $value ) {
  41. return str_replace( ' ', '', ucwords( str_replace( '_', ' ', $value )));
  42. }
  43. static function get_column_names( $db, $table_name ) {
  44. static $table_defs;
  45. if (isset($table_defs[$table_name] )) return $table_defs[$table_name];
  46. $table_defs[$table_name] = $db->MetaColumnNames($table_name);
  47. return $table_defs[$table_name];
  48. }
  49. static function debug_sql( $sql_statement, $source_object = 'sql' ) {
  50. if(!AMP_DEBUG_SQL) return;
  51. print $source_object . ":<BR>\n". $sql_statement . "<P>";
  52. trigger_error( $source_object . " debug: ". $sql_statement );
  53. }
  54. }