vendor/codeages/biz-framework/src/Dao/IdGenerator/OrderedTimeUUIDGenerator.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Codeages\Biz\Framework\Dao\IdGenerator;

use Ramsey\Uuid\UuidFactory;
use Ramsey\Uuid\Codec\OrderedTimeCodec;


/**
 * 针对MySQL Innodb优化的按时间序递增的ID生成器
 * 
 * @see https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/
 * @see https://github.com/ramsey/uuid/pull/118
 */
class OrderedTimeUUIDGenerator implements IdGenerator
{
    /**
     * @var Ramsey\Uuid\UuidFactoryInterface
     */
    protected $uuidFactory;

    public function __construct()
    {
        $factory = new UuidFactory();
        $codec = new OrderedTimeCodec($factory->getUuidBuilder());
        $factory->setCodec($codec);

        $this->uuidFactory = $factory;
    }
    /**
     * @inheritDoc
     */
    public function generate($encoded = true)
    {
        if ($encoded) {
            return $this->uuidFactory->uuid1()->getBytes();
        }

        return $this->uuidFactory->uuid1()->toString();
    }

    /**
     * @inheritDoc
     */
    public function encode($id)
    {
        return $this->uuidFactory->fromString($id)->getBytes();
    }

    /**
     * @inheritDoc
     */
    public function decode($idRaw)
    {
        return $this->uuidFactory->fromBytes($idRaw)->toString();
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。