sbooker / persistent-sequences
Persistent sequences
Installs: 4 886
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: ^7.4 || ^8.0
- sbooker/transaction-manager: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.0
Suggests
- doctrine/orm: If you want use DB persistence with Doctrine
- sbooker/doctrine-transaction-handler: If you want use DB persistence with Doctrine
README
Supports custom number generation by user-defined algorithms.
Installation
composer require sbooker/persistent-sequences
Usage
Step 1. Define Sequence mapping to persistent storage
Step 2. Define you custom sequence calculation algorithm. For example:
class ConcreteAlgorithm implements \Sbooker\PersistentSequences\Algorithm { public function first(): string { // return first item in sequence } public function next(string $currentValue): string { // return next item in sequence } }
Step 3. Define you sequence write storage or use Doctrine implementation
class ConcreteWriteStorage implements \Sbooker\PersistentSequences\SequenceWriteStorage { //... }
Step 4. Configure SequenceGenerator
$sequenceGenerator = new \Sbooker\PersistentSequences\SequenceGenerator( new ConcreteWriteStorage(), new \Sbooker\TransactionManager\TransactionManager( // see sbooker/transaction-manager ) );
Step 5. Use SequenceGenerator to generate sequence
$number = $sequenceGenerator->next('concrete-seq', new ConcreteAlgorithm());
License
See LICENSE file.