1<?php
2
3namespace Elastica\Query;
4
5use Elastica\Exception\InvalidException;
6
7/**
8 * SpanOr query.
9 *
10 * @author Marek Hernik <marek.hernik@gmail.com>
11 *
12 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html
13 */
14class SpanOr extends AbstractSpanQuery
15{
16    /**
17     * @param AbstractSpanQuery[] $clauses
18     */
19    public function __construct(array $clauses = [])
20    {
21        foreach ($clauses as $clause) {
22            if (!$clause instanceof AbstractSpanQuery) {
23                throw new InvalidException('Invalid parameter. Has to be array or instance of '.AbstractSpanQuery::class);
24            }
25        }
26
27        $this->setParams(['clauses' => $clauses]);
28    }
29
30    /**
31     * Add clause part to query.
32     *
33     * @throws InvalidException If not valid query
34     *
35     * @return $this
36     */
37    public function addClause(AbstractSpanQuery $clause): self
38    {
39        return $this->addParam('clauses', $clause);
40    }
41}
42