Conditions | 2 |
Paths | 2 |
Total Lines | 11 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
26 | public static function generate(string $path, string $url, int $length = 16): string |
||
27 | { |
||
28 | if (!extension_loaded('openssl')) { |
||
29 | throw new RuntimeException('OpenSSL is not installed.'); |
||
30 | } |
||
31 | |||
32 | File::makeDir(dirname($path)); |
||
33 | file_put_contents($path, openssl_random_pseudo_bytes($length)); |
||
34 | file_put_contents($path_f = File::tmpFile(), implode(PHP_EOL, [$url, $path, bin2hex(openssl_random_pseudo_bytes($length))])); |
||
35 | |||
36 | return $path_f; |
||
37 | } |
||
38 | } |