https://github.com/2lenet/configbundle
https://github.com/2lenet/configbundle
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/2lenet/configbundle
- Owner: 2lenet
- Created: 2022-12-12T10:45:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-18T14:39:56.000Z (over 1 year ago)
- Last Synced: 2024-11-19T17:02:13.581Z (over 1 year ago)
- Language: PHP
- Size: 83 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ConfigBundle
[](https://github.com/2lenet/ConfigBundle/actions/workflows/validate.yml)
[](https://github.com/2lenet/ConfigBundle/actions/workflows/test.yml)
[](https://insight.symfony.com/projects/79583c27-dbb5-4610-accd-1ee16b92008d)
Symfony bundle that gives you an easy configuration for your app. Perfect to use with the famous
CRUD [Crudit](https://github.com/2lenet/CruditBundle)
- [Installation](#Installation)
- [Customization](#Customization)
- [Usage](#Usage)
- [Initialise new configurations (Warm-up)](#initialise-new-configurations-warm-up)
## Installation
The bundle is not yet on packagist make sure to add the following to your `composer.json` file:
```json
{
"url": "https://github.com/2lenet/ConfigBundle",
"type": "git"
}
```
Install with composer:
```shell
composer require 2lenet/config-bundle
```
The bundle is flexible and built to suit your project it is shiped only with trait to use in your own config entity.
You will also get a Symfony Repository ready to use.
Create in your entity directory the class `Config` it has to implements the ConfigInterface if no customization is
needed you can use:
```php
establishment;
}
public function setEstablishment(?Establishment $establishment): self
{
$this->establishment = $establishment;
return $this;
}
}
```
You may also need more options than the ones in the Repository file, in that case create a new repository class in your
project. Don't forget to update the namspace used in your entity (see previous exemple).
## Usage
### General overview
To use the bundle, inject in your services the config repository and use one of
the [available methods](#Available-methods).
The bundle will check if the configuration exist otherwise a new configuration will be created.
### Supported configurations
The bundle offers support for configuration in the following formats :
- boolean
- string
- text
- integer
### Available methods
```php
public function getBool($group, $label, bool $default): bool
public function setBool(string $group, string $label, bool $value): void
public function getString($group, $label, string $default): string
public function setString($group, $label, string $value): void
public function getText($group, $label, string $default): string
public function setText($group, $label, string $value): void
public function getInt($group, $label, string $default): int
```
### Twig integration
```twig
{{ get_config_value('type', 'group', 'label', 'default') }}
```
### Initialise new configurations (Warm-up)
A command allows you to initialise new configurations. We suggest to execute it everytime your app starts.
```
bin/console lle:config:warmup
```
To configure the default values, create a class that implements WarmupInterface.
```php
initBool('CONFIG', 'active', true);
}
}
```
Do not use set*(), because it will overwrite defined configurations.