indragunawan/sequence-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

indragunawan/sequence-bundle

Composer 安装命令:

composer require indragunawan/sequence-bundle

包简介

Sequence Implementation

README 文档

README

Documentation

Installation

Step 1: Download bundle

If your project already uses Symfony Flex, execute this command to download, register and configure the bundle automatically:

composer require indragunawan/sequence-bundle

If you install without using Symfony Flex, first add the bundle by using composer then enable the bundle by adding new Indragunawan\SequenceBundle\IndragunawanSequenceBundle() to the list of registered bundles in the app/AppKernel.php file of your project

Step 2: Create your Sequence class

<?php
// src/App/Entity/Sequence.php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Indragunawan\SequenceBundle\Model\Sequence as BaseSequence;

/**
* @ORM\Entity(repositoryClass="App\Repository\SequenceRepository")
*/
class Sequence extends BaseSequence
{
    /**
    * @ORM\Id()
    * @ORM\GeneratedValue(strategy="IDENTITY")
    * @ORM\Column(type="integer")
    */
    private $id;

    public function getId()
    {
        return $this->id;
    }
}

Step 3: Configure the bundle

# app/config/config.yml
indragunawan_sequence:
orm:
    class: App\Entity\Sequence
    manager_name: default #if not set then the default value is 'default'

Step 4: Update your database schema

$ php bin/console doctrine:schema:update --force

Usage

Insert your sequence manually to sequence table in database

Field Data Type Required Properties Description
name string true unique Sequence name that use while you call in service manager
format string false - The format of text or string you want to be generate by service manager
last_value int false - The last value of the sequence
start_value int true - The start value for the sequence
increment_by int true - The increment of sequence value
last_reset datetime false - The date and time that sequence last restart

Format

For format you can see table below:

Format Value Result
null 1 1
'' 2 2
{{NUMBER|3|0}} 3 003
{{ABC}} ['ABC' => 'abcVal'] abcVal
{{NUMBER|5|A}} 4 AAAA4
{{NUMBER|5|A|0}} 5 AAAA5
{{NUMBER|5|A|1}} 6 6AAAA
{{NUMBER|5|A|2}} 7 AA7AA
{{NUMBER|lower|5|A}} 8 aaaa8
{{NUMBER|ucfirst|5|abc}} 9 Abca9
{{NUMBER|upper|5|a|2}} 8 AA8AA
{{y}} - date('y')
{{m}} - date('m')
{{d}} - date('d')

Reserved Placeholder

  • NUMBER (an integer contains sequence counter).
  • php date format See this.
  • Rj, Rn, Ry, RY, Rg for Roman numeral of date format.

Example

format value result
INV/{{NUMBER|3|0}}/{{ABC}} 1, ['ABC'=>'TEST'] INV/001/TEST
INV/{{NUMBER|3|0}} 1 INV/001
INV/{{NUMBER|4|A}} 1 INV/AAA1

another example can be see in Tests/Utils/PlaceholderReplacerTest.php

SequenceManager

NOTE: Sequence manager can only be use inside doctrine transaction

Call in Controller

// use Indragunawan\SequenceBundle\Services\SequenceManager
$sequenceManager = $this->get(SequenceManager::class);
$em->transactional(function () use ($entity) {
  $entity->setSeqNum($sequenceManager->getNextValue('sequence_name'));
});

Call in Event Listener

// use Indragunawan\SequenceBundle\Services\SequenceManagerInterface
// Inject SequenceManagerInterface on constructor

public function prePersist(LifecycleEventArgs $args)
{
    $entity = $args->getObject();
    if ($entity instanceof EntityClass) {
        $args->getObjectManager()->transactional(function () use ($entity) {
            $entity->setSeqNum($this->sequenceManager->getNextValue('sequence_name'));
        });
    }
}

ResetCounter

$ php bin/console indragunawan:sequence:reset-counter sequence_name

You can put this command into Crontab for periodically restart the counter.

License

This bundle is under the MIT license. See the complete license

indragunawan/sequence-bundle 适用场景与选型建议

indragunawan/sequence-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.3k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 05 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-19