-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathMemory.php
More file actions
69 lines (58 loc) · 1.31 KB
/
Memory.php
File metadata and controls
69 lines (58 loc) · 1.31 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
<?php
declare(strict_types=1);
namespace Gnikyt\BasicShopifyAPI\Store;
use Gnikyt\BasicShopifyAPI\Contracts\StateStorage;
use Gnikyt\BasicShopifyAPI\Session;
/**
* In-memory storage for timestamps used by rate limit middleware.
* Based on spatie/guzzle-rate-limiter-middleware.
*/
class Memory implements StateStorage
{
/**
* The data container.
*
* @var array
*/
protected $container = [];
/**
* {@inheritdoc}
*/
public function all(): array
{
return $this->container;
}
/**
* {@inheritdoc}
*/
public function get(Session $session): array
{
$shop = $session->getShop();
return $this->container[$shop] ?? [];
}
/**
* {@inheritdoc}
*/
public function set(array $values, Session $session): void
{
$this->container[$session->getShop()] = $values;
}
/**
* {@inheritdoc}
*/
public function push($value, Session $session): void
{
$shop = $session->getShop();
if (!isset($this->container[$shop])) {
$this->reset($session);
}
array_unshift($this->container[$shop], $value);
}
/**
* {@inheritdoc}
*/
public function reset(Session $session): void
{
$this->container[$session->getShop()] = [];
}
}