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