Skip to content

Commit d07999a

Browse files
committed
Add query to Context
1 parent 885a42e commit d07999a

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

docs/context.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class Context
2222
// The endpoint handling the request
2323
public ?EndpointInterface $endpoint = null;
2424

25+
// The query being constructed by the Index endpoint
26+
public ?object $query = null;
27+
2528
// The serializer instance
2629
public ?Serializer $serializer = null;
2730

src/Context.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Context
1212
{
1313
public ?ResourceInterface $resource = null;
1414
public ?EndpointInterface $endpoint = null;
15+
public ?object $query = null;
1516
public ?Serializer $serializer = null;
1617
public mixed $model = null;
1718
public ?Field $field = null;
@@ -138,6 +139,13 @@ public function withEndpoint(EndpointInterface $endpoint): static
138139
return $new;
139140
}
140141

142+
public function withQuery(object $query): static
143+
{
144+
$new = clone $this;
145+
$new->query = $query;
146+
return $new;
147+
}
148+
141149
public function withSerializer(Serializer $serializer): static
142150
{
143151
$new = clone $this;

src/Endpoint/Index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public function handle(Context $context): ?Response
8282

8383
$query = $resource->query($context);
8484

85+
$context = $context->withQuery($query);
86+
8587
$this->applySorts($query, $context);
8688
$this->applyFilters($query, $context);
8789

0 commit comments

Comments
 (0)