forked from ongr-io/ElasticsearchDSL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParametersTrait.php
100 lines (90 loc) · 1.89 KB
/
ParametersTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL;
/**
* A trait which handles the behavior of parameters in queries, filters, etc.
*/
trait ParametersTrait
{
/**
* @var array
*/
private $parameters = [];
/**
* Checks if parameter exists.
*
* @param string $name
*
* @return bool
*/
public function hasParameter($name)
{
return isset($this->parameters[$name]);
}
/**
* Removes parameter.
*
* @param string $name
*/
public function removeParameter($name)
{
if ($this->hasParameter($name)) {
unset($this->parameters[$name]);
}
}
/**
* Returns one parameter by it's name.
*
* @param string $name
*
* @return array|false
*/
public function getParameter($name)
{
return $this->parameters[$name];
}
/**
* Returns an array of all parameters.
*
* @return array
*/
public function getParameters()
{
return $this->parameters;
}
/**
* @param string $name
* @param array|string|\stdClass $value
*/
public function addParameter($name, $value)
{
$this->parameters[$name] = $value;
}
/**
* Sets an array of parameters.
*
* @param array $parameters
*/
public function setParameters(array $parameters)
{
$this->parameters = $parameters;
}
/**
* Returns given array merged with parameters.
*
* @param array $array
*
* @return array
*/
protected function processArray(array $array = [])
{
return array_merge($array, $this->parameters);
}
}