forked from typesense/typesense-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyticsRulesV1.php
More file actions
75 lines (62 loc) · 1.67 KB
/
AnalyticsRulesV1.php
File metadata and controls
75 lines (62 loc) · 1.67 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
<?php
namespace Typesense;
class AnalyticsRulesV1 implements \ArrayAccess
{
const RESOURCE_PATH = '/analytics/rules';
private ApiCall $apiCall;
private $analyticsRules = [];
public function __construct(ApiCall $apiCall)
{
$this->apiCall = $apiCall;
}
public function __get($ruleName)
{
if (!isset($this->analyticsRules[$ruleName])) {
$this->analyticsRules[$ruleName] = new AnalyticsRuleV1($ruleName, $this->apiCall);
}
return $this->analyticsRules[$ruleName];
}
public function upsert($ruleName, $params)
{
return $this->apiCall->put($this->endpoint_path($ruleName), $params);
}
public function retrieve()
{
return $this->apiCall->get($this->endpoint_path(), []);
}
private function endpoint_path($operation = null)
{
return self::RESOURCE_PATH . ($operation === null ? '' : "/" . encodeURIComponent($operation));
}
/**
* @inheritDoc
*/
public function offsetExists($offset): bool
{
return isset($this->analyticsRules[$offset]);
}
/**
* @inheritDoc
*/
public function offsetGet($offset): AnalyticsRuleV1
{
if (!isset($this->analyticsRules[$offset])) {
$this->analyticsRules[$offset] = new AnalyticsRuleV1($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]);
}
}