1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Soheilrt\AdobeConnectClient\Client\Helpers; |
4
|
|
|
|
5
|
|
|
use DomainException; |
6
|
|
|
use Soheilrt\AdobeConnectClient\Client\Exceptions\InvalidException; |
7
|
|
|
use Soheilrt\AdobeConnectClient\Client\Exceptions\NoAccessException; |
8
|
|
|
use Soheilrt\AdobeConnectClient\Client\Exceptions\NoDataException; |
9
|
|
|
use Soheilrt\AdobeConnectClient\Client\Exceptions\TooMuchDataException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Validate the status code. |
13
|
|
|
*/ |
14
|
|
|
abstract class StatusValidate |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private const STATUS_OK = 'ok'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private const STATUS_INVALID = 'invalid'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private const STATUS_NO_ACCESS = 'no-access'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private const STATUS_NO_DATA = 'no-data'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @see {https://helpx.adobe.com/adobe-connect/webservices/common-xml-elements-attributes.html} |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private const STATUS_TOO_MUCH_DATA = 'too-much-data'; |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Validate the status code and throw an exception if something is wrong. |
49
|
|
|
* |
50
|
|
|
* @param array $status |
51
|
|
|
* |
52
|
|
|
* @throws InvalidException |
53
|
|
|
* @throws NoAccessException |
54
|
|
|
* @throws NoDataException |
55
|
|
|
* @throws TooMuchDataException |
56
|
|
|
* @throws DomainException |
57
|
|
|
*/ |
58
|
|
|
public static function validate(array $status) |
59
|
|
|
{ |
60
|
|
|
switch ($status['code']) { |
61
|
|
|
case self::STATUS_OK: |
62
|
|
|
return; |
63
|
|
|
|
64
|
|
|
case self::STATUS_INVALID: |
65
|
|
|
$invalid = $status[self::STATUS_INVALID]; |
66
|
|
|
throw new InvalidException( |
67
|
|
|
self::getExceptionMessage(self::STATUS_INVALID, $invalid['subcode'], $invalid['field']) |
|
|
|
|
68
|
|
|
); |
69
|
|
|
case self::STATUS_NO_ACCESS: |
70
|
|
|
throw new NoAccessException( |
71
|
|
|
self::getExceptionMessage( |
|
|
|
|
72
|
|
|
self::STATUS_NO_ACCESS, |
73
|
|
|
$status['subcode'] |
74
|
|
|
) |
75
|
|
|
); |
76
|
|
|
case self::STATUS_NO_DATA: |
77
|
|
|
throw new NoDataException( |
78
|
|
|
self::getExceptionMessage(self::STATUS_NO_DATA) |
|
|
|
|
79
|
|
|
); |
80
|
|
|
case self::STATUS_TOO_MUCH_DATA: |
81
|
|
|
throw new TooMuchDataException( |
82
|
|
|
self::getExceptionMessage(self::STATUS_TOO_MUCH_DATA) |
|
|
|
|
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
throw new DomainException('Status Code is Invalid'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* |
91
|
|
|
* |
92
|
|
|
* @param string $statusCode |
93
|
|
|
* @param null|string $subCode |
94
|
|
|
* @param null|string $field |
95
|
|
|
* |
96
|
|
|
* @return mixed|void |
97
|
|
|
*/ |
98
|
|
|
private static function getExceptionMessage($statusCode, $subCode = null, $field = null) |
99
|
|
|
{ |
100
|
|
|
$codes = [ |
101
|
|
|
self::STATUS_NO_DATA => |
102
|
|
|
'There is no data available (in response to an action that would normally result in returning data). ' . |
103
|
|
|
'Usually indicates that there is no item with the ID you specified. ' . |
104
|
|
|
'To resolve the error, change the specified ID to that of an item that exists.', |
105
|
|
|
self::STATUS_TOO_MUCH_DATA => 'The action should have returned a single result but is actually returning ' . |
106
|
|
|
'multiple results. For example, if there are multiple users with the same user name and password, ' . |
107
|
|
|
'and you call the login action using that user name and password as parameters, ' . |
108
|
|
|
'the system cannot determine which user to log you in as, so it returns a too-much-data error.', |
109
|
|
|
self::STATUS_NO_ACCESS => [ |
110
|
|
|
'account-expired' => 'The account has expired.', |
111
|
|
|
'denied' => 'Based on the supplied credentials, you don’t have permission to call the action.', |
112
|
|
|
'no-login' => 'The user is not logged in. To resolve the error, log in (using the login action) ' . |
113
|
|
|
'before you make the call.', |
114
|
|
|
'illegalparent' => 'The specified acl - id is not a seminar or an unknown issue occured while ' . |
115
|
|
|
'retrieving the quota for that seminar.', |
116
|
|
|
'no-quota' => 'The account limits have been reached or exceeded.', |
117
|
|
|
'not-available' => 'The required resource is unavailable.', |
118
|
|
|
'not-secure' => 'You must use SSL to call this action.', |
119
|
|
|
'pending-activation' => 'The account is not yet activated.', |
120
|
|
|
'pending-license' => 'The account’s license agreement has not been settled.', |
121
|
|
|
'sco-expired' => 'The course or tracking content has expired.', |
122
|
|
|
'sco-not-started' => 'The meeting or course has not started.', |
123
|
|
|
'valuelessthanorequal' => 'Value is not a valid integer or is greater than the allowed license quota ' . |
124
|
|
|
'for that seminar.', |
125
|
|
|
], |
126
|
|
|
self::STATUS_INVALID => [ |
127
|
|
|
'duplicate' => 'The call attempted to add a duplicate item on %s in a context where uniqueness is ' . |
128
|
|
|
'required.', |
129
|
|
|
'format' => 'passed %s parameter had the wrong format.', |
130
|
|
|
'illegal-operation' => 'The requested operation on %s violates integrity rules ' . |
131
|
|
|
'(for example, moving a folder into itself).', |
132
|
|
|
'missing' => 'A required parameter %s is missing.', |
133
|
|
|
'no-such-item' => 'The requested %s does not exist.', |
134
|
|
|
'range' => 'The value of %s is outside the permitted range of values.' |
135
|
|
|
] |
136
|
|
|
]; |
137
|
|
|
|
138
|
|
|
//this statement will check for any unknown subcodes if any subcodes provided |
139
|
|
|
// and if any unknown provided, it'll return default error message! |
140
|
|
|
if ($subCode && !isset($codes[$statusCode][$subCode])) { |
141
|
|
|
return "{$statusCode} - {$subCode} - {$field}"; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
switch ($statusCode) { |
145
|
|
|
case self::STATUS_INVALID: |
146
|
|
|
return sprintf($codes[self::STATUS_INVALID][$subCode], $field); |
147
|
|
|
case self::STATUS_NO_ACCESS: |
148
|
|
|
return $codes[self::STATUS_NO_ACCESS][$subCode]; |
149
|
|
|
case self::STATUS_NO_DATA: |
150
|
|
|
return $codes[self::STATUS_NO_DATA]; |
151
|
|
|
case self::STATUS_TOO_MUCH_DATA: |
152
|
|
|
return $codes[self::STATUS_TOO_MUCH_DATA]; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|