Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Cache\RateLimiting;
4
 
5
class Limit
6
{
7
    /**
8
     * The rate limit signature key.
9
     *
10
     * @var mixed
11
     */
12
    public $key;
13
 
14
    /**
15
     * The maximum number of attempts allowed within the given number of minutes.
16
     *
17
     * @var int
18
     */
19
    public $maxAttempts;
20
 
21
    /**
22
     * The number of minutes until the rate limit is reset.
23
     *
24
     * @var int
25
     */
26
    public $decayMinutes;
27
 
28
    /**
29
     * The response generator callback.
30
     *
31
     * @var callable
32
     */
33
    public $responseCallback;
34
 
35
    /**
36
     * Create a new limit instance.
37
     *
38
     * @param  mixed  $key
39
     * @param  int  $maxAttempts
40
     * @param  int  $decayMinutes
41
     * @return void
42
     */
43
    public function __construct($key = '', int $maxAttempts = 60, int $decayMinutes = 1)
44
    {
45
        $this->key = $key;
46
        $this->maxAttempts = $maxAttempts;
47
        $this->decayMinutes = $decayMinutes;
48
    }
49
 
50
    /**
51
     * Create a new rate limit.
52
     *
53
     * @param  int  $maxAttempts
54
     * @return static
55
     */
56
    public static function perMinute($maxAttempts)
57
    {
58
        return new static('', $maxAttempts);
59
    }
60
 
61
    /**
62
     * Create a new rate limit using minutes as decay time.
63
     *
64
     * @param  int  $decayMinutes
65
     * @param  int  $maxAttempts
66
     * @return static
67
     */
68
    public static function perMinutes($decayMinutes, $maxAttempts)
69
    {
70
        return new static('', $maxAttempts, $decayMinutes);
71
    }
72
 
73
    /**
74
     * Create a new rate limit using hours as decay time.
75
     *
76
     * @param  int  $maxAttempts
77
     * @param  int  $decayHours
78
     * @return static
79
     */
80
    public static function perHour($maxAttempts, $decayHours = 1)
81
    {
82
        return new static('', $maxAttempts, 60 * $decayHours);
83
    }
84
 
85
    /**
86
     * Create a new rate limit using days as decay time.
87
     *
88
     * @param  int  $maxAttempts
89
     * @param  int  $decayDays
90
     * @return static
91
     */
92
    public static function perDay($maxAttempts, $decayDays = 1)
93
    {
94
        return new static('', $maxAttempts, 60 * 24 * $decayDays);
95
    }
96
 
97
    /**
98
     * Create a new unlimited rate limit.
99
     *
100
     * @return static
101
     */
102
    public static function none()
103
    {
104
        return new Unlimited;
105
    }
106
 
107
    /**
108
     * Set the key of the rate limit.
109
     *
110
     * @param  mixed  $key
111
     * @return $this
112
     */
113
    public function by($key)
114
    {
115
        $this->key = $key;
116
 
117
        return $this;
118
    }
119
 
120
    /**
121
     * Set the callback that should generate the response when the limit is exceeded.
122
     *
123
     * @param  callable  $callback
124
     * @return $this
125
     */
126
    public function response(callable $callback)
127
    {
128
        $this->responseCallback = $callback;
129
 
130
        return $this;
131
    }
132
}