|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bardex\Elastic; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class Script |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* @var string язык скрипта |
|
10
|
|
|
*/ |
|
11
|
|
|
protected $language = ''; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var array параметры скрипта |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $params = []; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var array тело скрипта |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $lines = []; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string разделитель строк в теле скрипта |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $lineSeparator = "\n"; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Создать новый скрипт |
|
30
|
|
|
* @param string $language=painless |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct($language='painless') |
|
33
|
|
|
{ |
|
34
|
|
|
$this->language = $language; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Установить разделитель строк в теле скрипта |
|
40
|
|
|
* @param string $lineSeparator |
|
41
|
|
|
* @return self $this |
|
42
|
|
|
*/ |
|
43
|
|
|
public function setLineSeparator($lineSeparator) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->lineSeparator = $lineSeparator; |
|
46
|
|
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Добавить строку в тело скрипта |
|
52
|
|
|
* @param string $line - строка |
|
53
|
|
|
* @return self $this |
|
54
|
|
|
*/ |
|
55
|
|
|
public function addLine($line) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->lines[] = $line; |
|
58
|
|
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Добавить параметр скрипта |
|
63
|
|
|
* @param string $name - имя параметра |
|
64
|
|
|
* @param mixed $value - значение параметра |
|
65
|
|
|
* @return self $this |
|
66
|
|
|
*/ |
|
67
|
|
|
public function addParam($name, $value) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->params[$name] = $value; |
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Скомпилировать скрипт в elastic-query тип |
|
75
|
|
|
* @return array |
|
76
|
|
|
*/ |
|
77
|
|
|
public function compile() |
|
78
|
|
|
{ |
|
79
|
|
|
$script = [ |
|
80
|
|
|
'script' => [ |
|
81
|
|
|
'lang' => $this->getLanguage(), |
|
82
|
|
|
'inline' => $this->getBody(), |
|
83
|
|
|
'params' => $this->getParams() |
|
84
|
|
|
] |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
// because ES |
|
88
|
|
|
if (empty($script['script']['params'])) unset($script['script']['params']); |
|
89
|
|
|
|
|
90
|
|
|
return $script; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Скомпилировать тело скрипта |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getBody() |
|
98
|
|
|
{ |
|
99
|
|
|
$body = implode($this->lineSeparator, $this->lines); |
|
100
|
|
|
return $body; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Получить параметры скрипта |
|
105
|
|
|
* @return array |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getParams() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->params; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Получить язык скрипта |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getLanguage() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->language; |
|
119
|
|
|
} |
|
120
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.