Skip to content

Commit e218795

Browse files
authored
Add support for psr/http-message ^2.0 (#719)
1 parent 0fee2b9 commit e218795

File tree

9 files changed

+135
-229
lines changed

9 files changed

+135
-229
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
then
5757
echo "Nothing to install, using default Algolia\AlgoliaSearch\Http\Php53HttpClient"
5858
else
59-
COMPOSER_MEMORY_LIMIT=-1 composer require <<parameters.http_client>>
59+
COMPOSER_MEMORY_LIMIT=-1 composer require <<parameters.http_client>> -W
6060
fi
6161
6262
- run:
@@ -135,8 +135,8 @@ workflows:
135135
version: "7.4"
136136
http_client: guzzlehttp/guzzle:"^6.0"
137137
- test:
138-
name: 'Guzzle 6 - PHP 7.2'
139-
version: "7.2"
138+
name: 'Guzzle 6 - PHP 7.3'
139+
version: "7.3"
140140
http_client: guzzlehttp/guzzle:"^6.0"
141141
- test:
142142
name: 'Legacy client - PHP 8.1'
@@ -151,6 +151,6 @@ workflows:
151151
version: "7.4"
152152
http_client: legacy
153153
- test:
154-
name: 'Legacy client - PHP 7.2'
155-
version: "7.2"
154+
name: 'Legacy client - PHP 7.3'
155+
version: "7.3"
156156
http_client: legacy

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
## ✨ Features
2828

2929
- Thin & minimal low-level HTTP client to interact with Algolia's API
30-
- Supports php `^7.2`.
30+
- Supports php `^7.3`.
3131

3232
## 💡 Getting Started
3333

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.2 || ^8.0",
14+
"php": "^7.3 || ^8.0",
1515
"ext-curl": "*",
1616
"ext-json": "*",
1717
"ext-mbstring": "*",
18-
"psr/http-message": "^1.0",
18+
"psr/http-message": "^1.0 || ^2.0",
1919
"psr/log": "^1.0 || ^2.0 || ^3.0",
2020
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
2121
},

src/Http/Psr7/BufferStream.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ public function __construct($hwm = 16384)
3232
$this->hwm = $hwm;
3333
}
3434

35-
public function __toString()
35+
public function __toString(): string
3636
{
3737
return $this->getContents();
3838
}
3939

40-
public function getContents()
40+
public function getContents(): string
4141
{
4242
$buffer = $this->buffer;
4343
$this->buffer = '';
4444

4545
return $buffer;
4646
}
4747

48-
public function close()
48+
public function close(): void
4949
{
5050
$this->buffer = '';
5151
}
@@ -55,50 +55,50 @@ public function detach()
5555
$this->close();
5656
}
5757

58-
public function getSize()
58+
public function getSize(): ?int
5959
{
6060
return strlen($this->buffer);
6161
}
6262

63-
public function isReadable()
63+
public function isReadable(): bool
6464
{
6565
return true;
6666
}
6767

68-
public function isWritable()
68+
public function isWritable(): bool
6969
{
7070
return true;
7171
}
7272

73-
public function isSeekable()
73+
public function isSeekable(): bool
7474
{
7575
return false;
7676
}
7777

78-
public function rewind()
78+
public function rewind(): void
7979
{
8080
$this->seek(0);
8181
}
8282

83-
public function seek($offset, $whence = SEEK_SET)
83+
public function seek(int $offset, int $whence = SEEK_SET): void
8484
{
8585
throw new \RuntimeException('Cannot seek a BufferStream');
8686
}
8787

88-
public function eof()
88+
public function eof(): bool
8989
{
9090
return 0 === strlen($this->buffer);
9191
}
9292

93-
public function tell()
93+
public function tell(): int
9494
{
9595
throw new \RuntimeException('Cannot determine the position of a BufferStream');
9696
}
9797

9898
/**
9999
* Reads data from the buffer.
100100
*/
101-
public function read($length)
101+
public function read(int $length): string
102102
{
103103
$currentLength = strlen($this->buffer);
104104

@@ -118,7 +118,7 @@ public function read($length)
118118
/**
119119
* Writes data to the buffer.
120120
*/
121-
public function write($string)
121+
public function write(string $string): int
122122
{
123123
$this->buffer .= $string;
124124

@@ -130,7 +130,7 @@ public function write($string)
130130
return strlen($string);
131131
}
132132

133-
public function getMetadata($key = null)
133+
public function getMetadata(?string $key = null)
134134
{
135135
if ('hwm' == $key) {
136136
return $this->hwm;

src/Http/Psr7/PumpStream.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(callable $source, array $options = [])
5151
$this->buffer = new BufferStream();
5252
}
5353

54-
public function __toString()
54+
public function __toString(): string
5555
{
5656
try {
5757
return copy_to_string($this);
@@ -60,7 +60,7 @@ public function __toString()
6060
}
6161
}
6262

63-
public function close()
63+
public function close(): void
6464
{
6565
$this->detach();
6666
}
@@ -71,52 +71,52 @@ public function detach()
7171
$this->source = null;
7272
}
7373

74-
public function getSize()
74+
public function getSize(): ?int
7575
{
7676
return $this->size;
7777
}
7878

79-
public function tell()
79+
public function tell(): int
8080
{
8181
return $this->tellPos;
8282
}
8383

84-
public function eof()
84+
public function eof(): bool
8585
{
8686
return !$this->source;
8787
}
8888

89-
public function isSeekable()
89+
public function isSeekable(): bool
9090
{
9191
return false;
9292
}
9393

94-
public function rewind()
94+
public function rewind(): void
9595
{
9696
$this->seek(0);
9797
}
9898

99-
public function seek($offset, $whence = SEEK_SET)
99+
public function seek(int $offset, int $whence = SEEK_SET): void
100100
{
101101
throw new \RuntimeException('Cannot seek a PumpStream');
102102
}
103103

104-
public function isWritable()
104+
public function isWritable(): bool
105105
{
106106
return false;
107107
}
108108

109-
public function write($string)
109+
public function write(string $string): int
110110
{
111111
throw new \RuntimeException('Cannot write to a PumpStream');
112112
}
113113

114-
public function isReadable()
114+
public function isReadable(): bool
115115
{
116116
return true;
117117
}
118118

119-
public function read($length)
119+
public function read(int $length): string
120120
{
121121
$data = $this->buffer->read($length);
122122
$readLen = strlen($data);
@@ -132,7 +132,7 @@ public function read($length)
132132
return $data;
133133
}
134134

135-
public function getContents()
135+
public function getContents(): string
136136
{
137137
$result = '';
138138
while (!$this->eof()) {
@@ -142,13 +142,13 @@ public function getContents()
142142
return $result;
143143
}
144144

145-
public function getMetadata($key = null)
145+
public function getMetadata(?string $key = null)
146146
{
147147
if (!$key) {
148148
return $this->metadata;
149149
}
150150

151-
return isset($this->metadata[$key]) ? $this->metadata[$key] : null;
151+
return $this->metadata[$key] ?? null;
152152
}
153153

154154
private function pump($length)

0 commit comments

Comments
 (0)