-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathAnalyticsRules.php
More file actions
105 lines (91 loc) · 2.47 KB
/
Copy pathAnalyticsRules.php
File metadata and controls
105 lines (91 loc) · 2.47 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Typesense;
class AnalyticsRules implements \ArrayAccess
{
const RESOURCE_PATH = '/analytics/rules';
private ApiCall $apiCall;
/**
* @var array
*/
private array $analyticsRules = [];
public function __construct(ApiCall $apiCall)
{
$this->apiCall = $apiCall;
}
/**
* Create one or more analytics rules. You can send a single rule object or an array of rule objects.
*
* @example
* $client->analytics->rules()->create(['name' => 'products_query_hits', 'type' => 'popular_queries', 'params' => []])
*
* @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
*
* @param array $rules Array of rule objects
* @return array Response from the API
*/
public function create(array $rules)
{
return $this->apiCall->post(self::RESOURCE_PATH, $rules);
}
/**
* Retrieve all analytics rules.
*
* @example
* $client->analytics->rules()->retrieve()
*
* @see https://typesense.org/docs/latest/api/analytics-query-suggestions.html
*
* @return array Response from the API
*/
public function retrieve()
{
return $this->apiCall->get(self::RESOURCE_PATH, []);
}
/**
* Get a specific rule by name
*
* @param string $ruleName
* @return AnalyticsRule
*/
public function __get($ruleName)
{
if (isset($this->{$ruleName})) {
return $this->{$ruleName};
}
if (!isset($this->analyticsRules[$ruleName])) {
$this->analyticsRules[$ruleName] = new AnalyticsRule($ruleName, $this->apiCall);
}
return $this->analyticsRules[$ruleName];
}
/**
* ArrayAccess implementation for backwards compatibility
*/
public function offsetExists($offset): bool
{
return isset($this->analyticsRules[$offset]);
}
/**
* @inheritDoc
*/
public function offsetGet($offset): AnalyticsRule
{
if (!isset($this->analyticsRules[$offset])) {
$this->analyticsRules[$offset] = new AnalyticsRule($offset, $this->apiCall);
}
return $this->analyticsRules[$offset];
}
/**
* @inheritDoc
*/
public function offsetSet($offset, $value): void
{
$this->analyticsRules[$offset] = $value;
}
/**
* @inheritDoc
*/
public function offsetUnset($offset): void
{
unset($this->analyticsRules[$offset]);
}
}