1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Endpoints\Source;
6
7use Elasticsearch\Endpoints\AbstractEndpoint;
8use Elasticsearch\Common\Exceptions;
9
10/**
11 * Class Get
12 *
13 * @category Elasticsearch
14 * @package  Elasticsearch\Endpoints\Source
15 * @author   Zachary Tong <zach@elastic.co>
16 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache2
17 * @link     http://elastic.co
18 */
19class Get extends AbstractEndpoint
20{
21    /**
22     * @throws \Elasticsearch\Common\Exceptions\RuntimeException
23     */
24    public function getURI(): string
25    {
26        if (isset($this->id) !== true) {
27            throw new Exceptions\RuntimeException(
28                'id is required for Get'
29            );
30        }
31        if (isset($this->index) !== true) {
32            throw new Exceptions\RuntimeException(
33                'index is required for Get'
34            );
35        }
36
37        $id = $this->id;
38        $index = $this->index;
39        $type = $this->type ?? null;
40
41        if (isset($type)) {
42            return "/$index/$type/$id/_source";
43        }
44        return "/$index/_source/$id";
45    }
46
47    public function getParamWhitelist(): array
48    {
49        return [
50            'parent',
51            'preference',
52            'realtime',
53            'refresh',
54            'routing',
55            '_source',
56            '_source_excludes',
57            '_source_includes',
58            'version',
59            'version_type'
60        ];
61    }
62
63    public function getMethod(): string
64    {
65        return 'GET';
66    }
67}
68