Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop @ratelimit Annotation, Create #[RateLimit] Attribute, Drop php7 support, Drop symfony 3 & 4 support #132

Merged
merged 4 commits into from
Aug 14, 2023
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
23 changes: 11 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2" ]
php: [ "8.0", "8.1", "8.2" ]
composer_flags: [ "", "--prefer-lowest" ]
symfony_version: [ "^3.4", "^4.4", "^5.4", "^6.3"]
symfony_version: [ "^5.4", "^6.1"]
exclude:
- php: "7.2"
symfony_version: "^6.3"
- php: "7.3"
symfony_version: "^6.3"
- php: "7.4"
symfony_version: "^6.3"
- php: "8.0"
symfony_version: "^6.3"
- php: "8.2"
symfony_version: "^4.4"
symfony_version: "^6.1"
name: PHP ${{ matrix.php }} SF ${{ matrix.symfony_version }} ${{ matrix.composer_flags}}
env:
PHP: ${{ matrix.os }}
Expand All @@ -40,6 +32,8 @@ jobs:
ini-values: memory_limit=256M,post_max_size=256M
- name: Checkout ratelimit bundle
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Install dependencies
run: |
composer self-update
Expand All @@ -48,4 +42,9 @@ jobs:
COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
- name: Run tests
run: |
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/simple-phpunit
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/simple-phpunit --coverage-text --coverage-clover=coverage.clover
- name: Upload coverage
if: ${{ matrix.php == '8.1' && github.repository == 'jaytaph/RateLimitBundle' }}
uses: sudo-bot/action-scrutinizer@latest
with:
cli-args: "--format=php-clover coverage.clover"
118 changes: 0 additions & 118 deletions Annotation/RateLimit.php

This file was deleted.

78 changes: 78 additions & 0 deletions Attribute/RateLimit.php
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;
}
}
4 changes: 2 additions & 2 deletions DependencyInjection/NoxlogicRateLimitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class NoxlogicRateLimitExtension extends Extension
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$this->loadServices($container, $config);

}

private function loadServices(ContainerBuilder $container, array $config)
private function loadServices(ContainerBuilder $container, array $config): void
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
Expand Down
Loading
Loading