| 1 |
<?php |
| 2 |
|
| 3 |
namespace CodesVault\Howdyqb; |
| 4 |
|
| 5 |
class Utilities |
| 6 |
{ |
| 7 |
public static function throughException($exception) |
| 8 |
{ |
| 9 |
if (php_sapi_name() !== 'cli') { |
| 10 |
printf("<div class='howdy-qb'>"); |
| 11 |
$error_msg = sprintf( |
| 12 |
"<strong style='color: #d60202;'>%s</strong> <strong style='color: red;'>%s</strong>", |
| 13 |
'ERROR Message:', |
| 14 |
$exception->getMessage() |
| 15 |
); |
| 16 |
printf($error_msg); |
| 17 |
printf("<br /><strong>In %s %s</strong><br /><br />", $exception->getFile(), $exception->getLine()); |
| 18 |
printf( |
| 19 |
"<div style='max-height: 300px; overflow: scroll;'><strong>Trace:</strong> <pre>%s</pre> </div><br />", |
| 20 |
$exception->getTraceAsString() |
| 21 |
); |
| 22 |
printf("</div>"); |
| 23 |
} |
| 24 |
|
| 25 |
throw new \Exception($exception->getMessage()); |
| 26 |
} |
| 27 |
|
| 28 |
public static function get_placeholder($db, $value) |
| 29 |
{ |
| 30 |
if ($db instanceof \wpdb) { |
| 31 |
if (is_array($value)) return '%s'; |
| 32 |
if (is_string($value)) return '%s'; |
| 33 |
if (is_integer($value)) return '%d'; |
| 34 |
if (is_float($value)) return '%f'; |
| 35 |
} |
| 36 |
return "?"; |
| 37 |
} |
| 38 |
|
| 39 |
public static function get_db_configs() |
| 40 |
{ |
| 41 |
if (empty(QueryFactory::getConfig())) { |
| 42 |
global $wpdb; |
| 43 |
return $wpdb; |
| 44 |
} |
| 45 |
return QueryFactory::getConfig(); |
| 46 |
} |
| 47 |
} |
| 48 |
|