|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The RandomLib library for securely generating random numbers and strings in PHP |
|
5
|
|
|
* |
|
6
|
|
|
* @author Anthony Ferrara <[email protected]> |
|
7
|
|
|
* @copyright 2011 The Authors |
|
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
|
9
|
|
|
* @version Build @@version@@ |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* The Mixer strategy interface. |
|
14
|
|
|
* |
|
15
|
|
|
* All mixing strategies must implement this interface |
|
16
|
|
|
* |
|
17
|
|
|
* PHP version 5.3 |
|
18
|
|
|
* |
|
19
|
|
|
* @category PHPPasswordLib |
|
20
|
|
|
* @package Random |
|
21
|
|
|
* |
|
22
|
|
|
* @author Anthony Ferrara <[email protected]> |
|
23
|
|
|
* @copyright 2011 The Authors |
|
24
|
|
|
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
|
25
|
|
|
* @license http://www.gnu.org/licenses/lgpl-2.1.html LGPL v 2.1 |
|
26
|
|
|
*/ |
|
27
|
|
|
namespace RandomLibtest\Mocks\Random; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The Mixer strategy interface. |
|
31
|
|
|
* |
|
32
|
|
|
* All mixing strategies must implement this interface |
|
33
|
|
|
* |
|
34
|
|
|
* @category PHPPasswordLib |
|
35
|
|
|
* @package Random |
|
36
|
|
|
* |
|
37
|
|
|
* @author Anthony Ferrara <[email protected]> |
|
38
|
|
|
*/ |
|
39
|
|
|
class Generator extends \RandomLib\Generator |
|
40
|
|
|
{ |
|
41
|
|
|
protected $callbacks = array(); |
|
42
|
|
|
|
|
43
|
|
|
public static function init() |
|
44
|
|
|
{ |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function __construct(array $callbacks = array()) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->callbacks = $callbacks; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function __call($name, array $args = array()) |
|
53
|
|
|
{ |
|
54
|
|
|
if (isset($this->callbacks[$name])) { |
|
55
|
|
|
return call_user_func_array($this->callbacks[$name], $args); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function addSource(\PasswordLib\Random\Source $source) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->__call('addSource', array($source)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function generate($size) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->__call('generate', array($size)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function generateInt($min = 0, $max = \PHP_INT_MAX) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->__call('generateInt', array($min, $max)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function generateString($length, $chars = '') |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->__call('generateString', array($length, $chars)); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|