1 | <?php |
||
33 | class Generator |
||
34 | { |
||
35 | /** |
||
36 | * @var integer default minimum password size |
||
37 | */ |
||
38 | const DEFAULT_MIN_LENGTH = 6; |
||
39 | /** |
||
40 | * @var integer default maximum password size |
||
41 | */ |
||
42 | const DEFAULT_MAX_LENGTH = 32; |
||
43 | |||
44 | /** |
||
45 | * @var Detector environment detector instance |
||
46 | */ |
||
47 | protected $detector; |
||
48 | /** |
||
49 | * @var array default configurations (key: type => value: configuration) |
||
50 | */ |
||
51 | protected $defaults = [ |
||
52 | 'upperCase' => true, |
||
53 | 'lowerCase' => true, |
||
54 | 'digits' => true, |
||
55 | 'special' => false, |
||
56 | 'brackets' => false, |
||
57 | 'minus' => false, |
||
58 | 'underline' => false, |
||
59 | 'space' => false, |
||
60 | 'length' => 12, |
||
61 | ]; |
||
62 | /** |
||
63 | * @var array data storage |
||
64 | */ |
||
65 | protected $data; |
||
66 | |||
67 | /** |
||
68 | * Detect environment, apply passed configuration and generate a password, if auto generating is turn on. |
||
69 | * |
||
70 | * @param array $config configurations array |
||
71 | * @param integer $minLength custom password minimum length |
||
72 | * @param integer $maxLength custom password maximum length |
||
73 | * @param boolean $autoGenerate whether generate password after initialization |
||
74 | */ |
||
75 | public function __construct(array $config = [], int $minLength = self::DEFAULT_MIN_LENGTH, int $maxLength = self::DEFAULT_MAX_LENGTH, bool $autoGenerate = true) |
||
95 | |||
96 | /** |
||
97 | * Get storage value or option according passed key. |
||
98 | * |
||
99 | * @param string $name specific storage key |
||
100 | * @return mixed the response value |
||
101 | */ |
||
102 | public function __get(string $name) |
||
110 | |||
111 | /** |
||
112 | * Change configuration type value. |
||
113 | * |
||
114 | * @param string $name configuration type |
||
115 | * @param boolean|integer $value the new value |
||
116 | * @return void |
||
117 | */ |
||
118 | public function __set(string $name, $value) |
||
124 | |||
125 | /** |
||
126 | * Generate the password based on configuration array. |
||
127 | * |
||
128 | * @return string the generated password |
||
129 | */ |
||
130 | public function generate(): string |
||
158 | } |
||
159 | |||
160 |