• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Ekman / es-pagination / 3d30d0e2-2ab7-43eb-898f-16cee41c973d

pending completion
3d30d0e2-2ab7-43eb-898f-16cee41c973d

push

circleci

GitHub
Test PHP 8.2

19 of 103 relevant lines covered (18.45%)

0.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/CursorFactories/EsPitCursorFactory.php
1
<?php
2

3
namespace Nekman\EsPagination\CursorFactories;
4

5
use Elasticsearch\Client;
6
use Nekman\EsPagination\Contracts\EsCursorFactoryInterface;
7
use Nekman\EsPagination\Exceptions\CreatePitException;
8

9
/**
10
 * Elasticsearch pit (point in time) is a lightweight view into the state of the data as it existed when initiated.
11
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html
12
 */
13
final class EsPitCursorFactory extends BaseCursorFactory
14
{
15
    private EsCursorFactoryInterface $decorator;
16
    private Client $client;
17
    private string $pitKeepAlive;
18

19
    public function __construct(EsCursorFactoryInterface $decorator, Client $client, string $pitKeepAlive = "1m")
20
    {
21
        $this->decorator = $decorator;
×
22
        $this->client = $client;
×
23
        $this->pitKeepAlive = $pitKeepAlive;
×
24
    }
25

26
    public function responses(array $params = []): iterable
27
    {
28
        // Check if the user has provided a PIT ID. If not, create one and manage it for the user.
29
        // If the user has created an own PIT then let them manage it themselves.
30
        $pit = $params["pit"]["id"] ?? null;
×
31

32
        if (!$pit) {
×
33
            $index = $params["index"] ?? null;
×
34

35
            if (!$index) {
×
36
                throw new CreatePitException("Could not create a PIT due to \"index\" missing in \$params");
×
37
            }
38

39
            $response = $this->client->openPointInTime([
×
40
                "index" => $index,
×
41
                "keep_alive" => $this->pitKeepAlive,
×
42
            ]);
×
43

44
            $pit = $response["id"] ?? null;
×
45
            unset($params["index"]);
×
46
        }
47

48
        $params["body"]["pit"] = [
×
49
            "id" => $pit,
×
50
            "keep_alive" => $params["pit"]["keep_alive"] ?? $this->pitKeepAlive,
×
51
        ];
×
52

53
        try {
54
            yield from $this->decorator->responses($params);
×
55
        } finally {
56
            @$this->client->closePointInTime([
×
57
                "body" => [
×
58
                    "id" => $pit,
×
59
                ],
×
60
            ]);
×
61
        }
62
    }
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc