{"id":15021922,"url":"https://github.com/indragunawan/sequence-bundle","last_synced_at":"2025-04-10T20:33:32.515Z","repository":{"id":47965929,"uuid":"134042763","full_name":"IndraGunawan/sequence-bundle","owner":"IndraGunawan","description":"Sequence implementation for Symfony Framework","archived":false,"fork":false,"pushed_at":"2021-08-11T12:40:02.000Z","size":32,"stargazers_count":5,"open_issues_count":2,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T18:11:19.755Z","etag":null,"topics":["sequence","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IndraGunawan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-19T08:05:48.000Z","updated_at":"2020-09-17T19:50:01.000Z","dependencies_parsed_at":"2022-08-12T15:21:11.089Z","dependency_job_id":null,"html_url":"https://github.com/IndraGunawan/sequence-bundle","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndraGunawan%2Fsequence-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndraGunawan%2Fsequence-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndraGunawan%2Fsequence-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndraGunawan%2Fsequence-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IndraGunawan","download_url":"https://codeload.github.com/IndraGunawan/sequence-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248290044,"owners_count":21078923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sequence","symfony-bundle"],"created_at":"2024-09-24T19:57:13.427Z","updated_at":"2025-04-10T20:33:32.488Z","avatar_url":"https://github.com/IndraGunawan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sequence Bundle\n\n## Documentation\n* [Installation](#installation)\n* [Usage](#usage)\n  - [Format](#format)\n  - [Using Sequence Manager](#SequenceManager)\n  - [Reset Counter](#ResetCounter)\n\n### Installation\n#### Step 1: Download bundle\nIf your project already uses Symfony Flex, execute this command to download, register and configure the bundle automatically:\n\n```bash\ncomposer require indragunawan/sequence-bundle\n```\n\nIf 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\n\n#### Step 2: Create your Sequence class\n\n```php\n\u003c?php\n// src/App/Entity/Sequence.php\n\nnamespace App\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Indragunawan\\SequenceBundle\\Model\\Sequence as BaseSequence;\n\n/**\n* @ORM\\Entity(repositoryClass=\"App\\Repository\\SequenceRepository\")\n*/\nclass Sequence extends BaseSequence\n{\n    /**\n    * @ORM\\Id()\n    * @ORM\\GeneratedValue(strategy=\"IDENTITY\")\n    * @ORM\\Column(type=\"integer\")\n    */\n    private $id;\n\n    public function getId()\n    {\n        return $this-\u003eid;\n    }\n}\n```\n\n#### Step 3: Configure the bundle\n\n```yaml\n# app/config/config.yml\nindragunawan_sequence:\norm:\n    class: App\\Entity\\Sequence\n    manager_name: default #if not set then the default value is 'default'\n```\n\n#### Step 4: Update your database schema\n\n```bash\n$ php bin/console doctrine:schema:update --force\n```\n\n### Usage\n\n#### Insert your sequence manually to sequence table in database\n\n| Field | Data Type | Required | Properties | Description |\n| ----- | --------- | -------- | ---------- | ----------- |\n| name | string | true | unique | Sequence name that use while you call in service manager |\n| format | string | false | - | The format of text or string you want to be generate by service manager |\n| last_value | int | false | - | The last value of the sequence |\n| start_value | int | true | - | The start value for the sequence |\n| increment_by | int | true | - | The increment of sequence value |\n| last_reset | datetime | false | - | The date and time that sequence last restart |\n\n### Format\n#### For format you can see table below:\n\n| Format | Value | Result |\n| ------ | ------ | --- |\n| null | 1 | 1 |\n| '' | 2 | 2 |\n| {{NUMBER\\|3\\|0}} | 3 | 003 |\n| {{ABC}} | ['ABC' =\u003e 'abcVal'] | abcVal |\n| {{NUMBER\\|5\\|A}} | 4 | AAAA4 |\n| {{NUMBER\\|5\\|A\\|0}} | 5 | AAAA5 |\n| {{NUMBER\\|5\\|A\\|1}} | 6 | 6AAAA |\n| {{NUMBER\\|5\\|A\\|2}} | 7 | AA7AA |\n| {{NUMBER\\|lower\\|5\\|A}} | 8 | aaaa8 |\n| {{NUMBER\\|ucfirst\\|5\\|abc}} | 9 | Abca9 |\n| {{NUMBER\\|upper\\|5\\|a\\|2}} | 8 | AA8AA |\n| {{y}} | - | date('y') |\n| {{m}} | - | date('m') |\n| {{d}} | - | date('d') |\n\n#### Reserved Placeholder\n* NUMBER (an integer contains sequence counter).\n* php date format [See this](http://php.net/manual/en/function.date.php).\n* Rj, Rn, Ry, RY, Rg for Roman numeral of date format.\n\n#### Example\n\n| format | value | result |\n| --- | --- | --- |\n| INV/{{NUMBER\\|3\\|0}}/{{ABC}} | 1, ['ABC'=\u003e'TEST'] | INV/001/TEST |\n| INV/{{NUMBER\\|3\\|0}} | 1 | INV/001 |\n| INV/{{NUMBER\\|4\\|A}} | 1 | INV/AAA1 |\n\nanother example can be see in ``Tests/Utils/PlaceholderReplacerTest.php``\n\n### SequenceManager\n\n#### NOTE: Sequence manager can only be use inside doctrine transaction\n\n### Call in Controller\n```php\n\n// use Indragunawan\\SequenceBundle\\Services\\SequenceManager\n$sequenceManager = $this-\u003eget(SequenceManager::class);\n$em-\u003etransactional(function () use ($entity) {\n  $entity-\u003esetSeqNum($sequenceManager-\u003egetNextValue('sequence_name'));\n});\n```\n\n### Call in Event Listener\n```php\n// use Indragunawan\\SequenceBundle\\Services\\SequenceManagerInterface\n// Inject SequenceManagerInterface on constructor\n\npublic function prePersist(LifecycleEventArgs $args)\n{\n    $entity = $args-\u003egetObject();\n    if ($entity instanceof EntityClass) {\n        $args-\u003egetObjectManager()-\u003etransactional(function () use ($entity) {\n            $entity-\u003esetSeqNum($this-\u003esequenceManager-\u003egetNextValue('sequence_name'));\n        });\n    }\n}\n```\n\n### ResetCounter\n```bash\n$ php bin/console indragunawan:sequence:reset-counter sequence_name\n```\nYou can put this command into Crontab for periodically restart the counter.\n\n## License\nThis bundle is under the MIT license. See the complete [license](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findragunawan%2Fsequence-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findragunawan%2Fsequence-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findragunawan%2Fsequence-bundle/lists"}