nubitio / sequence-bundle
Opt-in atomic field numbering for Nubit Symfony apps via the Sequence attribute and a shared counter table.
Package info
github.com/nubitio/sequence-bundle
Type:symfony-bundle
pkg:composer/nubitio/sequence-bundle
Requires
- php: >=8.5
- api-platform/core: ^4.1
- doctrine/orm: ^3.0
- nubitio/api-platform: 0.*
- symfony/config: ^7.4 || ^8.0
- symfony/dependency-injection: ^7.4 || ^8.0
- symfony/framework-bundle: ^7.4 || ^8.0
- symfony/property-access: ^7.4 || ^8.0
- symfony/serializer: ^7.4 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^12.0
README
Opt-in atomic numbering for document fields.
Install
composer require nubitio/sequence-bundle
Create the counter table (once per app):
CREATE TABLE nubit_sequence_counter ( id SERIAL PRIMARY KEY, scope_key VARCHAR(190) NOT NULL, name VARCHAR(64) NOT NULL, next_value INT NOT NULL DEFAULT 1, CONSTRAINT UNIQ_SEQUENCE_SCOPE_NAME UNIQUE (scope_key, name) );
Or run a Doctrine migration that maps Nubit\SequenceBundle\Entity\SequenceCounter.
Usage
use Nubit\SequenceBundle\Attribute\Sequence; #[Sequence(field: 'number', name: 'order', prefix: 'ORD-', padding: 4, scope: ['restaurant'])] class Order { // number is allocated on POST when left empty }
Counters are isolated per scope (restaurant:1|…) and sequence name (order).
Frontend integration
The Hydra API doc publishes x-sequence on the resource class so @nubitio/react-admin hides the allocated field on create/edit forms and marks it read-only in the grid:
{
"@id": "#Order",
"x-sequence": {
"field": "number",
"name": "order",
"prefix": "ORD-",
"padding": 4,
"scope": ["restaurant"]
}
}
No manual visibleOnForm: false on the sequence property is required when the bundle is enabled.