|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of laravel-quota |
|
5
|
|
|
* |
|
6
|
|
|
* (c) David Faith <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* Full copyright and license information is available |
|
9
|
|
|
* in the LICENSE file distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Projectmentor\Quota\Stubs; |
|
13
|
|
|
|
|
14
|
|
|
use Projectmentor\Quota\Contracts\PayloadInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* This is the rate data class. |
|
18
|
|
|
* |
|
19
|
|
|
* It stubs constructor parameters for: |
|
20
|
|
|
* bandwithThottle\tokenBucket\Rate |
|
21
|
|
|
* |
|
22
|
|
|
* Initial properties for a new Rate instance via |
|
23
|
|
|
* Projectmentor\Quota\Factories\FactoryInterface |
|
24
|
|
|
* |
|
25
|
|
|
* @author David Faith <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class RateData implements PayloadInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* The rate limit |
|
31
|
|
|
* i.e. capacity of the token-bucket |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $limit; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The time period constant from Rate |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $period; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Initialize $this |
|
44
|
|
|
* @param int $limit capacity |
|
45
|
|
|
* @param string $period Rate::<CONSTANT> |
|
46
|
|
|
* @return void |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct($limit, $period) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->limit = $limit; |
|
|
|
|
|
|
51
|
|
|
$this->period = $period; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get the token bucket capacity |
|
56
|
|
|
* i.e: the maximum number of |
|
57
|
|
|
* tokens available at any time. |
|
58
|
|
|
* @return |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getLimit() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->limit; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Get the constant name for the |
|
67
|
|
|
* time period between |
|
68
|
|
|
* bucket refill. |
|
69
|
|
|
* e.g: 'SECOND' | 'DAY' ... |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getPeriod() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->period; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Implements PayloadInterface |
|
80
|
|
|
* emit json payload. |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function toJson() |
|
84
|
|
|
{ |
|
85
|
|
|
return 'Hi'; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Implements PayloadInterface |
|
90
|
|
|
* emit array payload. |
|
91
|
|
|
* @return string |
|
|
|
|
|
|
92
|
|
|
*/ |
|
93
|
|
|
public function toArray() |
|
94
|
|
|
{ |
|
95
|
|
|
return ['Hi']; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
|
|
|
|
|
98
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.