{"id":21311483,"url":"https://github.com/mhujer/consistence-bundle","last_synced_at":"2025-07-23T06:34:43.614Z","repository":{"id":35853317,"uuid":"219749090","full_name":"mhujer/consistence-bundle","owner":"mhujer","description":"ConsistenceBundle adds translator service, translator twig filter and form type for Consistence Enums","archived":false,"fork":false,"pushed_at":"2023-12-09T15:23:18.000Z","size":47,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-08T03:28:07.985Z","etag":null,"topics":["bundle","consistence","enum","enums","php","symfony"],"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/mhujer.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":"2019-11-05T13:15:45.000Z","updated_at":"2022-01-01T10:16:30.000Z","dependencies_parsed_at":"2022-09-09T04:50:15.288Z","dependency_job_id":null,"html_url":"https://github.com/mhujer/consistence-bundle","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/mhujer/consistence-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhujer%2Fconsistence-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhujer%2Fconsistence-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhujer%2Fconsistence-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhujer%2Fconsistence-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mhujer","download_url":"https://codeload.github.com/mhujer/consistence-bundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhujer%2Fconsistence-bundle/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264913996,"owners_count":23682757,"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":["bundle","consistence","enum","enums","php","symfony"],"created_at":"2024-11-21T17:18:33.592Z","updated_at":"2025-07-23T06:34:43.597Z","avatar_url":"https://github.com/mhujer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ConsistenceBundle adds translator service, translator twig filter and form type for Consistence Enums \n \n[![Build Status](https://travis-ci.org/mhujer/consistence-bundle.svg?branch=master)](https://travis-ci.org/mhujer/consistence-bundle)  [![Latest Stable Version](https://poser.pugx.org/mhujer/consistence-bundle/version.png)](https://packagist.org/packages/mhujer/consistence-bundle) [![Total Downloads](https://poser.pugx.org/mhujer/consistence-bundle/downloads.png)](https://packagist.org/packages/mhujer/consistence-bundle) [![License](https://poser.pugx.org/mhujer/consistence-bundle/license.svg)](https://packagist.org/packages/mhujer/consistence-bundle) [![Coverage Status](https://coveralls.io/repos/mhujer/consistence-bundle/badge.svg?branch=master)](https://coveralls.io/r/mhujer/consistence-bundle?branch=master)\n\nThis Bundle provides translator service, translator twig filter and form type for [consistence/consistence](https://github.com/consistence/consistence) enums.\n\n\n# Installation\n\n## Applications that use Symfony Flex\n\nOpen a command console, enter your project directory and execute:\n\n```console\n$ composer require mhujer/consistence-bundle\n```\n\n## Applications that don't use Symfony Flex\n\n### Step 1: Download the Bundle\n\nOpen a command console, enter your project directory and execute the\nfollowing command to download the latest stable version of this bundle:\n\n```console\n$ composer require mhujer/consistence-bundle\n```\n\nThis command requires you to have Composer installed globally, as explained\nin the [installation chapter](https://getcomposer.org/doc/00-intro.md)\nof the Composer documentation.\n\n### Step 2: Enable the Bundle\n\nThen, enable the bundle by adding it to the list of registered bundles\nin the `config/bundles.php` file of your project:\n\n```php\n// config/bundles.php\n\nreturn [\n    // ...\n    Mhujer\\ConsistenceBundle\\MhujerConsistenceBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n# Usage\n\nExamples consider having the following enum:\n\n```php\n\u003c?php declare(strict_types = 1);\n\nnamespace App\\Card;\n\nfinal class CardColor extends \\Consistence\\Enum\\Enum\n{\n\n    public const BLACK = 'black';\n    public const RED = 'red';\n\n}\n```\n\n## Translation file\n\nThe translator automatically converts an instance of enum to a translation key consisting of FQCN of the enum, colon and its value, e.g.:\n\n```\nApp\\Card\\CardColor:red\n```\n\nBest approach is to create a translation file using the PHP format (`enums.en.php`) which allows you to use the class name:\n\n```php\n\u003c?php declare(strict_types = 1);\n\nuse App\\Card\\CardColor;\n\nreturn [\n    CardColor::class . ':' . CardColor::RED =\u003e 'red',\n    CardColor::class . ':' . CardColor::BLACK =\u003e 'black',\n];\n\n```\n\nAs you might have noticed, the translation domain is set to `enums`.\n\n## Twig\n\nIn Twig templates you can use `transEnum` filter to convert an enum to a translated string:\n\n```twig\n{{ variableContainingEnum | transEnum }}\n```\n\n## Translation domain\n\nSometimes it is useful to have different translations for the same enum (e.g. when the enum is used in admin and frontend UI). This is achieved by an `translationDomain` parameter which can be passed to `transEnum`:\n\n```twig\n{{ variableContainingEnum | transEnum('enums-frontend') }}\n```\n\nIt loads translations transparently from another domain using Symfony translator:\n\n\n```php\n// enums-frontend.en.php\n\u003c?php declare(strict_types = 1);\n\nuse App\\Card\\CardColor;\n\nreturn [\n    CardColor::class . ':' . CardColor::RED =\u003e 'Red',\n    CardColor::class . ':' . CardColor::BLACK =\u003e 'Black',\n];\n\n```\n\n\n## Forms\n\nIn forms, you can use `EnumType` as a field type. You need to set an option `enum_class` to an enum class:\n\n```php\npublic function buildForm(FormBuilderInterface $builder, array $options)\n{\n    $builder\n        -\u003eadd('cardColor', EnumType::class, [\n            'enum_class' =\u003e CardColor::class,\n            'label' =\u003e 'Card Color',\n        ])\n    //...\n```\n\nProperty in your [request object](https://blog.martinhujer.cz/symfony-forms-with-request-objects/) should look like this (it contains an instance of `CardColor`):\n\n```php\n/**\n * @Assert\\NotBlank()\n * @var \\App\\Card\\CardColor\n */\npublic $cardColor;\n```\n\n\n# Requirements\nWorks with PHP 7.4 or higher and Symfony 5.4 or higher.\n\n\n# Submitting bugs and feature requests\nBugs and feature request are tracked on [GitHub](https://github.com/mhujer/consistence-bundle/issues)\n\n\n# Author\n[Martin Hujer](https://www.martinhujer.cz) \n\n\n# Changelog\n\n## 2.0.1 (2023-12-09)\n- add Symfony 7 and PHP 8.2 support (dfridrich)\n\n## 2.0.0 (2022-09-20)\n- require PHP 8.1\n- add support for native enums to make migration easier\n\n## 1.4.0 (2021-12-04)\n- require Symfony 5.4+\n- allow PHP 8.1\n- allow Symfony 6.0\n\n## 1.3.0 (2021-06-10)\n- BC break: optional parameter in `transEnum` is treated as translation domain\n\n## 1.2.0 (2021-06-03)\n- add optional parameter `$enumNamespace` to `transEnum` method\n\n## 1.1.0 (2021-02-28)\n- allow PHP 8.0\n- require PHP 7.4+\n\n## 1.0.2 (2020-01-13)\n- Fixed [#3](https://github.com/mhujer/consistence-bundle/issues/3): _Undefined \"translator\" dependency in services.yaml_ \n\n## 1.0.1 (2019-11-24)\n- Symfony 5 and Twig 3 compatibility\n\n## 1.0.0 (2019-11-06)\n- initial release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhujer%2Fconsistence-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmhujer%2Fconsistence-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhujer%2Fconsistence-bundle/lists"}