1. Go to this page and download the library: Download ekreative/ratelimit-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/ */
ekreative / ratelimit-bundle example snippets
use Noxlogic\RateLimitBundle\Annotation\RateLimit;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
/**
* @Route(...)
*
* @RateLimit(limit=1000, period=3600)
*/
public function someApiAction()
{
}
use Noxlogic\RateLimitBundle\Annotation\RateLimit;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
/**
* @Route(...)
*
* @RateLimit(methods={"PUT", "POST"}, limit=1000, period=3600)
* @RateLimit(methods={"GET"}, limit=1000, period=3600)
* @RateLimit(limit=5000, period=3600)
*/
public function someApiAction()
{
}
use Noxlogic\RateLimitBundle\Annotation\RateLimit;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
/**
* @Ratelimit(methods={"POST"}, limit=100, period=10); // 100 POST requests per 10 seconds
*/
class DefaultController extends Controller
{
/**
* @ratelimit(method="POST", limit=200, period=10); // 200 POST requests to indexAction allowed.
*/
public function indexAction()
{
}
}
namespace MyBundle\Listener;
use Noxlogic\RateLimitBundle\Events\GenerateKeyEvent;
class RateLimitGenerateKeyListener
{
public function onGenerateKey(GenerateKeyEvent $event)
{
$key = $this->generateKey();
$event->addToKey($key);
// $event->setKey($key); // to overwrite key completely
}
}