[TASK] add RandomStringUtility
This commit is contained in:
parent
c9bd34eb23
commit
8f24164f03
32
Classes/Utility/RandomStringUtility.php
Normal file
32
Classes/Utility/RandomStringUtility.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
namespace Cjel\TemplatesAide\Utility;
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* This file is part of the "" Extension for TYPO3 CMS.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the
|
||||||
|
* LICENSE.txt file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* (c) 2019 Philipp Dieter <philipp@glanzstueck.agency>, Glanzstück GmbH
|
||||||
|
*
|
||||||
|
***/
|
||||||
|
|
||||||
|
class RandomStringUtility
|
||||||
|
{
|
||||||
|
public static function getToken(
|
||||||
|
int $length = 64,
|
||||||
|
string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
): string {
|
||||||
|
if ($length < 1) {
|
||||||
|
throw new \RangeException("Length must be a positive integer");
|
||||||
|
}
|
||||||
|
$pieces = [];
|
||||||
|
$max = mb_strlen($keyspace, '8bit') - 1;
|
||||||
|
for ($i = 0; $i < $length; ++$i) {
|
||||||
|
$pieces []= $keyspace[random_int(0, $max)];
|
||||||
|
}
|
||||||
|
return implode('', $pieces);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user