-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFetchRecordsRequest.php
More file actions
55 lines (43 loc) · 1.34 KB
/
FetchRecordsRequest.php
File metadata and controls
55 lines (43 loc) · 1.34 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
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace IFresh\FileMakerODataApi\Requests\Records;
use IFresh\FileMakerODataApi\QueryOptions;
use Psr\Http\Message\RequestInterface;
use Saloon\Enums\Method;
use Saloon\Http\PendingRequest;
use Saloon\Http\Request;
use Saloon\Http\Response;
class FetchRecordsRequest extends Request
{
protected Method $method = Method::GET;
public function __construct(
private readonly string $database,
private readonly string $table,
private readonly ?QueryOptions $queryOptions = null,
) {
//
}
public function resolveEndpoint(): string
{
return "/{$this->database}/{$this->table}";
}
public function createDtoFromResponse(Response $response): array
{
return $response->json('value');
}
public function handlePsrRequest(RequestInterface $request, PendingRequest $pendingRequest): RequestInterface
{
$queryOptions = $this->queryOptions->toArray();
$queryString = collect($queryOptions)
->map(fn ($value, $key) => "{$key}={$value}")
->join('&');
$uri = $request->getUri()->withQuery($queryString);
return $request->withUri($uri);
}
protected function defaultQuery(): array
{
if (filled($this->queryOptions)) {
return $this->queryOptions->toArray();
}
return [];
}
}