1<?php
2
3namespace Elastica\Script;
4
5/**
6 * Inline script.
7 *
8 * @author avasilenko <aa.vasilenko@gmail.com>
9 * @author Tobias Schultze <http://tobion.de>
10 * @author Martin Janser <martin.janser@liip.ch>
11 *
12 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html
13 */
14class Script extends AbstractScript
15{
16    /**
17     * @var string
18     */
19    private $_scriptCode;
20
21    /**
22     * @param string      $scriptCode Script source code
23     * @param string|null $documentId Document ID the script action should be performed on (only relevant in update context)
24     */
25    public function __construct(string $scriptCode, ?array $params = null, ?string $lang = null, ?string $documentId = null)
26    {
27        parent::__construct($params, $lang, $documentId);
28
29        $this->setScript($scriptCode);
30    }
31
32    public function setScript(string $scriptCode): self
33    {
34        $this->_scriptCode = $scriptCode;
35
36        return $this;
37    }
38
39    public function getScript(): string
40    {
41        return $this->_scriptCode;
42    }
43
44    /**
45     * {@inheritdoc}
46     */
47    protected function getScriptTypeArray(): array
48    {
49        return ['source' => $this->_scriptCode];
50    }
51}
52