| 1 |
<?php |
| 2 |
/* |
| 3 |
* This file is part of the ManageWP Worker plugin. |
| 4 |
* |
| 5 |
* (c) ManageWP LLC <contact@managewp.com> |
| 6 |
* |
| 7 |
* For the full copyright and license information, please view the LICENSE |
| 8 |
* file that was distributed with this source code. |
| 9 |
*/ |
| 10 |
|
| 11 |
class MWP_Worker_Exception extends Exception |
| 12 |
{ |
| 13 |
const CONNECTION_PUBLIC_KEY_EXISTS = 10001; |
| 14 |
const CONNECTION_PUBLIC_KEY_NOT_FOUND = 10010; |
| 15 |
const CONNECTION_SIGNATURE_NOT_VALID = 10011; |
| 16 |
const CONNECTION_SIGNATURE_EMPTY = 10018; |
| 17 |
const OPENSSL_ENCRYPT_ERROR = 10002; |
| 18 |
const OPENSSL_DECRYPT_ERROR = 10003; |
| 19 |
const OPENSSL_VERIFY_ERROR = 10005; |
| 20 |
const PHPSECLIB_ENCRYPT_ERROR = 10006; |
| 21 |
const PHPSECLIB_DECRYPT_ERROR = 10007; |
| 22 |
const PHPSECLIB_VERIFY_ERROR = 10009; |
| 23 |
const NONCE_FORMAT_INVALID = 10012; |
| 24 |
const NONCE_EXPIRED = 10013; |
| 25 |
const NONCE_ALREADY_USED = 10014; |
| 26 |
const AUTHENTICATION_NO_ADMIN_USER = 10015; |
| 27 |
const AUTHENTICATION_MESSAGE_ID_EMPTY = 10016; |
| 28 |
const AUTHENTICATION_PUBLIC_KEY_EMPTY = 10017; |
| 29 |
const AUTHENTICATION_INVALID_SIGNATURE = 10019; |
| 30 |
const AUTHENTICATION_INVALID_SERVICE_SIGNATURE = 10040; |
| 31 |
const ACTION_NOT_REGISTERED = 10020; |
| 32 |
const CONNECTION_PUBLIC_KEY_NOT_PROVIDED = 10021; |
| 33 |
const CONNECTION_VERIFICATION_TEST_FAILED = 10022; |
| 34 |
const PHP_EVAL_ERROR = 10023; |
| 35 |
const LEGACY_AUTHENTICATION_INVALID_SIGNATURE = 10024; |
| 36 |
const LEGACY_AUTHENTICATION_KEY_EXISTS = 10025; |
| 37 |
const AUTO_LOGIN_USERNAME_REQUIRED = 10026; |
| 38 |
const FILESYSTEM_CREDENTIALS_ERROR = 10027; |
| 39 |
const SHELL_NOT_AVAILABLE = 10028; |
| 40 |
const BACKUP_DATABASE_METHOD_NOT_AVAILABLE = 10029; |
| 41 |
const BACKUP_DATABASE_FAILED = 10030; |
| 42 |
const BACKUP_DATABASE_MISSING_TABLES = 10031; |
| 43 |
const IO_EXCEPTION = 10032; |
| 44 |
const BACKUP_DATABASE_INVALID_OUTPUT_METHOD = 10033; |
| 45 |
const PHP_EXTENSION_REQUIRED_CURL = 10034; |
| 46 |
const JSON_RESPONSE_EXCEPTION = 10035; |
| 47 |
const WORKER_RECOVERING = 10036; |
| 48 |
const WORKER_UPDATING = 10037; |
| 49 |
const WORKER_RECOVER_STARTED = 10038; |
| 50 |
const CONNECTION_INVALID_KEY = 10100; |
| 51 |
|
| 52 |
const GENERAL_ERROR = 10000; |
| 53 |
|
| 54 |
static $codes = array(); |
| 55 |
|
| 56 |
protected $errorName; |
| 57 |
|
| 58 |
protected $context; |
| 59 |
|
| 60 |
public function __construct($code, $message = null, array $context = array()) |
| 61 |
{ |
| 62 |
$this->errorName = $this->getErrorNameForCode($code); |
| 63 |
$this->context = $context; |
| 64 |
|
| 65 |
if ($message === null) { |
| 66 |
$message = sprintf('Error [%d]: %s', $code, $this->errorName); |
| 67 |
} |
| 68 |
|
| 69 |
parent::__construct($message, $code); |
| 70 |
} |
| 71 |
|
| 72 |
private function getErrorNameForCode($code) |
| 73 |
{ |
| 74 |
if (count(self::$codes) === 0) { |
| 75 |
$reflectionClass = new ReflectionClass(__CLASS__); |
| 76 |
self::$codes = array_flip($reflectionClass->getConstants()); |
| 77 |
} |
| 78 |
|
| 79 |
if (array_key_exists($code, self::$codes)) { |
| 80 |
return self::$codes[$code]; |
| 81 |
} |
| 82 |
|
| 83 |
return self::GENERAL_ERROR; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* @return string |
| 88 |
*/ |
| 89 |
public function getErrorName() |
| 90 |
{ |
| 91 |
return $this->errorName; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* @return array |
| 96 |
*/ |
| 97 |
public function getContext() |
| 98 |
{ |
| 99 |
return $this->context; |
| 100 |
} |
| 101 |
} |
| 102 |
|