Skip to content

Commit 5df18c9

Browse files
author
Simonas Šerlinskas
committed
Merge remote-tracking branch 'remotes/origin/5.x' into 6.x
# Conflicts: # composer.json
2 parents 6f9ba45 + 14b8fc6 commit 5df18c9

File tree

9 files changed

+60
-14
lines changed

9 files changed

+60
-14
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"require": {
1414
"php": "^7.0",
1515
"symfony/serializer": "^3.0|^4.0",
16-
"paragonie/random_compat": "^1.0|^2.0"
16+
"paragonie/random_compat": "*"
1717
},
1818
"require-dev": {
1919
"elasticsearch/elasticsearch": "^6.0",

Diff for: src/Aggregation/Bucketing/DateHistogramAggregation.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,25 @@ class DateHistogramAggregation extends AbstractAggregation
2828
*/
2929
protected $interval;
3030

31+
/**
32+
* @var string
33+
*/
34+
protected $format;
35+
3136
/**
3237
* Inner aggregations container init.
3338
*
3439
* @param string $name
3540
* @param string $field
3641
* @param string $interval
3742
*/
38-
public function __construct($name, $field = null, $interval = null)
43+
public function __construct($name, $field = null, $interval = null, $format = null)
3944
{
4045
parent::__construct($name);
4146

4247
$this->setField($field);
4348
$this->setInterval($interval);
49+
$this->setFormat($format);
4450
}
4551

4652
/**
@@ -59,6 +65,14 @@ public function setInterval($interval)
5965
$this->interval = $interval;
6066
}
6167

68+
/**
69+
* @param string $format
70+
*/
71+
public function setFormat($format)
72+
{
73+
$this->format = $format;
74+
}
75+
6276
/**
6377
* {@inheritdoc}
6478
*/
@@ -81,6 +95,10 @@ public function getArray()
8195
'interval' => $this->getInterval(),
8296
];
8397

98+
if (!empty($this->format)) {
99+
$out['format'] = $this->format;
100+
}
101+
84102
return $out;
85103
}
86104
}

Diff for: src/Aggregation/Bucketing/DateRangeAggregation.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ public function addRange($from = null, $to = null, $key = null)
8686
'from' => $from,
8787
'to' => $to,
8888
'key' => $key,
89-
]
89+
],
90+
function ($v) {
91+
return !is_null($v);
92+
}
9093
);
9194

9295
if (empty($range)) {

Diff for: src/Aggregation/Bucketing/GeoDistanceAggregation.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ public function addRange($from = null, $to = null)
132132
[
133133
'from' => $from,
134134
'to' => $to,
135-
]
135+
],
136+
function ($v) {
137+
return !is_null($v);
138+
}
136139
);
137140

138141
if (empty($range)) {

Diff for: src/Aggregation/Bucketing/Ipv4RangeAggregation.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ public function addRange($from = null, $to = null)
6565
[
6666
'from' => $from,
6767
'to' => $to,
68-
]
68+
],
69+
function ($v) {
70+
return !is_null($v);
71+
}
6972
);
7073

7174
$this->ranges[] = $range;

Diff for: src/Aggregation/Bucketing/RangeAggregation.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ public function addRange($from = null, $to = null, $key = '')
8484
[
8585
'from' => $from,
8686
'to' => $to,
87-
]
87+
],
88+
function ($v) {
89+
return !is_null($v);
90+
}
8891
);
8992

9093
if ($this->keyed && !empty($key)) {

Diff for: src/Query/Compound/BoolQuery.php

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public function toArray()
116116

117117
$output = $this->processArray($output);
118118

119+
if (empty($output)) {
120+
$output = new \stdClass();
121+
}
122+
119123
return [$this->getType() => $output];
120124
}
121125

Diff for: src/Search.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class Search
155155
/**
156156
* @var OrderedSerializer
157157
*/
158-
private $serializer;
158+
private static $serializer;
159159

160160
/**
161161
* @var SearchEndpointInterface[]
@@ -167,12 +167,14 @@ class Search
167167
*/
168168
public function __construct()
169169
{
170-
$this->serializer = new OrderedSerializer(
171-
[
172-
new CustomReferencedNormalizer(),
173-
new CustomNormalizer(),
174-
]
175-
);
170+
if (static::$serializer === null) {
171+
static::$serializer = new OrderedSerializer(
172+
[
173+
new CustomReferencedNormalizer(),
174+
new CustomNormalizer(),
175+
]
176+
);
177+
}
176178
}
177179

178180
/**
@@ -703,7 +705,7 @@ public function getUriParams()
703705
*/
704706
public function toArray()
705707
{
706-
$output = array_filter($this->serializer->normalize($this->endpoints));
708+
$output = array_filter(static::$serializer->normalize($this->endpoints));
707709

708710
$params = [
709711
'from' => 'from',

Diff for: tests/Unit/Query/Compound/BoolQueryTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public function testBoolToArray()
6969
$this->assertEquals($expected, $bool->toArray());
7070
}
7171

72+
/**
73+
* Tests bool query with empty body if it forms \stdObject
74+
*/
75+
public function testEmptyBoolQuery()
76+
{
77+
$bool = new BoolQuery();
78+
79+
$this->assertEquals(['bool' => new \stdClass()], $bool->toArray());
80+
}
81+
7282
/**
7383
* Tests bool query in filter context.
7484
*/

0 commit comments

Comments
 (0)