forked from newsapps/wordpress-mtv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.php
53 lines (47 loc) · 1.4 KB
/
utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* @package MTV
* @version 1.0
*/
// function exception_error_handler($errno, $errstr, $errfile, $errline ) {
// throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
// }
// set_error_handler("exception_error_handler");
/**
* Check for an array item, return $default if it's empty
**/
function get_default($array, $key, $default="") {
return empty($array[$key]) ? $default : $array[$key];
}
/**
* Dump the contents of a variable to the error log. works
* like var_dump.
**/
function var_log( $stuff ) {
error_log( stripslashes(var_export( $stuff, true )) );
}
class NotImplementedException extends LogicException {}
class WPException extends JsonableException {
public $wp_error;
public function __construct( $wp_error ) {
parent::__construct( $wp_error->get_error_message() );
$this->wp_error = $wp_error;
}
public function __call( $method, $args ) {
return call_user_func_array(array($this->wp_error, $name), $args);
}
public function to_json() {
return array_merge(parent::to_json(), array(
'codes' => $this->wp_error->get_error_codes(),
'messages' => $this->wp_error->get_error_messages()
));
}
}
class JsonableException extends Exception {
public function to_json() {
return array(
'message' => $this->message,
'code' => $this->code
);
}
}