Skip to content
Permalink
Browse files

Fixed unique bug

  • Loading branch information...
stelin committed Jul 31, 2019
1 parent 24d0038 commit 444ddeb51e0741dda06e8f548f2579cf534bdf30
@@ -11,6 +11,7 @@
use function sprintf;
use Swoft\Aop\Concern\AopTrait;
use Swoft\Proxy\Ast\Visitor\Visitor;
use Swoft\Stdlib\Helper\Str;
use function uniqid;
/**
@@ -69,7 +70,7 @@ class ProxyVisitor extends Visitor
public function __construct(string $proxyId = '', string $aopClassName = AopTrait::class)
{
$this->aopClassName = $aopClassName;
$this->proxyId = $proxyId ?: uniqid();
$this->proxyId = $proxyId ?: Str::getUniqid();
}
/**
@@ -8,6 +8,7 @@
use Swoft\Proxy\Proxy as BaseProxy;
use Swoft\Rpc\Client\Exception\RpcClientException;
use Swoft\Rpc\Client\Proxy\Ast\ProxyVisitor;
use Swoft\Stdlib\Helper\Str;
class Proxy
{
@@ -26,7 +27,7 @@ public static function newClassName(string $className): string
);
}
$proxyId = sprintf('IGNORE_%s', uniqid());
$proxyId = sprintf('IGNORE_%s', Str::getUniqid());
$visitor = new ProxyVisitor($proxyId);
$className = BaseProxy::newClassName($className, $visitor);
return $className;
@@ -56,7 +56,7 @@ class StringHelper
/**
* Transliterate a UTF-8 value to ASCII.
*
* @param string $value
* @param string $value
*
* @return string
*/
@@ -72,8 +72,8 @@ public static function ascii($value): string
/**
* Convert a value to camel case.
*
* @param string $value
* @param bool $lcfirst
* @param string $value
* @param bool $lcfirst
*
* @return string
*/
@@ -113,8 +113,8 @@ public static function explode(string $str, string $separator = ',', int $limit
/**
* Determine if a given string contains a given substring.
*
* @param string $haystack
* @param string|array $needles
* @param string $haystack
* @param string|array $needles
*
* @return bool
*/
@@ -132,8 +132,8 @@ public static function contains(string $haystack, $needles): bool
/**
* Determine if a given string ends with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @param string $haystack
* @param string|array $needles
*
* @return bool
*/
@@ -150,6 +150,7 @@ public static function endsWith(string $haystack, $needles): bool
/**
* @param string $str
*
* @return string
*/
public static function firstLine(string $str): string
@@ -168,8 +169,8 @@ public static function firstLine(string $str): string
/**
* Cap a string with a single instance of a given value.
*
* @param string $value
* @param string $cap
* @param string $value
* @param string $cap
*
* @return string
*/
@@ -183,8 +184,8 @@ public static function finish($value, $cap): string
/**
* Determine if a given string matches a given pattern.
*
* @param string $pattern
* @param string $value
* @param string $pattern
* @param string $value
*
* @return bool
*/
@@ -207,7 +208,7 @@ public static function is(string $pattern, string $value): bool
/**
* Return the length of the given string.
*
* @param string $value
* @param string $value
*
* @return int
*/
@@ -226,6 +227,7 @@ public static function len(string $value): int
* @param int $padLen
* @param string $padStr
* @param int $padType
*
* @return string
*/
public static function pad(string $string, int $padLen, string $padStr = ' ', int $padType = STR_PAD_RIGHT): string
@@ -246,9 +248,9 @@ public static function padRight(string $string, int $padLen, string $padStr = '
/**
* Limit the number of characters in a string.
*
* @param string $value
* @param int $limit
* @param string $end
* @param string $value
* @param int $limit
* @param string $end
*
* @return string
*/
@@ -264,7 +266,7 @@ public static function limit($value, $limit = 100, $end = '...'): string
/**
* Convert the given string to lower-case.
*
* @param string $value
* @param string $value
*
* @return string
*/
@@ -276,9 +278,9 @@ public static function lower(string $value): string
/**
* Limit the number of words in a string.
*
* @param string $value
* @param int $words
* @param string $end
* @param string $value
* @param int $words
* @param string $end
*
* @return string
*/
@@ -296,8 +298,8 @@ public static function words($value, $words = 100, $end = '...'): string
/**
* Parse a `Class@method` style callback into class and method.
*
* @param string $callback
* @param string $default
* @param string $callback
* @param string $default
*
* @return array
*/
@@ -324,7 +326,7 @@ public static function uniqID(string $prefix = '', bool $moreEntropy = false): s
/**
* Generate a more truly "random" alpha-numeric string.
*
* @param int $length
* @param int $length
*
* @return string
* @throws RuntimeException
@@ -335,7 +337,7 @@ public static function random(int $length = 16): string
$string = '';
while (($len = strlen($string)) < $length) {
$size = $length - $len;
$size = $length - $len;
$bytes = random_bytes($size);
$string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
@@ -347,7 +349,7 @@ public static function random(int $length = 16): string
/**
* Generate a more truly "random" bytes.
*
* @param int $length
* @param int $length
*
* @return string
* @throws Exception
@@ -374,7 +376,7 @@ public static function randomBytes(int $length = 16): string
* Generate a "random" alpha-numeric string.
* Should not be considered sufficient for cryptography, etc.
*
* @param int $length
* @param int $length
*
* @return string
*/
@@ -390,8 +392,8 @@ public static function quickRandom(int $length = 16): string
* Note: This method will leak length information.
* Note: Adapted from Symfony\Component\Security\Core\Util\StringUtils.
*
* @param string $knownString
* @param string $userInput
* @param string $knownString
* @param string $userInput
*
* @return bool
* @deprecated since version 5.2. Use hash_equals instead.
@@ -404,9 +406,9 @@ public static function equals(string $knownString, string $userInput): bool
/**
* Replace the first occurrence of a given value in the string.
*
* @param string $search
* @param string $replace
* @param string $subject
* @param string $search
* @param string $replace
* @param string $subject
*
* @return string
*/
@@ -424,9 +426,9 @@ public static function replaceFirst($search, $replace, $subject): string
/**
* Replace the last occurrence of a given value in the string.
*
* @param string $search
* @param string $replace
* @param string $subject
* @param string $search
* @param string $replace
* @param string $subject
*
* @return string
*/
@@ -444,7 +446,7 @@ public static function replaceLast(string $search, $replace, string $subject): s
/**
* Convert the given string to upper-case.
*
* @param string $value
* @param string $value
*
* @return string
*/
@@ -456,7 +458,7 @@ public static function upper(string $value): string
/**
* Convert the given string to title case.
*
* @param string $value
* @param string $value
*
* @return string
*/
@@ -468,8 +470,8 @@ public static function title($value): string
/**
* Generate a URL friendly "slug" from a given string.
*
* @param string $title
* @param string $separator
* @param string $title
* @param string $separator
*
* @return string
*/
@@ -494,8 +496,8 @@ public static function slug(string $title, string $separator = '-'): string
/**
* Convert a string to snake case.
*
* @param string $value
* @param string $delimiter
* @param string $value
* @param string $delimiter
*
* @return string
*/
@@ -519,8 +521,8 @@ public static function snake(string $value, string $delimiter = '_'): string
/**
* Determine if a given string starts with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @param string $haystack
* @param string|array $needles
*
* @return bool
*/
@@ -538,7 +540,7 @@ public static function startsWith(string $haystack, $needles): bool
/**
* Convert a value to studly caps case.
*
* @param string $value
* @param string $value
*
* @return string
*/
@@ -558,9 +560,9 @@ public static function studly($value): string
/**
* Returns the portion of string specified by the start and length parameters.
*
* @param string $string
* @param int $start
* @param int|null $length
* @param string $string
* @param int $start
* @param int|null $length
*
* @return string
*/
@@ -572,7 +574,7 @@ public static function substr(string $string, $start, $length = null): string
/**
* Make a string's first character uppercase.
*
* @param string $string
* @param string $string
*
* @return string
*/
@@ -624,8 +626,8 @@ public static function strSplit($str, $splitLength = 1)
* // Output:
* XCDDVXV7FUSYAVXFFKSL
*
* @param string $type A type of pool, or a string of characters to use as the pool
* @param integer $length Length of string to return
* @param string $type A type of pool, or a string of characters to use as the pool
* @param integer $length Length of string to return
*
* @return string
* @throws Exception
@@ -738,6 +740,7 @@ public static function formatPath(string $path): string
/**
* @param string $path
*
* @return string
*/
public static function rmPharPrefix(string $path): string
@@ -749,6 +752,19 @@ public static function rmPharPrefix(string $path): string
return $path;
}
/**
* @param string $prefix
* @param bool $moreEntropy
*
* @return string
*/
public static function getUniqid(string $prefix = "", bool $moreEntropy = false): string
{
$uniqid = uniqid($prefix, $moreEntropy);
$uniqid = str_replace('.', '', $uniqid);
return $uniqid;
}
/**
* @param array|string $queryData
*
@@ -43,4 +43,12 @@ public function testRmPharPrefix(): void
$path = Str::rmPharPrefix('/vendor/composer/.env');
$this->assertSame('/vendor/composer/.env', $path);
}
public function testGetUnique(): void
{
$uniqueId = Str::getUniqid();
$this->assertNotEmpty($uniqueId);
$this->assertIsString($uniqueId);
}
}

0 comments on commit 444ddeb

Please sign in to comment.
You can’t perform that action at this time.