1 | <?php |
||
15 | class RandomReader extends AbstractGenerator |
||
16 | { |
||
17 | /** @var string Path to the random device */ |
||
18 | private $source; |
||
19 | |||
20 | /** @var resource|null File pointer to the random source */ |
||
21 | private $pointer; |
||
22 | |||
23 | /** |
||
24 | * Creates new instance of RandomReader. |
||
25 | * @param bool $urandom True to read from /dev/urandom and false to read from /dev/random |
||
26 | */ |
||
27 | 10 | public function __construct($urandom = true) |
|
32 | |||
33 | /** |
||
34 | * Closes the file pointer. |
||
35 | */ |
||
36 | 10 | public function __destruct() |
|
37 | { |
||
38 | 10 | if (isset($this->pointer)) { |
|
39 | 9 | fclose($this->pointer); |
|
40 | 3 | } |
|
41 | |||
42 | 10 | $this->pointer = null; |
|
43 | 10 | } |
|
44 | |||
45 | 10 | public function isSupported() |
|
49 | |||
50 | 9 | protected function readBytes($count) |
|
54 | |||
55 | /** |
||
56 | * Returns the pointer to the random source. |
||
57 | * @return resource The pointer to the random source |
||
58 | */ |
||
59 | 9 | private function getPointer() |
|
73 | } |
||
74 |