PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.22.3
JetBackup – Backup, Restore & Migrate v3.1.22.3
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / 3rdparty / SocketAPI / SocketAPI.php
backup / src / JetBackup / 3rdparty / SocketAPI Last commit date
Client 9 months ago Exception 1 year ago Message 1 year ago Protocol 1 year ago Socket 4 months ago .htaccess 1 year ago SocketAPI.php 1 year ago autoload.php 1 year ago index.html 1 year ago web.config 1 year ago
SocketAPI.php
99 lines
1 <?php
2 /*
3 *
4 * JetBackup @ package
5 * Created By Idan Ben-Ezra
6 *
7 * Copyrights @ JetApps
8 * https://www.jetapps.com
9 *
10 **/
11 namespace JetBackup\SocketAPI;
12
13 use JetBackup\SocketAPI\Client\Client;
14 use JetBackup\SocketAPI\Exception\ClientException;
15 use JetBackup\SocketAPI\Exception\SocketAPIException;
16
17 class SocketAPI {
18
19 private $_data;
20 private string $_function;
21
22 public function __construct($function) {
23 $this->_function = $function;
24 }
25 /**
26 * @return array
27 * @throws SocketAPIException
28 */
29 public function execute() {
30 try {
31 $message = [];
32 $message['function'] = $this->_function;
33 if($this->_data) $message['data'] = $this->_data;
34
35 $client = new Client();
36 $response = json_decode($client->send(json_encode($message)), true);
37 $client->close();
38 if($response === false) throw new ClientException("Invalid response");
39 return $response;
40 } catch(ClientException $e) {
41 throw new SocketAPIException($e->getMessage());
42 }
43 }
44
45 /**
46 * @param string $key
47 * @param mixed $value
48 *
49 * @return $this
50 */
51 public function arg($key, $value) {
52 $this->_data[$key] = $value;
53 return $this;
54 }
55
56 /**
57 * @param int $limit
58 * @param int $skip
59 *
60 * @return $this
61 */
62 public function limit($limit, $skip=0) {
63 $this->_data['limit'] = $limit;
64 $this->_data['skip'] = $skip;
65 return $this;
66 }
67
68 /**
69 * @param string $key
70 *
71 * @return $this
72 */
73 public function sortAsc($key) {
74 $this->_data['sort'][$key] = 1;
75 return $this;
76 }
77
78 /**
79 * @param string $key
80 *
81 * @return $this
82 */
83 public function sortDesc($key) {
84 $this->_data['sort'][$key] = -1;
85 return $this;
86 }
87
88 /**
89 * @return SocketAPI
90 * @throws SocketAPIException
91 */
92 public static function api($function):SocketAPI {
93 if(!function_exists('socket_connect'))
94 throw new SocketAPIException("The function socket_connect not installed or disabled within your PHP.");
95
96 return new SocketAPI($function);
97 }
98 }
99