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     * Constructs a SpanOr query object.
18     *
19     * @param AbstractSpanQuery[] $clauses
20     */
21    public function __construct(array $clauses = [])
22    {
23        if (!empty($clauses)) {
24            foreach ($clauses as $clause) {
25                if (!$clause instanceof AbstractSpanQuery) {
26                    throw new InvalidException(
27                        'Invalid parameter. Has to be array or instance of '.AbstractSpanQuery::class
28                    );
29                }
30            }
31        }
32        $this->setParams(['clauses' => $clauses]);
33    }
34
35    /**
36     * Add clause part to query.
37     *
38     * @param AbstractSpanQuery $clause
39     *
40     * @throws InvalidException If not valid query
41     *
42     * @return $this
43     */
44    public function addClause(AbstractSpanQuery $clause): self
45    {
46        return $this->addParam('clauses', $clause);
47    }
48}
49