PHP code example of bedrockstreaming / rate-limit-bundle

1. Go to this page and download the library: Download bedrockstreaming/rate-limit-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bedrockstreaming / rate-limit-bundle example snippets




return [
    ...
    Bedrock\Bundle\RateLimitBundle\RateLimitBundle::class => ['all' => true],
    ...
];

#[RateLimit(limit: 10, period: 120)]

#[GraphQlRateLimit(
    endpoints: [
        [ 'endpoint' => 'GetMyQuery', 'limit' => 10, 'period' => 12],
        [ 'endpoint' => 'EditMyMutation'],
    ]
)]

$rectorConfig->ruleWithConfiguration(
    \Rector\Php80\Rector\Class_\AnnotationToAttributeRector::class,
    [
        new \Rector\Php80\ValueObject\AnnotationToAttribute(
        'Bedrock\Bundle\RateLimitBundle\Annotation\GraphQLRateLimit',
        \Bedrock\Bundle\RateLimitBundle\Attribute\GraphQLRateLimit::class
        ),
        new \Rector\Php80\ValueObject\AnnotationToAttribute(
            'Bedrock\Bundle\RateLimitBundle\Annotation\RateLimit',
            \Bedrock\Bundle\RateLimitBundle\Attribute\RateLimit::class
        )
    ],
);
yaml
    ...
    Bedrock\Bundle\RateLimitBundle\RateLimitModifier\HttpMethodRateLimitModifier:
        tags: [ 'rate_limit.modifiers' ]   

    Bedrock\Bundle\RateLimitBundle\RateLimitModifier\RequestAttributeRateLimitModifier:
            arguments:
                $attributeName: 'myRequestAttribute'
            tags: [ 'rate_limit.modifiers' ]
 
    ...
yaml
bedrock_rate_limit:
    limit: 1000
    period: 60

    routes:
        get_foobar:
            limit: 500
            period: 10
        post_foobar:
            period: 10