承接 simensen/sequence 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

simensen/sequence

Composer 安装命令:

composer require simensen/sequence

包简介

Sequences

README 文档

README

Sequence is an opinionated model for generating sequences of unique integers.

Description

This model was designed to extract and make explicit the requirement that some models need to have auto-incrementing behavior. It originated from a project that required MySQL-style auto-incrementing fields.

Installation

Install the project with Composer:

composer require simensen/sequence

Usage

Sequence

The Sequence<T> Interface

The Sequence<T> interface represents the state of an incrementing numeric value.

Calling a Sequence's next(): T method will return the next value. The core expectations for the next value:

  • The next value SHOULD be a number (int)
  • The next value SHOULD be unique to the sequence

Additional Sequences (see below for Sequences) may provide additional guarantees.

Sequence Configuration

Attributes are provided to facilitate commonly needed Sequence configuration without introducing these concepts through the public interfaces.

Connection

Used to configure the connection name used by the sequence.

CurrentValueColumn

Used to configure the column or field name that contains the sequence's current value.

DefaultStartValue

Used to configure the start value of a sequence.

Name

Used to configure the name of the sequence.

NameColumn

Used to configure the column or field that contains the sequence's name.

Table

Used to configure the table or document name that contains the sequence.

NumericSequence

The NumericSequence abstract class can be used when a native int will suffice.

use Simensen\Sequence\NumericSequence;

#[Connection('accounting_db')]
#[Table('invoice_number_sequence')]
final readonly class InvoiceNumber extends NumericSequence
{
}

CastedSequence

The CastedSequence<T> abstract class can be used when a model wraps the native int with a value object of type T. The transformation from int to type T is facilitated by a cast(int $next): T method.

use Simensen\Sequence\CastedSequence;

/**
 * @extends CastedSequence<PartId>
 */
#[Table('part_id_seq')]
final readonly class PartIdSequence extends CastedSequence
{
    protected function cast(int $next): PartId
    {
        return PartId::fromInt($next);
    }
}

Sequences

The Sequences interface provides the bridge between a Sequence and its underlying persistence infrastructure.

Calling a Sequences' nextValueForSequence($sequenceClassName): int method will return the next value for the specified $sequenceClassName. The core expectations for the next value:

  • The Sequences MAY require additional configuration
    • The Sequences MAY introduce additional Sequence Configuration attributes
  • The Sequences SHOULD read and map the Sequence Configuration attributes where possible
    • An in-memory implementation may not care about Column, Connection, or Table
    • A database-backed implementation may care about Column, Connection, or Table
  • The next value SHOULD be a number (int)
  • The next value SHOULD be unique to at least the sequence

Additional Sequences may provide additional guarantees.

GlobalInMemorySequences

This Sequences implementation is useful for testing. It generates unique next values using the same underlying value for every type of Sequence<T>.

use Simensen\Sequence\Sequences\Adapter\GlobalInMemorySequences;

$sequences = new GlobalInMemorySequences();

$userIdSequence = new UserIdSequence($sequences);
$serviceIdSequence = new ServiceIdSequence($sequences);

$userIdSequence->next(); // 1
$userIdSequence->next(); // 2

$serviceIdSequence->next(); // 3

$userIdSequence->next(); // 4

ClassBasedInMemorySequences

This Sequences implementation is useful for testing. It generates unique next values using a different underlying value for every type of Sequence<T>.

use Simensen\Sequence\Sequences\Adapter\ClassBasedInMemorySequences;

$sequences = new ClassBasedInMemorySequences();

$userIdSequence = new UserIdSequence($sequences);
$serviceIdSequence = new ServiceIdSequence($sequences);

$userIdSequence->next(); // 1
$userIdSequence->next(); // 2

$serviceIdSequence->next(); // 1

$userIdSequence->next(); // 3

CurrentValueManagement

The CurrentValueManagement interface exposes additional functionality for Sequences to manage aspects of Sequence's current value.

registerPotentialCurrentValueForSequence

Useful for backfilling sequence-related data. This method sets the current value to the specified value only if it is a larger value than the existing current value.

This method is called with a Sequence<T> class name and a potential current value.

If the Sequence<T> does not have a current value yet, the default start value is used for the current value.

If the potential current value is greater than the current value for the Sequence<T>, the potential current value becomes the new current value.

Otherwise, there is no change to the current value.

forceSetCurrentValueForSequence

Useful in testing. This method sets the current value to the specified value regardless of the existing current value.

This method is called with a Sequence<T> class name and a value.

The current value for the Sequence<T> is always set to the new value.

License

This project is licensed under the MIT License. See the LICENSE file for more details on terms and conditions.

Feel free to use and contribute to the project under these terms!

simensen/sequence 适用场景与选型建议

simensen/sequence 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.16k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 simensen/sequence 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 simensen/sequence 我们能提供哪些服务?
定制开发 / 二次开发

基于 simensen/sequence 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-30