Script.php 1.3 KB

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