本文整理汇总了PHP中Ramsey\Uuid\Uuid::uuid5方法的典型用法代码示例。如果您正苦于以下问题:PHP Uuid::uuid5方法的具体用法?PHP Uuid::uuid5怎么用?PHP Uuid::uuid5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ramsey\Uuid\Uuid
的用法示例。
在下文中一共展示了Uuid::uuid5方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateId
/**
* Generate ID
* @return String
*/
public function generateId($version = 4, $includeDash = false)
{
try {
switch ($version) {
case 1:
$uuid = Uuid::uuid1();
break;
case 3:
$uuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, php_uname('n'));
break;
case 5:
$uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, php_uname('n'));
break;
default:
$uuid = Uuid::uuid4();
break;
}
return $includeDash ? $uuid->toString() : str_replace('-', '', $uuid->toString());
} catch (UnsatisfiedDependencyException $e) {
// Some dependency was not met. Either the method cannot be called on a
// 32-bit system, or it can, but it relies on Moontoast\Math to be present.
echo 'Caught exception: ' . $e->getMessage() . "\n";
exit;
}
}
示例2: createUuid
/**
* @return mixed
* @throws \Exception
*/
public function createUuid()
{
if (!$this->getInstanceIdentifier()) {
throw new \Exception("No instance identifier specified.");
}
$uuid = \Ramsey\Uuid\Uuid::uuid5(\Ramsey\Uuid\Uuid::NAMESPACE_DNS, $this->getInstanceIdentifier());
return $uuid;
}
示例3: stub
/**
* Quick way to set variables for a new lease.
*
* @param $resourceId
* @param null $userId
* @param null $duration
* @return array
*/
public static function stub($resourceId, $userId = null, $duration = null)
{
$duration = is_null($duration) ? 60 : $duration;
$userId = is_null($userId) ? Auth::user()->id : $userId;
$leaseParams = ['resource_id' => $resourceId, 'user_id' => $userId, 'duration' => $duration, 'expires_at' => Carbon::create()->addMinutes($duration)];
$leaseParams['uuid'] = Uuid::uuid5(Uuid::NAMESPACE_DNS, $leaseParams['resource_id'] . $leaseParams['user_id']);
return $leaseParams;
}
示例4: bootUuidModel
/**
* Registering uuid listeners
*/
public static function bootUuidModel()
{
static::creating(function ($model) {
$model->uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, sprintf('%s.%s.%s.%s', rand(0, time()), time(), static::class, config('modelutils.namespace')))->toString();
});
static::saving(function ($model) {
$originalUuid = $model->getOriginal('uuid');
// Preventing lateral modifying uuid
if ($originalUuid !== $model->uuid) {
$model->uuid = $originalUuid;
}
});
}
示例5: generateV5
/**
* Generates a v5 UUID.
*
* @param string $str
* The word to generate the UUID with.
* @param string $namespace
* A namespace
* @return String Valid v5 UUID.
*/
public function generateV5($str, $namespace = NULL)
{
// Use default namespace if none is provided.
if (!empty($namespace)) {
// Is this a UUID already?
if (Uuid::isValid($namespace)) {
return Uuid::uuid5($namespace, $str)->toString();
} else {
return Uuid::uuid5(Uuid::uuid5(Uuid::NAMESPACE_DNS, $namespace), $str)->toString();
}
} else {
return Uuid::uuid5($this->namespace, $str)->toString();
}
}
示例6: generateGuid
public static function generateGuid($reference = null)
{
if (isset($reference)) {
$uuid = Uuid::uuid5(Uuid::NAMESPACE_OID, $reference);
} else {
$uuid = Uuid::uuid4();
}
return '{' . $uuid->toString() . '}';
}
示例7: getCacheKey
/**
* Unique cache key for this Container.
*
* @return string
*/
public function getCacheKey()
{
//Return Key
return 'PersonalityInsights-' . Uuid::uuid5(Uuid::NAMESPACE_DNS, collect(['contentItems' => $this->toArray()])->toJson())->toString();
}
示例8: generateUuid5
/**
* @param string $namespace
* @param string $name
*
* @return $this
*/
public function generateUuid5($namespace, $name)
{
$this->uuid = Uuid::uuid5($namespace, $name);
return $this;
}
示例9: calculateUuid
/**
* Calculates a UUID for a passed string.
*
* @param string $input The input to calculate the UUID for.
*
* @author Benjamin Carl <opensource@clickalicious.de>
*
* @return string The UUID
*/
protected function calculateUuid($input)
{
try {
// Generate a version 5 (name-based and hashed with SHA1) UUID object
$uuid5 = Uuid::uuid5(Uuid::NAMESPACE_DNS, $input);
$uuid = $uuid5->toString();
} catch (UnsatisfiedDependencyException $e) {
$uuid = sha1($input);
}
return $uuid;
}
示例10: uuid
/**
* Generate and return a UUID.
*
* If the $name parameter is provided, set the namespace to the provided
* name and generate a UUID.
*
* @param string $name
* @return string
*/
public function uuid($name = null)
{
if (is_null($name)) {
$uuid = Uuid::uuid4();
} else {
if (stristr($name, 'http') == false) {
$uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, $name);
} else {
$uuid = Uuid::uuid5(Uuid::NAMESPACE_URL, $name);
}
}
return $this->encode($uuid);
}
示例11: testShouldAcceptUuid5
public function testShouldAcceptUuid5()
{
$uuid = new Uuid(BaseUuid::uuid5(BaseUuid::NAMESPACE_DNS, 'user'));
$this->assertInstanceOf('App\\Domain\\Identity\\Uuid', $uuid);
}
示例12: v5
/**
* UUID v5 generator.
*
* @since 150424 Initial release.
*
* @param string $namespace Namespace.
* @param string $identifier Identifier.
* @param bool $optimize Optimize?
*
* @return string Version 5 UUID (32 bytes optimized).
* Or 36 bytes unoptimized; i.e., w/ dashes.
*/
public function v5(string $namespace, string $identifier, bool $optimize = true) : string
{
switch ($namespace) {
case 'dns':
$namespace = UuidGen::NAMESPACE_DNS;
break;
// Stop here.
// Stop here.
case 'url':
$namespace = UuidGen::NAMESPACE_URL;
break;
// Stop here.
// Stop here.
case 'oid':
$namespace = UuidGen::NAMESPACE_OID;
break;
// Stop here.
// Stop here.
case 'x500':
$namespace = UuidGen::NAMESPACE_X500;
break;
// Stop here.
// Stop here.
default:
throw $this->c::issue('Invalid namespace.');
}
$uuid = UuidGen::uuid5($namespace, $identifier)->toString();
return $optimize ? str_replace('-', '', $uuid) : $uuid;
}
示例13: uuidProvider
public function uuidProvider()
{
return array(array(Uuid::uuid1()), array(Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net')), array(Uuid::uuid4()), array(Uuid::uuid5(Uuid::NAMESPACE_DNS, 'php.net')), array(Uuid::fromString(self::UUID_SAMPLE)));
}
示例14: pageId
/**
* Generates a hash based on page identifier
*
* @param string $identifier
* @param null|integer $id
* @return string
*/
private static function pageId($identifier, $id = null)
{
$uuid5 = Uuid::uuid5(Uuid::NAMESPACE_DNS, $identifier);
if ($id) {
$uuid5 = Uuid::uuid5(Uuid::NAMESPACE_DNS, $identifier . '-' . $id);
}
return $uuid5;
}
示例15: createUuid
/**
* Creates the requested UUID
*
* @param int $version
* @param string $namespace
* @param string $name
* @return Uuid
*/
protected function createUuid($version, $namespace = null, $name = null)
{
switch ((int) $version) {
case 1:
$uuid = Uuid::uuid1();
break;
case 4:
$uuid = Uuid::uuid4();
break;
case 3:
case 5:
$ns = $this->validateNamespace($namespace);
if (empty($name)) {
throw new Exception('The name argument is required for version 3 or 5 UUIDs');
}
if ($version == 3) {
$uuid = Uuid::uuid3($ns, $name);
} else {
$uuid = Uuid::uuid5($ns, $name);
}
break;
default:
throw new Exception('Invalid UUID version. Supported are version "1", "3", "4", and "5".');
}
return $uuid;
}