-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathding_provider.exceptions.inc
More file actions
92 lines (83 loc) · 2.4 KB
/
ding_provider.exceptions.inc
File metadata and controls
92 lines (83 loc) · 2.4 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* @file
* Ding provider exception classes.
*/
/**
* Exception that is thrown by providers when the given operation
* cannot be completed until the user authenticates.
*/
class DingProviderAuthException extends Exception { }
/**
* Thrown when no provider is configured for the given provider.
*/
class DingProviderNoProvider extends Exception { }
/**
* Thrown when provider doesn't implement the given function.
*/
class DingProviderDoesntImplement extends Exception { }
/**
* Exception class that can provide a translated and substituted
* message. Exceptions that is instanceof DingProviderUserException is
* errors appropriate for displaying to the end user. Internal errors
* not suitable for end users should not be implemented as as subclass
* of this class.
*
* When instantiating this class or subclasses, you should give a
* translated string as message, like so:
* @code
* throw new DingProviderUserException(t('Internal error on @title'));
* @endcode
*
* Which replacements are available should be documented in the
* Exception or one of it's parents.
*/
class DingProviderUserException extends Exception {
/**
* Return the error message with replacements substituted just like
* t(). NOTE: The message returned by getMessage is already
* translated, this methods only takes care of replacements.
*
* @param $args
* Array of replacements, just like the second argument to t().
* @return
* The translated string.
*/
public function getMessageT($args) {
$string = $this->getMessage();
if (empty($args)) {
return $string;
}
else {
// Allow subclasses to add in default args.
if (property_exists($this, 'args')) {
$args += $this->args;
}
// Transform arguments before inserting them.
foreach ($args as $key => $value) {
switch ($key[0]) {
case '@':
// Escaped only.
$args[$key] = check_plain($value);
break;
case '%':
default:
// Escaped and placeholder.
$args[$key] = drupal_placeholder($value);
break;
case '!':
// Pass-through.
}
}
return strtr($string, $args);
}
}
}
class DingProviderException extends Exception {
private $callback;
public function getCallback() {
if (isset($this->callback)) {
return $this->callback;
}
}
}