kebza / sequence-bundle
Symfony 扩展包,提供创建多个序列用于发票/用户代码的能力。可以保存到数据库或文件
1.0.0
2017-08-07 02:35 UTC
Requires
- php: >=5.6.2
- symfony/framework-bundle: >=3.0
Requires (Dev)
- phpunit/phpunit: ^6.3
This package is auto-updated.
Last update: 2024-09-07 00:12:21 UTC
README
生成序列(用于发票/订单/...)。支持自定义编号格式。
安装
composer require kebza/sequence-bundle
在 AppKernel 中启用扩展包
# app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Kebza\SequenceBundle\KebzaSequenceBundle(), // ... ); }
如果你使用 doctrine 存储,你需要将映射添加到你的实体管理器。
doctrine: orm: mappings: KebzaSequenceBundle: ~
然后更新你的数据库模式
php bin/console doctine:schema:update
配置
在开始之前,你需要配置你的序列。
kebza_sequence: storage: doctrine # file | memory sequences: first: pattern: '{YYYY}{ID|6|WEEK}' step: 1 initial: 1 second: pattern: '{YY}{WW}{ID|6|WEEK}' step: 1 initial: 1
用法
你可以通过请求 kebza.sequence.manager 服务及其方法来使用序列。
// From controller $manager = $this->get('kebza.sequence.manager'); $manager->current('first'); // If sequence not initialized, returns null otherwise current formatted value $manager->next('first'); // Returns next value $manager->increment('first'); // Increments by configuration of step.
存储
- doctrine - 将序列保存到数据库
- file - 将信息保存到目录中的文件
- memory - 脚本结束后,序列的信息将丢失
模式
在模式中可以使用替换来格式化最终输出
- {ID|X|Y} - 将 ID 替换为当前数字。如果指定了 X,将在最终长度中使用零进行填充。Y 可以是 YEAR、MONTH、WEEK,这意味着序列将在每年、每月、每周重置
- {YYYY} - 年份 - 2017
- {YY} - 年份 - 17
- {MM} - 月份 12
- {WW} - 周数