Skip to content

Commit 7c944e3

Browse files
committed
PHP 7.2 backwards compatibility, PHP 8.1 friendly.
1 parent ad1b152 commit 7c944e3

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ https://github.com/tcdent/php-restclient
55

66
Installation
77
-----------
8-
Requires PHP 8.0 or above. Use [0.1.7](https://github.com/tcdent/php-restclient/releases/tag/0.1.7) for legacy versions of PHP.
8+
Requires PHP 7.2 or above. Use [0.1.7](https://github.com/tcdent/php-restclient/releases/tag/0.1.7) for legacy versions of PHP.
99

1010
``` sh
1111
$ composer require tcdent/php-restclient

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"issues": "http://github.com/tcdent/php-restclient/issues"
1818
},
1919
"require": {
20-
"php": ">=8.0",
20+
"php": ">=7.2",
2121
"ext-curl": "*",
2222
"ext-json": "*"
2323
},

restclient.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,31 @@ public function offsetUnset($key) : void {
105105
}
106106

107107
// Request methods:
108-
public function get(string $url, array|string $parameters=[], array $headers=[]) : RestClient {
108+
public function get(string $url, $parameters=[], array $headers=[]) : RestClient {
109109
return $this->execute($url, 'GET', $parameters, $headers);
110110
}
111111

112-
public function post(string $url, array|string $parameters=[], array $headers=[]) : RestClient {
112+
public function post(string $url, $parameters=[], array $headers=[]) : RestClient {
113113
return $this->execute($url, 'POST', $parameters, $headers);
114114
}
115115

116-
public function put(string $url, array|string $parameters=[], array $headers=[]) : RestClient {
116+
public function put(string $url, $parameters=[], array $headers=[]) : RestClient {
117117
return $this->execute($url, 'PUT', $parameters, $headers);
118118
}
119119

120-
public function patch(string $url, array|string $parameters=[], array $headers=[]) : RestClient {
120+
public function patch(string $url, $parameters=[], array $headers=[]) : RestClient {
121121
return $this->execute($url, 'PATCH', $parameters, $headers);
122122
}
123123

124-
public function delete(string $url, array|string $parameters=[], array $headers=[]) : RestClient {
124+
public function delete(string $url, $parameters=[], array $headers=[]) : RestClient {
125125
return $this->execute($url, 'DELETE', $parameters, $headers);
126126
}
127127

128-
public function head(string $url, array|string $parameters=[], array $headers=[]) : RestClient {
128+
public function head(string $url, $parameters=[], array $headers=[]) : RestClient {
129129
return $this->execute($url, 'HEAD', $parameters, $headers);
130130
}
131131

132-
public function execute(string $url, string $method='GET', array|string $parameters=[], array $headers=[]) : RestClient {
132+
public function execute(string $url, string $method='GET', $parameters=[], array $headers=[]) : RestClient {
133133
$client = clone $this;
134134
$client->url = $url;
135135
$client->handle = curl_init();
@@ -187,7 +187,7 @@ public function execute(string $url, string $method='GET', array|string $paramet
187187
}
188188

189189
if($client->options['base_url']){
190-
if($client->url[0] !== '/' && !str_ends_with($client->options['base_url'], '/'))
190+
if($client->url[0] !== '/' && substr($client->options['base_url'], -1) !== '/')
191191
$client->url = '/' . $client->url;
192192
$client->url = $client->options['base_url'] . $client->url;
193193
}
@@ -218,7 +218,7 @@ public function parse_response($response) : void {
218218
// Since we tokenize on \n, use the remaining \r to detect empty lines.
219219
if(count($headers) > 0) break; // Must be the newline after headers, move on to response body
220220
}
221-
elseif(str_starts_with($line, 'HTTP')){
221+
elseif(strpos($line, 'HTTP') === 0){
222222
// One or more HTTP status lines
223223
$this->response_status_lines[] = trim($line);
224224
}
@@ -259,7 +259,7 @@ public function get_response_format() : string {
259259
"Response format could not be determined.");
260260
}
261261

262-
public function decode_response() : mixed {
262+
public function decode_response(){
263263
if(empty($this->decoded_response)){
264264
$format = $this->get_response_format();
265265
if(!array_key_exists($format, $this->options['decoders']))

0 commit comments

Comments
 (0)