forked from docker-php/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemEvents.php
More file actions
43 lines (34 loc) · 1.43 KB
/
Copy pathSystemEvents.php
File metadata and controls
43 lines (34 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace Docker\Endpoint;
use Amp\Artax\Client as ArtaxClient;
use Docker\API\Endpoint\SystemEvents as BaseEndpoint;
use Docker\Client\AmpArtaxStreamEndpoint;
use Docker\Client\AmpArtaxStreamEndpointTrait;
use Docker\Client\ProvideAmpArtaxClientOptions;
use Docker\Stream\EventStream;
use Jane\OpenApiRuntime\Client\Client;
use Jane\OpenApiRuntime\Client\Exception\InvalidFetchModeException;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Serializer\SerializerInterface;
class SystemEvents extends BaseEndpoint implements ProvideAmpArtaxClientOptions, AmpArtaxStreamEndpoint
{
use AmpArtaxStreamEndpointTrait;
public function getAmpArtaxClientOptions(): array
{
return [ArtaxClient::OP_TRANSFER_TIMEOUT => 0];
}
public function parsePSR7Response(ResponseInterface $response, SerializerInterface $serializer, string $fetchMode = Client::FETCH_OBJECT)
{
if (Client::FETCH_OBJECT === $fetchMode) {
if (200 === $response->getStatusCode()) {
return new EventStream($response->getBody(), $serializer);
}
return $this->transformResponseBody((string) $response->getBody(), $response->getStatusCode(), $serializer);
}
if (Client::FETCH_RESPONSE === $fetchMode) {
return $response;
}
throw new InvalidFetchModeException(\sprintf('Fetch mode %s is not supported', $fetchMode));
}
}