-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from axi/attributes
Drop @ratelimit Annotation, Create #[RateLimit] Attribute, Drop php7 support, Drop symfony 3 & 4 support
- Loading branch information
Showing
22 changed files
with
429 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Noxlogic\RateLimitBundle\Attribute; | ||
|
||
#[\Attribute(\Attribute::IS_REPEATABLE |\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] | ||
final class RateLimit | ||
{ | ||
/** | ||
* @var array HTTP Methods protected by this attribute. Defaults to all method | ||
*/ | ||
public array $methods = []; | ||
|
||
public function __construct( | ||
$methods = [], | ||
|
||
/** | ||
* @var int Number of calls per period | ||
*/ | ||
public int $limit = -1, | ||
|
||
/** | ||
* @var int Number of seconds of the time period in which the calls can be made | ||
*/ | ||
public int $period = 3600, | ||
|
||
/** | ||
* @var mixed Generic payload | ||
*/ | ||
public mixed $payload = null | ||
) { | ||
// @RateLimit annotation used to support single method passed as string, keep that for retrocompatibility | ||
if (!is_array($methods)) { | ||
$this->methods = [$methods]; | ||
} else { | ||
$this->methods = $methods; | ||
} | ||
} | ||
|
||
public function getLimit(): int | ||
{ | ||
return $this->limit; | ||
} | ||
|
||
public function setLimit(int $limit): void | ||
{ | ||
$this->limit = $limit; | ||
} | ||
|
||
public function getMethods(): array | ||
{ | ||
return $this->methods; | ||
} | ||
|
||
public function setMethods($methods): void | ||
{ | ||
$this->methods = (array) $methods; | ||
} | ||
|
||
public function getPeriod(): int | ||
{ | ||
return $this->period; | ||
} | ||
|
||
public function setPeriod(int $period): void | ||
{ | ||
$this->period = $period; | ||
} | ||
|
||
public function getPayload(): mixed | ||
{ | ||
return $this->payload; | ||
} | ||
|
||
public function setPayload(mixed $payload): void | ||
{ | ||
$this->payload = $payload; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.