Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for psr/http-message ^2.0 #719

Merged
merged 6 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
then
echo "Nothing to install, using default Algolia\AlgoliaSearch\Http\Php53HttpClient"
else
COMPOSER_MEMORY_LIMIT=-1 composer require <<parameters.http_client>>
COMPOSER_MEMORY_LIMIT=-1 composer require <<parameters.http_client>> -W
fi

- run:
Expand Down Expand Up @@ -135,8 +135,8 @@ workflows:
version: "7.4"
http_client: guzzlehttp/guzzle:"^6.0"
- test:
name: 'Guzzle 6 - PHP 7.2'
version: "7.2"
name: 'Guzzle 6 - PHP 7.3'
version: "7.3"
http_client: guzzlehttp/guzzle:"^6.0"
- test:
name: 'Legacy client - PHP 8.1'
Expand All @@ -151,6 +151,6 @@ workflows:
version: "7.4"
http_client: legacy
- test:
name: 'Legacy client - PHP 7.2'
version: "7.2"
name: 'Legacy client - PHP 7.3'
version: "7.3"
http_client: legacy
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
## ✨ Features

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

## 💡 Getting Started

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.3 || ^8.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"psr/http-message": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
},
Expand Down
28 changes: 14 additions & 14 deletions src/Http/Psr7/BufferStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ public function __construct($hwm = 16384)
$this->hwm = $hwm;
}

public function __toString()
public function __toString(): string
{
return $this->getContents();
}

public function getContents()
public function getContents(): string
{
$buffer = $this->buffer;
$this->buffer = '';

return $buffer;
}

public function close()
public function close(): void
{
$this->buffer = '';
}
Expand All @@ -55,50 +55,50 @@ public function detach()
$this->close();
}

public function getSize()
public function getSize(): ?int
{
return strlen($this->buffer);
}

public function isReadable()
public function isReadable(): bool
{
return true;
}

public function isWritable()
public function isWritable(): bool
{
return true;
}

public function isSeekable()
public function isSeekable(): bool
{
return false;
}

public function rewind()
public function rewind(): void
{
$this->seek(0);
}

public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET): void
{
throw new \RuntimeException('Cannot seek a BufferStream');
}

public function eof()
public function eof(): bool
{
return 0 === strlen($this->buffer);
}

public function tell()
public function tell(): int
{
throw new \RuntimeException('Cannot determine the position of a BufferStream');
}

/**
* Reads data from the buffer.
*/
public function read($length)
public function read(int $length): string
{
$currentLength = strlen($this->buffer);

Expand All @@ -118,7 +118,7 @@ public function read($length)
/**
* Writes data to the buffer.
*/
public function write($string)
public function write(string $string): int
{
$this->buffer .= $string;

Expand All @@ -130,7 +130,7 @@ public function write($string)
return strlen($string);
}

public function getMetadata($key = null)
public function getMetadata(?string $key = null)
{
if ('hwm' == $key) {
return $this->hwm;
Expand Down
30 changes: 15 additions & 15 deletions src/Http/Psr7/PumpStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(callable $source, array $options = [])
$this->buffer = new BufferStream();
}

public function __toString()
public function __toString(): string
{
try {
return copy_to_string($this);
Expand All @@ -60,7 +60,7 @@ public function __toString()
}
}

public function close()
public function close(): void
{
$this->detach();
}
Expand All @@ -71,52 +71,52 @@ public function detach()
$this->source = null;
}

public function getSize()
public function getSize(): ?int
{
return $this->size;
}

public function tell()
public function tell(): int
{
return $this->tellPos;
}

public function eof()
public function eof(): bool
{
return !$this->source;
}

public function isSeekable()
public function isSeekable(): bool
{
return false;
}

public function rewind()
public function rewind(): void
{
$this->seek(0);
}

public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET): void
{
throw new \RuntimeException('Cannot seek a PumpStream');
}

public function isWritable()
public function isWritable(): bool
{
return false;
}

public function write($string)
public function write(string $string): int
{
throw new \RuntimeException('Cannot write to a PumpStream');
}

public function isReadable()
public function isReadable(): bool
{
return true;
}

public function read($length)
public function read(int $length): string
{
$data = $this->buffer->read($length);
$readLen = strlen($data);
Expand All @@ -132,7 +132,7 @@ public function read($length)
return $data;
}

public function getContents()
public function getContents(): string
{
$result = '';
while (!$this->eof()) {
Expand All @@ -142,13 +142,13 @@ public function getContents()
return $result;
}

public function getMetadata($key = null)
public function getMetadata(?string $key = null)
{
if (!$key) {
return $this->metadata;
}

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

private function pump($length)
Expand Down