Calls
9 months ago
.htaccess
9 months ago
Ajax.php
9 months ago
ListRecord.php
9 months ago
aAjax.php
9 months ago
iAjax.php
9 months ago
index.html
9 months ago
web.config
9 months ago
aAjax.php
111 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Ajax; |
| 4 | |
| 5 | use JetBackup\Exception\AjaxException; |
| 6 | use JetBackup\Exception\UserInputException; |
| 7 | use JetBackup\UserInput\UserInput; |
| 8 | |
| 9 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 10 | |
| 11 | abstract class aAjax implements iAjax { |
| 12 | |
| 13 | protected UserInput $_data; |
| 14 | private bool $_is_cli=false; |
| 15 | private string $_response_message=''; |
| 16 | private array $_response_data=[]; |
| 17 | private array $_response_cli=[]; |
| 18 | |
| 19 | public function __construct() { |
| 20 | $this->_data = new UserInput(); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @param array $data |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | public function setData(array $data=[]):void { |
| 29 | unset($data['actionType']); |
| 30 | $this->_data->setData($data); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param bool $cli |
| 35 | * |
| 36 | * @return void |
| 37 | */ |
| 38 | public function setCLI(bool $cli):void { |
| 39 | $this->_is_cli = $cli; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @return bool |
| 44 | */ |
| 45 | public function isCLI(): bool { |
| 46 | return $this->_is_cli; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @param array $data |
| 51 | * |
| 52 | * @return void |
| 53 | */ |
| 54 | public function setResponseCLI(array $data):void { $this->_response_cli = $data; } |
| 55 | |
| 56 | /** |
| 57 | * @return array |
| 58 | */ |
| 59 | public function getResponseCLI(): array { return $this->_response_cli ?? []; } |
| 60 | |
| 61 | /** |
| 62 | * @param array $data |
| 63 | * |
| 64 | * @return void |
| 65 | */ |
| 66 | public function setResponseData(array $data):void { $this->_response_data = $data; } |
| 67 | |
| 68 | /** |
| 69 | * @return array |
| 70 | */ |
| 71 | public function getResponseData(): array { return $this->_response_data ?? []; } |
| 72 | |
| 73 | /** |
| 74 | * @param string $message |
| 75 | * |
| 76 | * @return void |
| 77 | */ |
| 78 | public function setResponseMessage(string $message):void { $this->_response_message = $message; } |
| 79 | |
| 80 | /** |
| 81 | * @return string |
| 82 | */ |
| 83 | public function getResponseMessage(): string { return $this->_response_message ?? ''; } |
| 84 | |
| 85 | /** |
| 86 | * @param string $key |
| 87 | * |
| 88 | * @return bool |
| 89 | */ |
| 90 | public function isset(string $key):bool { |
| 91 | $fields = $this->_data->getData(); |
| 92 | return isset($fields[$key]); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @param string $key |
| 97 | * @param $default |
| 98 | * @param int $type |
| 99 | * @param int $subType |
| 100 | * |
| 101 | * @return array|bool|float|int|mixed|object |
| 102 | * @throws AjaxException |
| 103 | */ |
| 104 | public function getUserInput(string $key, $default, int $type, int $subType = 0) { |
| 105 | try { |
| 106 | return $this->_data->getValidated($key, $default, $type, $subType); |
| 107 | } catch(UserInputException $e) { |
| 108 | throw new AjaxException($e->getMessage(), $e->getData()); |
| 109 | } |
| 110 | } |
| 111 | } |