-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathText.php
More file actions
55 lines (48 loc) · 1.33 KB
/
Text.php
File metadata and controls
55 lines (48 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
*
* Description
*
* @package Paystack
* @category Source
* @author Michael Akanji <matscode@gmail.com>
* @date 2017-06-26
* @copyright (c) 2016 - 2017, TECRUM (http://www.tecrum.com)
*
*/
namespace Matscode\Paystack\Utility;
class Text
{
/**
*
* @author Hackan <hackan@gmail.com>
* @link https://php.net/manual/en/function.uniqid.php#120123
*
* @param int $length
*
* @param int $capsMix
*
* @return bool|string
* @throws \Exception
*/
public static function uniqueRef( $length = 15, $capsMix = 5 )
{
// uniqid gives 15 chars, but you could adjust it to your needs.
if ( function_exists( "random_bytes" ) ) {
$bytes = random_bytes( ceil( $length / 2 ) );
} elseif ( function_exists( "openssl_random_pseudo_bytes" ) ) {
$bytes = openssl_random_pseudo_bytes( ceil( $length / 2 ) );
} else {
throw new \Exception( "No cryptographically secure random function available" );
}
if ( $capsMix > 10 ) {
throw new \Exception( 'capsMix can not be greater than 10' );
}
$caps = substr( str_shuffle( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ), 1, $capsMix );
return str_shuffle( substr( bin2hex( $bytes ), 0, $length ) . $caps );
}
public static function removeSlashes( $string )
{
return trim( $string, '/' );
}
}