PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.0.3
WindPress – Tailwind CSS integration for WordPress v3.0.3
3.2.89 3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 All 143 releases
windpress / vendor / hidehalo / nanoid-php / src / Core.php

Core.php in WindPress – Tailwind CSS integration for WordPress 3.0.3, at vendor/hidehalo/nanoid-php/src/Core.php

33 lines 1008 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WindPressPackages\Hidehalo\Nanoid;
4
5 class Core implements CoreInterface
6 {
7 /**
8 * @inheritDoc
9 * @see https://github.com/ai/nanoid/blob/master/async/index.browser.js#L4
10 */
11 public function random(GeneratorInterface $generator, $size, $alphabet = CoreInterface::SAFE_SYMBOLS)
12 {
13 $len = \strlen($alphabet);
14 $mask = (2 << (int) (\log($len - 1) / \M_LN2)) - 1;
15 $step = (int) \ceil(1.6 * $mask * $size / $len);
16 $id = '';
17 while (\true) {
18 $bytes = $generator->random($step);
19 // NOTE: `$bytes` maybe not a normal "Array"
20 // sometimes it's begin from index 1, use iterator please
21 foreach ($bytes as $byte) {
22 $byte &= $mask;
23 if (isset($alphabet[$byte])) {
24 $id .= $alphabet[$byte];
25 if (\strlen($id) === $size) {
26 return $id;
27 }
28 }
29 }
30 }
31 }
32 }
33