1<?php 2 3namespace Elastica\Query; 4 5use Elastica\Script\AbstractScript; 6use Elastica\Script\Script as BaseScript; 7 8/** 9 * Script query. 10 * 11 * @author Nicolas Ruflin <spam@ruflin.com> 12 * 13 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html 14 */ 15class Script extends AbstractQuery 16{ 17 /** 18 * Construct script query. 19 * 20 * @param AbstractScript|array|string $script Script 21 */ 22 public function __construct($script = null) 23 { 24 if (null !== $script) { 25 $this->setScript($script); 26 } 27 } 28 29 /** 30 * Sets script object. 31 * 32 * @param array|BaseScript|string $script 33 * 34 * @return $this 35 */ 36 public function setScript($script): self 37 { 38 return $this->setParam('script', BaseScript::create($script)); 39 } 40 41 /** 42 * {@inheritdoc} 43 */ 44 public function toArray(): array 45 { 46 $array = parent::toArray(); 47 48 if (isset($array['script'])) { 49 $array['script'] = $array['script']['script']; 50 } 51 52 return $array; 53 } 54} 55