update
This commit is contained in:
55
projects/priceservice/vendor/symfony/rate-limiter/Storage/CacheStorage.php
vendored
Normal file
55
projects/priceservice/vendor/symfony/rate-limiter/Storage/CacheStorage.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\RateLimiter\Storage;
|
||||
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\RateLimiter\LimiterStateInterface;
|
||||
|
||||
/**
|
||||
* @author Wouter de Jong <wouter@wouterj.nl>
|
||||
*/
|
||||
class CacheStorage implements StorageInterface
|
||||
{
|
||||
private CacheItemPoolInterface $pool;
|
||||
|
||||
public function __construct(CacheItemPoolInterface $pool)
|
||||
{
|
||||
$this->pool = $pool;
|
||||
}
|
||||
|
||||
public function save(LimiterStateInterface $limiterState): void
|
||||
{
|
||||
$cacheItem = $this->pool->getItem(sha1($limiterState->getId()));
|
||||
$cacheItem->set($limiterState);
|
||||
if (null !== ($expireAfter = $limiterState->getExpirationTime())) {
|
||||
$cacheItem->expiresAfter($expireAfter);
|
||||
}
|
||||
|
||||
$this->pool->save($cacheItem);
|
||||
}
|
||||
|
||||
public function fetch(string $limiterStateId): ?LimiterStateInterface
|
||||
{
|
||||
$cacheItem = $this->pool->getItem(sha1($limiterStateId));
|
||||
$value = $cacheItem->get();
|
||||
if ($value instanceof LimiterStateInterface) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function delete(string $limiterStateId): void
|
||||
{
|
||||
$this->pool->deleteItem(sha1($limiterStateId));
|
||||
}
|
||||
}
|
||||
61
projects/priceservice/vendor/symfony/rate-limiter/Storage/InMemoryStorage.php
vendored
Normal file
61
projects/priceservice/vendor/symfony/rate-limiter/Storage/InMemoryStorage.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\RateLimiter\Storage;
|
||||
|
||||
use Symfony\Component\RateLimiter\LimiterStateInterface;
|
||||
|
||||
/**
|
||||
* @author Wouter de Jong <wouter@wouterj.nl>
|
||||
*/
|
||||
class InMemoryStorage implements StorageInterface
|
||||
{
|
||||
private array $buckets = [];
|
||||
|
||||
public function save(LimiterStateInterface $limiterState): void
|
||||
{
|
||||
$this->buckets[$limiterState->getId()] = [$this->getExpireAt($limiterState), serialize($limiterState)];
|
||||
}
|
||||
|
||||
public function fetch(string $limiterStateId): ?LimiterStateInterface
|
||||
{
|
||||
if (!isset($this->buckets[$limiterStateId])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
[$expireAt, $limiterState] = $this->buckets[$limiterStateId];
|
||||
if (null !== $expireAt && $expireAt <= microtime(true)) {
|
||||
unset($this->buckets[$limiterStateId]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return unserialize($limiterState);
|
||||
}
|
||||
|
||||
public function delete(string $limiterStateId): void
|
||||
{
|
||||
if (!isset($this->buckets[$limiterStateId])) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->buckets[$limiterStateId]);
|
||||
}
|
||||
|
||||
private function getExpireAt(LimiterStateInterface $limiterState): ?float
|
||||
{
|
||||
if (null !== $expireSeconds = $limiterState->getExpirationTime()) {
|
||||
return microtime(true) + $expireSeconds;
|
||||
}
|
||||
|
||||
return $this->buckets[$limiterState->getId()][0] ?? null;
|
||||
}
|
||||
}
|
||||
26
projects/priceservice/vendor/symfony/rate-limiter/Storage/StorageInterface.php
vendored
Normal file
26
projects/priceservice/vendor/symfony/rate-limiter/Storage/StorageInterface.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\RateLimiter\Storage;
|
||||
|
||||
use Symfony\Component\RateLimiter\LimiterStateInterface;
|
||||
|
||||
/**
|
||||
* @author Wouter de Jong <wouter@wouterj.nl>
|
||||
*/
|
||||
interface StorageInterface
|
||||
{
|
||||
public function save(LimiterStateInterface $limiterState): void;
|
||||
|
||||
public function fetch(string $limiterStateId): ?LimiterStateInterface;
|
||||
|
||||
public function delete(string $limiterStateId): void;
|
||||
}
|
||||
Reference in New Issue
Block a user