forked from cloudinary/cloudinary_php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch.php
More file actions
82 lines (62 loc) · 1.85 KB
/
Copy pathSearch.php
File metadata and controls
82 lines (62 loc) · 1.85 KB
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
<?php
namespace Cloudinary {
class Search
{
private $query_hash;
public function __construct()
{
$this->query_hash = array(
'sort_by' => array(),
'aggregate' => array(),
'with_field' => array(),
);
}
public function expression($value)
{
$this->query_hash['expression'] = $value;
return $this;
}
public function max_results($value)
{
$this->query_hash['max_results'] = $value;
return $this;
}
public function next_cursor($value)
{
$this->query_hash['next_cursor'] = $value;
return $this;
}
public function sort_by($field_name, $dir = 'desc')
{
array_push($this->query_hash['sort_by'], array($field_name => $dir));
return $this;
}
public function aggregate($value)
{
array_push($this->query_hash['aggregate'], $value);
return $this;
}
public function with_field($value)
{
array_push($this->query_hash['with_field'], $value);
return $this;
}
public function as_array()
{
return array_filter(
$this->query_hash,
function ($value) {
return ((is_array($value) && !empty($value)) || ($value != null));
}
);
}
public function execute($options = array())
{
$api = new Api();
$uri = array('resources/search');
$options = array_merge($options, array('content_type' => 'application/json'));
$method = 'post';
return $api->call_api($method, $uri, $this->as_array(), $options);
}
}
}