{"id":22425199,"url":"https://github.com/2lenet/configbundle","last_synced_at":"2025-08-01T08:32:51.594Z","repository":{"id":65208674,"uuid":"577259950","full_name":"2lenet/ConfigBundle","owner":"2lenet","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-18T14:39:56.000Z","size":85,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-19T17:02:13.581Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2lenet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-12T10:45:00.000Z","updated_at":"2024-10-18T14:36:49.000Z","dependencies_parsed_at":"2024-06-19T21:57:27.625Z","dependency_job_id":"a05a29b5-094b-4aea-9c97-da6f8a99893a","html_url":"https://github.com/2lenet/ConfigBundle","commit_stats":{"total_commits":13,"total_committers":5,"mean_commits":2.6,"dds":0.5384615384615384,"last_synced_commit":"06e24538d765ad8b9c1b08e4be4307ad99f8a3b6"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lenet%2FConfigBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lenet%2FConfigBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lenet%2FConfigBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lenet%2FConfigBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2lenet","download_url":"https://codeload.github.com/2lenet/ConfigBundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228356403,"owners_count":17907191,"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":[],"created_at":"2024-12-05T19:13:28.229Z","updated_at":"2025-08-01T08:32:51.576Z","avatar_url":"https://github.com/2lenet.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ConfigBundle\n\n[![Validate](https://github.com/2lenet/ConfigBundle/actions/workflows/validate.yml/badge.svg)](https://github.com/2lenet/ConfigBundle/actions/workflows/validate.yml)\n[![.github/workflows/test.yml](https://github.com/2lenet/ConfigBundle/actions/workflows/test.yml/badge.svg)](https://github.com/2lenet/ConfigBundle/actions/workflows/test.yml)\n[![SymfonyInsight](https://insight.symfony.com/projects/79583c27-dbb5-4610-accd-1ee16b92008d/mini.svg)](https://insight.symfony.com/projects/79583c27-dbb5-4610-accd-1ee16b92008d)\n\n\nSymfony bundle that gives you an easy configuration for your app. Perfect to use with the famous\nCRUD [Crudit](https://github.com/2lenet/CruditBundle)\n\n- [Installation](#Installation)\n- [Customization](#Customization)\n- [Usage](#Usage)\n- [Initialise new configurations (Warm-up)](#initialise-new-configurations-warm-up)\n\n## Installation\n\nThe bundle is not yet on packagist make sure to add the following to your `composer.json` file:\n\n```json\n{\n    \"url\": \"https://github.com/2lenet/ConfigBundle\",\n    \"type\": \"git\"\n}\n```\n\nInstall with composer:\n\n```shell\ncomposer require 2lenet/config-bundle\n```\n\nThe bundle is flexible and built to suit your project it is shiped only with trait to use in your own config entity.\n\nYou will also get a Symfony Repository ready to use.\n\nCreate in your entity directory the class `Config` it has to implements the ConfigInterface if no customization is\nneeded you can use:\n\n```php\n\u003c?php\n\nnamespace App\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Lle\\ConfigBundle\\Traits\\ConfigTrait;\nuse App\\Repository\\ConfigRepository;\nuse Lle\\ConfigBundle\\Contracts\\ConfigInterface;\n\n/**\n * @ORM\\Entity(repositoryClass=ConfigRepository::class)\n */\nclass Config implements ConfigInterface\n{\n    use ConfigTrait;\n}\n\n```\n\nYour repository file has to extend the ConfigRepository from the bundle:\n\n```php\n\u003c?php\n\nnamespace App\\Repository;\n\nuse App\\Entity\\Config;\nuse Doctrine\\Persistence\\ManagerRegistry;\nuse Lle\\ConfigBundle\\Repository\\AbstractConfigRepository;\nuse Lle\\ConfigBundle\\Service\\CacheManager;\n\n/**\n * @method Config|null find($id, $lockMode = null, $lockVersion = null)\n * @method Config|null findOneBy(array $criteria, array $orderBy = null)\n * @method Config[]    findAll()\n * @method Config[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)\n */\nclass ConfigRepository extends AbstractConfigRepository\n{\n    public function __construct(ManagerRegistry $registry, CacheManager $cacheManager)\n    {\n        parent::__construct($cacheManager, $registry, Config::class);\n    }\n...\n}\n\n```\n\nIn your project add the folowing to the config file: `/config/packages/doctrine.yaml`\n\n```yaml\ndoctrine:\n    orm:\n        resolve_target_entities:\n            Lle\\ConfigBundle\\Contracts\\ConfigInterface: App\\Entity\\Config\n```\n\nIn `/config/routes.yaml` add:\n\n```yaml\nlle_config:\n    resource: \"@LleConfigBundle/Resources/config/routes.yaml\"\n```\n\nYou can then create a migration\n\n```shell\nbin/console make:migration\n```\n\nCheck the migration file created and ask doctrine to execute the migration :\n\n```shell\nbin/console doctrine:migrations:migrate\n```\n\nYou are ready to go!\n\n## Customization\n\nIf you need more options or entity fields you can add them in your entity class:\n\n```php\n\u003c?php\n\nnamespace App\\Entity;\n\nuse App\\Repository\\ConfigRepository;\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Lle\\ConfigBundle\\Contracts\\ConfigInterface;\nuse Lle\\ConfigBundle\\Traits\\ConfigTrait;\n\n/**\n * @ORM\\Entity(repositoryClass=ConfigRepository::class)\n */\nclass Config implements ConfigInterface\n{\n    use ConfigTrait;\n\n    /**\n     * @ORM\\ManyToOne(targetEntity=Establishment::class, inversedBy=\"configs\")\n     * @ORM\\JoinColumn(nullable=false)\n     */\n    private ?Establishment $establishment;\n\n    public function getEstablishment(): ?Establishment\n    {\n        return $this-\u003eestablishment;\n    }\n\n    public function setEstablishment(?Establishment $establishment): self\n    {\n        $this-\u003eestablishment = $establishment;\n\n        return $this;\n    }\n}\n\n```\n\nYou may also need more options than the ones in the Repository file, in that case create a new repository class in your\nproject. Don't forget to update the namspace used in your entity (see previous exemple).\n\n## Usage\n\n### General overview\n\nTo use the bundle, inject in your services the config repository and use one of\nthe [available methods](#Available-methods).\nThe bundle will check if the configuration exist otherwise a new configuration will be created.\n\n### Supported configurations\n\nThe bundle offers support for configuration in the following formats :\n\n- boolean\n- string\n- text\n- integer\n\n### Available methods\n\n```php\n    public function getBool($group, $label, bool $default): bool\n   \n    public function setBool(string $group, string $label, bool $value): void\n    \n    public function getString($group, $label, string $default): string\n    \n    public function setString($group, $label, string $value): void\n   \n    public function getText($group, $label, string $default): string\n    \n    public function setText($group, $label, string $value): void\n   \n    public function getInt($group, $label, string $default): int\n```\n\n### Twig integration\n\n```twig\n{{ get_config_value('type', 'group', 'label', 'default') }}\n```\n\n### Initialise new configurations (Warm-up)\n\nA command allows you to initialise new configurations. We suggest to execute it everytime your app starts.\n\n```\nbin/console lle:config:warmup\n```\n\nTo configure the default values, create a class that implements WarmupInterface.\n\n```php\n\u003c?php\n\nnamespace App\\Warmup;\n\nuse Lle\\ConfigBundle\\Contracts\\WarmupInterface;\nuse Lle\\ConfigBundle\\Repository\\AbstractConfigRepository;\n\nclass ConfigWarmup implements WarmupInterface\n{\n    public function warmup(AbstractConfigRepository $configRepository): void\n    {\n        $configRepository-\u003einitBool('CONFIG', 'active', true);\n    }\n}\n```\n\nDo not use set*(), because it will overwrite defined configurations.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2lenet%2Fconfigbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2lenet%2Fconfigbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2lenet%2Fconfigbundle/lists"}