{"id":20838011,"url":"https://github.com/fusonic/symfony-rate-limit-bundle","last_synced_at":"2025-07-06T01:04:12.554Z","repository":{"id":55843634,"uuid":"136041741","full_name":"fusonic/symfony-rate-limit-bundle","owner":"fusonic","description":null,"archived":false,"fork":false,"pushed_at":"2020-12-11T11:14:00.000Z","size":28,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-30T05:53:33.869Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fusonic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-04T14:59:41.000Z","updated_at":"2020-12-11T11:12:20.000Z","dependencies_parsed_at":"2022-08-15T07:50:19.658Z","dependency_job_id":null,"html_url":"https://github.com/fusonic/symfony-rate-limit-bundle","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/fusonic/symfony-rate-limit-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusonic%2Fsymfony-rate-limit-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusonic%2Fsymfony-rate-limit-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusonic%2Fsymfony-rate-limit-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusonic%2Fsymfony-rate-limit-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fusonic","download_url":"https://codeload.github.com/fusonic/symfony-rate-limit-bundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fusonic%2Fsymfony-rate-limit-bundle/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263833416,"owners_count":23517373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T01:09:10.114Z","updated_at":"2025-07-06T01:04:12.522Z","avatar_url":"https://github.com/fusonic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RateLimitBundle\n\nThis bundle provides simple rate limiting based on routes.\n\n## Getting started\n\n1. Install bundle:\n\n```\ncomposer require fusonic/rate-limit-bundle\n```\n\n2. Add RateLimitBundle to kernel:\n\n```PHP\n    Fusonic\\RateLimitBundle\\RateLimitBundle::class =\u003e ['prod' =\u003e true],\n```\n\n3. Add cache config\n\n```YAML\nframework:\n    cache:\n        app: cache.adapter.array\n```\n\n4. Add rate limit config\n\n```YAML\nfusonic_rate_limit:\n    cache_provider: \"cache.app\"\n    enabled: true\n    routes:\n        foo:\n            limit: 2\n            period: 3600\n```\n\n## How does it work\n\nThe bundle makes use of Symfony's event system. Therefore some events exist under `Fusonic/RateLimitBundle/Event`:\n- **RateLimitAttemptsUpdatedEvent** will be emitted when a request for a rate limited route is detected.\n- **RateLimitExceededEvent** will be emitted when a route limit is exceeded.\n- **RateLimitResetAttemptsEvent** can be used to reset the state for a specific route (e.g. after a successful login)\n\n### Example\n\nCreate an event listener or subscriber:\n\n```PHP\n\u003c?php\n\nnamespace AppBundle\\EventListener;\n\nuse Fusonic\\RateLimitBundle\\Event\\RateLimitEvents;\nuse Fusonic\\RateLimitBundle\\Event\\RateLimitExceededEvent;\nuse Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\nuse Symfony\\Component\\HttpKernel\\Exception\\TooManyRequestsHttpException;\n\nfinal class RateLimitSubscriber implements EventSubscriberInterface\n{\n    public static function getSubscribedEvents(): array\n    {\n        return [\n            RateLimitEvents::ROUTE_LIMIT_EXCEEDED =\u003e 'onLimitExceeded',\n        ];\n    }\n\n    public function onLimitExceeded(RateLimitExceededEvent $event): void\n    {\n        $config = $event-\u003egetRouteLimitConfig();\n        $message = 'You sent too many requests for this endpoint.';\n        throw new TooManyRequestsHttpException($config-\u003egetPeriod(), $message);\n    }\n}\n```\n\nAnd register it as service.\n \n```YAML\n    app.rate_limit_subscriber:\n        class: AppBundle\\EventListener\\RateLimitSubscriber\n        tags:\n            - { name: kernel.event_subscriber }\n\n```\n\n## Execute tests\n\nRun the the tests by executing:\n\n```\nvendor/bin/simple-phpunit\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusonic%2Fsymfony-rate-limit-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffusonic%2Fsymfony-rate-limit-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusonic%2Fsymfony-rate-limit-bundle/lists"}