1<?php
2
3namespace Elastica\QueryBuilder;
4
5/**
6 * Abstract Version class.
7 *
8 * @author Manuel Andreo Garcia <andreo.garcia@googlemail.com>
9 */
10abstract class Version
11{
12    /**
13     * supported query methods.
14     *
15     * @var string[]
16     */
17    protected $queries = [];
18
19    /**
20     * supported filter methods.
21     *
22     * @var string[]
23     */
24    protected $filters = [];
25
26    /**
27     * supported aggregation methods.
28     *
29     * @var string[]
30     */
31    protected $aggregations = [];
32
33    /**
34     * supported $suggester methods.
35     *
36     * @var string[]
37     */
38    protected $suggesters = [];
39
40    /**
41     * supported methods for field collapsing.
42     *
43     * @var array
44     */
45    protected $collapsers = [];
46
47    /**
48     * returns true if $name is supported, false otherwise.
49     */
50    public function supports(string $name, string $type): bool
51    {
52        switch ($type) {
53            case DSL::TYPE_QUERY:
54                return \in_array($name, $this->queries, true);
55            case DSL::TYPE_AGGREGATION:
56                return \in_array($name, $this->aggregations, true);
57            case DSL::TYPE_SUGGEST:
58                return \in_array($name, $this->suggesters, true);
59            case DSL::TYPE_COLLAPSE:
60                return \in_array($name, $this->collapsers, true);
61        }
62
63        // disables version check in Facade for custom DSL objects
64        return true;
65    }
66
67    /**
68     * @return string[]
69     */
70    public function getAggregations(): array
71    {
72        return $this->aggregations;
73    }
74
75    /**
76     * @return string[]
77     */
78    public function getQueries(): array
79    {
80        return $this->queries;
81    }
82
83    /**
84     * @return string[]
85     */
86    public function getSuggesters(): array
87    {
88        return $this->suggesters;
89    }
90
91    /**
92     * @return string[]
93     */
94    public function getCollapsers(): array
95    {
96        return $this->collapsers;
97    }
98}
99