Skip to content

Commit 7052a58

Browse files
committed
fox is_callable function
1 parent b3ee2a9 commit 7052a58

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

src/Classes/Search.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(Query $query, $q, $settings = NULL)
4444
$this->query = $query;
4545
$this->q = $q;
4646

47-
if(is_callable($settings)){
47+
if(is_callback_function($settings)){
4848
$settings($this);
4949
}
5050

src/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function create()
142142

143143
$callback = $this->callback;
144144

145-
if (is_callable($callback)) {
145+
if (is_callback_function($callback)) {
146146
$callback($this);
147147
}
148148

src/Query.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public function id($_id = false)
434434
public function where($name, $operator = "=", $value = NULL)
435435
{
436436

437-
if (is_callable($name)) {
437+
if (is_callback_function($name)) {
438438
$name($this);
439439
return $this;
440440
}
@@ -491,7 +491,7 @@ public function where($name, $operator = "=", $value = NULL)
491491
public function whereNot($name, $operator = "=", $value = NULL)
492492
{
493493

494-
if (is_callable($name)) {
494+
if (is_callback_function($name)) {
495495
$name($this);
496496
return $this;
497497
}
@@ -584,7 +584,7 @@ public function whereNotBetween($name, $first_value, $last_value = null)
584584
public function whereIn($name, $value = [])
585585
{
586586

587-
if (is_callable($name)) {
587+
if (is_callback_function($name)) {
588588
$name($this);
589589
return $this;
590590
}
@@ -604,7 +604,7 @@ public function whereIn($name, $value = [])
604604
public function whereNotIn($name, $value = [])
605605
{
606606

607-
if (is_callable($name)) {
607+
if (is_callback_function($name)) {
608608
$name($this);
609609
return $this;
610610
}
@@ -653,7 +653,7 @@ public function whereExists($name, $exists = true)
653653
public function distance($name, $value, $distance)
654654
{
655655

656-
if (is_callable($name)) {
656+
if (is_callback_function($name)) {
657657
$name($this);
658658
return $this;
659659
}
@@ -681,7 +681,7 @@ public function search($q = NULL, $settings = NULL)
681681

682682
$search = new Search($this, $q, $settings);
683683

684-
if(!is_callable($settings)){
684+
if(!is_callback_function($settings)){
685685
$search->boost($settings ? $settings : 1);
686686
}
687687

@@ -757,22 +757,22 @@ function body($body = [])
757757
public function query()
758758
{
759759

760-
$query = [
760+
$query = [];
761761

762-
'index' => $this->getIndex(),
762+
$query["index"] = $this->getIndex();
763763

764-
'body' => $this->getBody(),
765-
766-
"from" => $this->getSkip(),
764+
if ($this->getType()) {
765+
$query["type"] = $this->getType();
766+
}
767767

768-
"size" => $this->getTake(),
768+
$query["body"] = $this->getBody();
769769

770-
'client' => ['ignore' => $this->ignores]
770+
$query["from"] = $this->getSkip();
771771

772-
];
772+
$query["size"] = $this->getTake();
773773

774-
if ($this->getType()) {
775-
$query["type"] = $this->getType();
774+
if(count($this->ignores)){
775+
$query["client"] = ['ignore' => $this->ignores];
776776
}
777777

778778
$search_type = $this->getSearchType();
@@ -1053,7 +1053,7 @@ public function insert($data, $_id = NULL)
10531053
public function bulk($data)
10541054
{
10551055

1056-
if (is_callable($data)) {
1056+
if (is_callback_function($data)) {
10571057

10581058
$bulk = new Bulk($this);
10591059

src/helpers.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@ function config_path($path = '')
1313
return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
1414
}
1515
}
16+
17+
if ( ! function_exists('is_callback_function'))
18+
{
19+
/**
20+
* Check if a callback function.
21+
*
22+
* @param string $callback
23+
* @return string
24+
*/
25+
function is_callback_function($callback)
26+
{
27+
return is_callable($callback) && is_object($callback) && $callback instanceof Closure;
28+
}
29+
}
30+
31+

tests/Traits/ESQueryTrait.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ protected function getQueryArray()
5454

5555
'size' => $this->take,
5656

57-
'client' => [
58-
59-
'ignore' => []
60-
61-
]
62-
6357
];
6458
}
6559

tests/WhereTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ protected function getExpected($name, $operator = "=", $value = NULL)
147147

148148
$query["body"]["query"]["bool"] = $bool;
149149

150-
151150
return $query;
152151
}
153152

0 commit comments

Comments
 (0)