在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):GrahamCampbell/Laravel-Throttle开源软件地址(OpenSource Url):https://github.com/GrahamCampbell/Laravel-Throttle开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Laravel ThrottleLaravel Throttle was created by, and is maintained by Graham Campbell, and is a rate limiter for Laravel. Feel free to check out the change log, releases, security policy, license, code of conduct, and contribution guidelines. InstallationThis version requires PHP 7.4-8.1 and supports Laravel 8-9.
To get the latest version, simply require the project using Composer: $ composer require "graham-campbell/throttle:^9.0" Once installed, if you are not using automatic package discovery, then you need to register the You can also optionally alias our facade: 'Throttle' => GrahamCampbell\Throttle\Facades\Throttle::class, ConfigurationLaravel Throttle supports optional configuration. To get started, you'll need to publish all vendor assets: $ php artisan vendor:publish This will create a There is one config option: Cache DriverThis option ( UsageThrottleThis is the class of most interest. It is bound to the ioc container as The The other 5 methods all accept the same parameters as the Facades\ThrottleThis facade will dynamically pass static method calls to the Throttler\ThrottlerInterfaceThis interface defines the public methods a throttler class must implement. All 5 methods here accept no parameters. The The The The The Throttler\CacheThrottlerThis class implements Factories\FactoryInterfaceThis interface defines the public methods a throttler factory class must implement. Such a class must only implement one method. The Factories\CacheFactoryThis class implements Http\Middleware\ThrottleMiddlewareYou may put the ThrottleServiceProviderThis class contains no public methods of interest. This class should be added to the providers array in Real ExamplesHere you can see an example of just how simple this package is to use. Our first example will be a super simple usage of our default middleware. This will setup a middleware for that url with a limit of 10 hits and a retention time of 1 hour. use Illuminate\Support\Facades\Route;
Route::get('foo', ['middleware' => 'GrahamCampbell\Throttle\Http\Middleware\ThrottleMiddleware', function () {
return 'Why herro there!';
}]); What if we want custom limits? Easy! Laravel allows us to pass parameters to a middleware. This will setup a middleware for that url with a limit of 50 hits and a retention time of 30 mins. use Illuminate\Support\Facades\Route;
Route::get('foo', ['middleware' => 'GrahamCampbell\Throttle\Http\Middleware\ThrottleMiddleware:50,30', function () {
return 'Why herro there!';
}]); What if we don't want to use the default middleware provided with this package? Well, that's easy too. use GrahamCampbell\Throttle\Facades\Throttle;
use Illuminate\Support\Facades\Request;
// now let's get a throttler object for that request
// we'll use the same config as in the previous example
// note that only the first parameter is "required"
$throttler = Throttle::get(Request::instance(), 50, 30);
// let's check if we've gone over the limit
var_dump($throttler->check());
// we implement Countable
var_dump(count($throttler));
// there are a few more functions available
// please see the previous documentation Also note that you can call methods straight on the factory instead of calling the get method. use GrahamCampbell\Throttle\Facades\Throttle;
use Illuminate\Support\Facades\Request;
$request = Request::instance();
// the attempt function will hit the throttle, then return check
var_dump(Throttle::attempt($request));
// so this is the same as writing
var_dump(Throttle::hit($request)->check());
// and, of course, the same as
var_dump(Throttle::get($request)->attempt()); Further InformationThere are other classes in this package that are not documented here (such as the transformers). This is because they are not intended for public use and are used internally by this package. SecurityIf you discover a security vulnerability within this package, please send an email to [email protected]. All security vulnerabilities will be promptly addressed. You may view our full security policy here. LicenseLaravel Throttle is licensed under The MIT License (MIT). For EnterpriseAvailable as part of the Tidelift Subscription The maintainers of |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论