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 TokenBucket data class. |
18
|
|
|
* |
19
|
|
|
* It stubs constructor parameters for: |
20
|
|
|
* bandwithThottle\tokenBucket\TokenBucket |
21
|
|
|
* |
22
|
|
|
* Initial properties for a new TokenBucket instance via |
23
|
|
|
* \Projectmentor\Quota\Factories\FactoryInterface |
24
|
|
|
* |
25
|
|
|
* @author David Faith <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class TokenBucketData implements PayloadInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* The maximum token capacity |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $capacity; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The bucket refresh rate |
37
|
|
|
* @var \bandwithThrottle\tokenBucket\Rate |
38
|
|
|
*/ |
39
|
|
|
protected $rate; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The storage instance |
43
|
|
|
* @var \bandwidthThrottle\tokenBucket\storage\FileStorage |
44
|
|
|
*/ |
45
|
|
|
protected $storage; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Initialize $this |
49
|
|
|
* @param int $capacity of the bucket |
50
|
|
|
* @param \bandwithThrottle\tokenBucket\Rate |
51
|
|
|
* @param \bandwidthThrottle\tokenBucket\storage\FileStorage |
52
|
|
|
* @return void |
|
|
|
|
53
|
|
|
*/ |
54
|
|
|
public function __construct($capacity, $rate, $storage) |
55
|
|
|
{ |
56
|
|
|
$this->capacity = $capacity; |
57
|
|
|
$this->rate = $rate; |
|
|
|
|
58
|
|
|
$this->storage = $storage; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the token bucket capacity |
63
|
|
|
* i.e: the maximum number of |
64
|
|
|
* tokens available at any time. |
65
|
|
|
* |
66
|
|
|
* @return int |
67
|
|
|
*/ |
68
|
|
|
public function getCapacity() |
69
|
|
|
{ |
70
|
|
|
return $this->capacity; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get Rate instance |
75
|
|
|
* |
76
|
|
|
* @return \bandwidthThrottle\tokenBucket\Rate |
|
|
|
|
77
|
|
|
*/ |
78
|
|
|
public function getRate() |
79
|
|
|
{ |
80
|
|
|
return $this->rate; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the storage instance. |
85
|
|
|
* |
86
|
|
|
* @return \bandwithThrottle\tokenBucket\storage\FileStorage |
|
|
|
|
87
|
|
|
*/ |
88
|
|
|
public function getStorage() |
89
|
|
|
{ |
90
|
|
|
return $this->storage; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Implements PayloadInterface |
95
|
|
|
* emit json payload. |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function toJson() |
99
|
|
|
{ |
100
|
|
|
return 'Hi'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Implements PayloadInterface |
105
|
|
|
* emit array payload. |
106
|
|
|
* @return string |
|
|
|
|
107
|
|
|
*/ |
108
|
|
|
public function toArray() |
109
|
|
|
{ |
110
|
|
|
return ['Hi']; |
111
|
|
|
} |
112
|
|
|
} |
|
|
|
|
113
|
|
|
|
Adding a
@return
annotation 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.