mezatech/paggern
Composer 安装命令:
composer require mezatech/paggern
包简介
Pattern interpreter for generating random strings.
关键字:
README 文档
README
Pattern interpreter for generating random strings.
Generator
$generator = new \Gajus\Paggern\Generator(); /** * Generate a set of random codes based on Paggern pattern. * Codes are guaranteed to be unique within the set. * * @param string $pattern Paggern pattern. * @param int $amount Number of codes to generate. * @param int $safeguard Number of additional codes generated in case there are duplicates that need to be replaced. * @return array */ $codes = $generator->generateFromPattern('FOO[A-Z]{10}[0-9]{2}', 100);
The above example will generate an array containing 100 codes, each prefixed with "FOO", followed by 10 characters from "ABCDEFGHKMNOPRSTUVWXYZ23456789" haystack and 2 numbers from "0123456789" haystack.
Paggern utilises RandomLib to generate the pattern matching random character pool.
Lexer
Lexer exposes a method to tokenise the string. Lexer is independant of the Generator. You can choose to interpret Lexer tokens using your own implementation of the Generator.
$lexer = new \Gajus\Paggern\Lexer(); /** * Tokeniser explodes input into components describing the properties expressed in the pattern. * * @param string $pattern * @param boolean $expand Augment token definition with the haystack of possible values. * @return array */ $lexer->tokenise('[a-c]{3}[1-3]{3}', true);
[
[
'type' => 'range',
'token' => 'a-c',
'repetition' => 3,
'haystack' => 'abc'
],
[
'type' => 'range',
'token' => '1-3',
'repetition' => 3,
'haystack' => 123
]
]
Supported Tokens
Literal
Pattern can consist of literal characters, e.g. prefix of suffix of the code.
$lexer->tokenise('abc');
[
[
'type' => 'literal',
'string' => 'abc'
]
]
The above pattern commands that the string is literally "abc".
Range
Range can be either numeric or ASCII.
$lexer->tokenise('[a-z]');
In the [a-z] example, string must be a character from "abcdefghijklmnopqrstuvwxyz" haystack.
[
[
'type' => 'range',
'token' => 'a-z',
'repetition' => 1
]
]
Range with Repetition
If the character must occur more than once, use repetition.
$lexer->tokenise('[a-c]{3}');
In the [a-z]{3} example, string must consist of 3 characters from the "abc" haystack.
[
[
'type' => 'range',
'token' => 'a-c',
'repetition' => 3
]
]
Character Classes
Predefined character classes can be used instead of ranges.
| Character Class | Range |
|---|---|
\U |
"ABCDEFGHKMNOPRSTUVWXYZ23456789" (or A-Z0-9 excluding IJLQ01) describes characters that are unambiguously recognised regardless of the font or case-sensitivity. The designated use case is voucher codes. |
Character Classes with Repetition
Similar to the Range with Repetition, Character Classes can be used with repetition, e.g.
$lexer->tokenise('\U{3}');
Limitations
- Pattern cannot include
[]{}characters. - Pattern cannot include characters outside of the ASCII.
mezatech/paggern 适用场景与选型建议
mezatech/paggern 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「parser」 「code」 「voucher」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mezatech/paggern 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mezatech/paggern 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mezatech/paggern 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
An MT940 bank statement parser for PHP
Laravel integration for the jsonapi.org parser
Promotional Codes Generator for Laravel 5.1
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-04-25