Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/Stores/MemoryStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ class MemoryStore implements RateLimitStore
*
* @var array<string, mixed>
*/
protected array $store = [];
protected static array $store = [];

/**
* Get a rate limit from the store
*/
public function get(string $key): ?string
{
return $this->store[$key] ?? null;
return self::$store[$key] ?? null;
}

/**
* Set the rate limit into the store
*/
public function set(string $key, string $value, int $ttl): bool
{
$this->store[$key] = $value;
self::$store[$key] = $value;

return true;
}
Expand All @@ -40,6 +40,14 @@ public function set(string $key, string $value, int $ttl): bool
*/
public function getStore(): array
{
return $this->store;
return self::$store;
}

/**
* Clear the store
*/
public static function clear(): void
{
self::$store = [];
}
}
10 changes: 9 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@
|
*/

use Saloon\RateLimitPlugin\Stores\MemoryStore;
use Orchestra\Testbench\TestCase as LaravelTestCase;

uses(LaravelTestCase::class)->in('./Laravel');
uses(LaravelTestCase::class)
->beforeEach(fn () => MemoryStore::clear())
->in('./Laravel');

uses()
->beforeEach(fn () => MemoryStore::clear())
->afterEach(fn () => MemoryStore::clear())
->in('./');

/*
|--------------------------------------------------------------------------
Expand Down
Loading