This repository was archived by the owner on Oct 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?php
22namespace Nats ;
33
4+ use PhpSpec \CodeGenerator \Generator \GeneratorInterface ;
45use RandomLib \Factory ;
56use RandomLib \Generator ;
67
@@ -115,7 +116,7 @@ public function getSubscriptions()
115116 private $ streamSocket ;
116117
117118 /**
118- * @var Generator
119+ * @var Generator|Php71RandomGenerator
119120 */
120121 private $ randomGenerator ;
121122
@@ -130,8 +131,12 @@ public function __construct(ConnectionOptions $options = null)
130131 $ this ->pubs = 0 ;
131132 $ this ->subscriptions = [];
132133 $ this ->options = $ options ;
133- $ randomFactory = new Factory ();
134- $ this ->randomGenerator = $ randomFactory ->getLowStrengthGenerator ();
134+ if (version_compare (phpversion (), '7.0 ' , '> ' )){
135+ $ this ->randomGenerator = new Php71RandomGenerator ();
136+ } else {
137+ $ randomFactory = new Factory ();
138+ $ this ->randomGenerator = $ randomFactory ->getLowStrengthGenerator ();
139+ }
135140
136141 if (is_null ($ options )) {
137142 $ this ->options = new ConnectionOptions ();
Original file line number Diff line number Diff line change 1+ <?php
2+
3+
4+ namespace Nats ;
5+
6+
7+
8+ class Php71RandomGenerator
9+ {
10+ /**
11+ * A simple wrapper on random_bytes
12+ *
13+ * @param $len
14+ * @return string
15+ */
16+ public function generateString ($ len ) {
17+ return bin2hex (random_bytes ($ len ));
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments