mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-01-26 05:28:11 +00:00
47 lines
829 B
PHP
47 lines
829 B
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the godruoyi/php-snowflake.
|
|
*
|
|
* (c) Godruoyi <g@godruoyi.com>
|
|
*
|
|
* This source file is subject to the MIT license that is bundled.
|
|
*/
|
|
|
|
namespace Godruoyi\Snowflake;
|
|
|
|
class RandomSequenceResolver implements SequenceResolver
|
|
{
|
|
/**
|
|
* The las ttimestamp.
|
|
*
|
|
* @var null
|
|
*/
|
|
protected $lastTimeStamp = -1;
|
|
|
|
/**
|
|
* The sequence.
|
|
*
|
|
* @var int
|
|
*/
|
|
protected $sequence = 0;
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function sequence(int $currentTime)
|
|
{
|
|
if ($this->lastTimeStamp === $currentTime) {
|
|
++$this->sequence;
|
|
$this->lastTimeStamp = $currentTime;
|
|
|
|
return $this->sequence;
|
|
}
|
|
|
|
$this->sequence = 0;
|
|
$this->lastTimeStamp = $currentTime;
|
|
|
|
return 0;
|
|
}
|
|
}
|