PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / trunk
JetBackup – Backup, Restore & Migrate vtrunk
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 / Web / JetHttpResponseHeaders.php
backup / src / JetBackup / Web Last commit date
File 1 year ago .htaccess 1 year ago JetHttp.php 1 year ago JetHttpResponse.php 1 year ago JetHttpResponseHeaders.php 1 year ago index.html 1 year ago web.config 1 year ago
JetHttpResponseHeaders.php
121 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\Web;
12
13 use stdClass;
14
15 defined("__JETBACKUP__") or die("Restricted Access.");
16
17 class JetHttpResponseHeaders {
18
19 private int $_code=0;
20 private string $_message='';
21 private object $_headers;
22 private bool $_is_ftp;
23
24 /**
25 * @param string $headers
26 * @param bool $isFTP
27 */
28 public function __construct(string $headers, bool $isFTP=false) {
29 $this->_headers = new stdClass();
30 $this->_is_ftp = $isFTP;
31 $this->_parseResponseHeaders($headers);
32 }
33
34 /**
35 * @param string $response
36 *
37 * @return void
38 */
39 private function _parseResponseHeaders(string $response): void {
40
41 $headers = explode("\r\n", $response);
42
43 foreach( $headers as $v ) {
44 if($this->_is_ftp && preg_match("/^\d{3}/", $v)) {
45 $this->addHeader('ftp', trim($v), true);
46 } else {
47 $t = explode( ':', $v, 2 );
48 if(!$this->_is_ftp && sizeof($t) == 1 && preg_match( "#HTTP/[0-9.]+\s+([0-9]+)\s+(.*)#",$v, $m ) ){
49 $this->setCode(intval($m[1]));
50 $this->setMessage(trim($m[2]));
51 continue;
52 }
53
54 if(sizeof($t) == 2) $this->addHeader(strtolower($t[0]), trim($t[1]));
55 }
56 }
57 }
58
59 /**
60 * @param int $code
61 *
62 * @return void
63 */
64 public function setCode(int $code):void { $this->_code = $code; }
65
66 /**
67 * @return int
68 */
69 public function getCode():int { return $this->_code; }
70
71 /**
72 * @param string $message
73 *
74 * @return void
75 */
76 public function setMessage(string $message):void { $this->_message = $message; }
77
78 /**
79 * @return string
80 */
81 public function getMessage():string { return $this->_message; }
82
83 /**
84 * @param object $headers
85 *
86 * @return void
87 */
88 public function setHeaders(object $headers):void {
89 $this->_headers = $headers;
90 }
91
92 /**
93 * @param string $key
94 * @param string $value
95 * @param bool $append
96 *
97 * @return void
98 */
99 public function addHeader(string $key, string $value, bool $append=false):void {
100 if($append) {
101 if(!isset($this->_headers->{$key})) $this->_headers->{$key} = [];
102 $this->_headers->{$key}[] = $value;
103 } else $this->_headers->{$key} = $value;
104 }
105
106 /**
107 * @return object
108 */
109 public function getHeaders():object {
110 return $this->_headers;
111 }
112
113 /**
114 * @param string $key
115 *
116 * @return mixed
117 */
118 public function getHeader(string $key) {
119 return $this->_headers->{$key} ?? null;
120 }
121 }