ソースを参照

parent 5a3768be4c2e550afd0178a7c43a0fef784d63a6
author nojimage <nojimage@gmail.com> 1574768435 +0900
committer Corey Taylor <corey.taylor.fl@gmail.com> 1575464245 -0600

Updated Text::uuid() to use random_int from paragonie/random_compat with PHP 5.6

nojimage 6 年 前
コミット
02e8bcdf38
3 ファイル変更11 行追加12 行削除
  1. 2 1
      composer.json
  2. 8 10
      src/Utility/Text.php
  3. 1 1
      tests/TestCase/Error/ErrorHandlerTest.php

+ 2 - 1
composer.json

@@ -35,7 +35,8 @@
         "aura/intl": "^3.0.0",
         "psr/log": "^1.0.0",
         "psr/simple-cache": "^1.0.0",
-        "zendframework/zend-diactoros": "^1.4.0"
+        "zendframework/zend-diactoros": "^1.4.0",
+        "paragonie/random_compat": "^2.0|9.99.99"
     },
     "suggest": {
         "ext-openssl": "To use Security::encrypt() or have secure CSRF token generation.",

+ 8 - 10
src/Utility/Text.php

@@ -60,25 +60,23 @@ class Text
      */
     public static function uuid()
     {
-        $random = function_exists('random_int') ? 'random_int' : 'mt_rand';
-
         return sprintf(
             '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
             // 32 bits for "time_low"
-            $random(0, 65535),
-            $random(0, 65535),
+            random_int(0, 65535),
+            random_int(0, 65535),
             // 16 bits for "time_mid"
-            $random(0, 65535),
+            random_int(0, 65535),
             // 12 bits before the 0100 of (version) 4 for "time_hi_and_version"
-            $random(0, 4095) | 0x4000,
+            random_int(0, 4095) | 0x4000,
             // 16 bits, 8 bits for "clk_seq_hi_res",
             // 8 bits for "clk_seq_low",
             // two most significant bits holds zero and one for variant DCE1.1
-            $random(0, 0x3fff) | 0x8000,
+            random_int(0, 0x3fff) | 0x8000,
             // 48 bits for "node"
-            $random(0, 65535),
-            $random(0, 65535),
-            $random(0, 65535)
+            random_int(0, 65535),
+            random_int(0, 65535),
+            random_int(0, 65535)
         );
     }
 

+ 1 - 1
tests/TestCase/Error/ErrorHandlerTest.php

@@ -476,7 +476,7 @@ class ErrorHandlerTest extends TestCase
      */
     public function testHandlePHP7Error()
     {
-        $this->skipIf(!class_exists('Error'), 'Requires PHP7');
+        $this->skipIf(version_compare(PHP_VERSION, '7.0.0', '<'), 'Requires PHP7');
         $error = new PHP7ErrorException(new ParseError('Unexpected variable foo'));
         $errorHandler = new TestErrorHandler();