2017 © Pedro Peláez
 

library laravel-ez-throttle

A simple Laravel Throttle extension

image

acidf0x/laravel-ez-throttle

A simple Laravel Throttle extension

  • Friday, January 12, 2018
  • by AcidF0x
  • Repository
  • 0 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Laravel-EzThrottle

A simple Laravel Throttle extension, (*1)

Installation

install using composer:, (*2)

 composer require acidf0x/laravel-ez-throttle

Basic Usage

Start by creating an Throttle instance, (*3)

use AcidF0x\EzThrottle\Throttle;  

$throttle = new Throttle();
// or
$throttle = new Throttle($throttleKey , $maxAttempts, $decayMinutes);


// increase hit count
$throttle->hit()

if ($throttle->isBlock()) {
    echo $throttle->getErrorMsg(); // "Too Many Requests. Please try again in 1 minutes"
} else {
    // ...

    if ( ... ) {
        $throttle->clear();   
    }

}

or use the EzThrottle trait if you want, (*4)

use AcidF0x\EzThrottle\Foundation\EzThrottle;

class SomeController extends Controller
{
    use EzThrottle;

    $protected $ThrottleKey = 'LoginThrottle';
    $protected $maxAttempts = '3';
    $protected $decayMinutes = '1';

    public function doLogin()
    {
        //.....

        // increase hit count
        $this->hit()
        if ($this->isBlock()) {
            return $this->getErrorMsg(); // "Too Many Requests. Please try again in 1 minutes"
        } else {
            // ...
            if ( ... ) {
                $this->clear();
            }
        }

        //......
    }
}

Customize

php artisan vendor:publish --provider=AcixF0x\Ezthrrotle\EzthrottleServiceProvider

Localization

# resources/lang/vendor/ezthrottle/en/error.php

return [
        'sec'=> 'Too Many Requests. Please try again in :sec seconds',
        'min'=> 'Too Many Requests. Please try again in :min minutes',
        'hour'=> 'Too Many Requests. Please try again in :hour hours',
        'days'=> 'Too Many Requests. Please try again in :day days',
];

Config

# config/ezthrottle.php
return [
    'defaultThrottleKey' => 'throttle', 
    'defaultDecayMinutes' => '1',
    'defaultMaxAttempts' => '3'
];

Todos

  • [ ] change Trait Method
  • [ ] Test and support Variable Laravel Ver. (5.*)
  • [ ] Change Composer Dependency

The Versions

12/01 2018

dev-master

9999999-dev

A simple Laravel Throttle extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by duhuicho

11/01 2018

v1.0.0

1.0.0.0

A simple Laravel Throttle extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by duhuicho

11/01 2018

v1.0.0-alpha.4

1.0.0.0-alpha4

A simple Laravel Throttle extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by duhuicho

11/01 2018

v1.0.0-alpha.3

1.0.0.0-alpha3

A simple Laravel Throttle extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by duhuicho

11/01 2018

v1.0.0-alpha.2

1.0.0.0-alpha2

A simple Laravel Throttle extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by duhuicho

11/01 2018

v1.0.0-alpha.1

1.0.0.0-alpha1

A simple Laravel Throttle extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by duhuicho