PHPackages                             jbtronics/settings-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jbtronics/settings-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

jbtronics/settings-bundle
=========================

A symfony bundle to easily create typesafe, user-configurable settings for symfony applications

v3.3.1(2mo ago)9772.9k↑62.2%11[1 issues](https://github.com/jbtronics/settings-bundle/issues)[3 PRs](https://github.com/jbtronics/settings-bundle/pulls)1MITPHPPHP ^8.1CI passing

Since Feb 17Pushed 4d ago3 watchersCompare

[ Source](https://github.com/jbtronics/settings-bundle)[ Packagist](https://packagist.org/packages/jbtronics/settings-bundle)[ Fund](https://www.paypal.me/do9jhb)[ GitHub Sponsors](https://github.com/jbtronics)[ RSS](/packages/jbtronics-settings-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (67)Versions (37)Used By (1)

**[Documentation](https://jbtronics.github.io/settings-bundle/)**

[![codecov](https://camo.githubusercontent.com/ffecedca8f02784d430fb418b707769aec46e522894c2ff3271a608dbb4e6b43/68747470733a2f2f636f6465636f762e696f2f6769746875622f6a6274726f6e6963732f73657474696e67732d62756e646c652f67726170682f62616467652e7376673f746f6b656e3d324947474b394d474f57)](https://codecov.io/github/jbtronics/settings-bundle)

Settings bundle
===============

[](#settings-bundle)

Settings-bundle is a symfony bundle that let you easily create and manage user-configurable settings, which are changeable via a web frontend. It allows for easy creation of type-safe settings objects, which can be easily managed and changed via a web frontend in your symfony application.

Introduction
------------

[](#introduction)

By default, symfony is mostly configured by parameters in configuration files, where a recompilation of the container is required, or via environment variables, which can not be easily changed by the application itself.

However, you often want administrators and users of your application let change settings and configuration of your application. This bundle provides a simple way to do this. Unlike other bundles with a similar goal, this bundle tries to be as modular as possible and to be as type-safe as possible. Therefore you define your Settings as a class, and access objects of this class in your application, instead of doing simple key-value lookups with mixed return types.

All relevant definitions of settings are done directly in the settings class via metadata attributes. This makes it easy to understand and maintain the settings. The bundle also provides a simple way to generate forms to change the settings, which can be easily integrated into your application.

Features
--------

[](#features)

- Class based settings, which get easily managed by the bundle
- Type-safe access to settings
- Easy to use API
- Retrieve settings via dependency injection in service constructors
- Almost zero configuration required in many cases, as the bundle tries to derive as much information as possible from code metadata like property types, etc.
- Various storage backends, like database, json files, PHP files, etc. (custom backends can be easily implemented)
- Use symfony/validator to easily restrict possible values of settings parameters
- Automatically generate forms to change settings
- Easy possibility to version settings and automatically migrate old stored data to the current format
- Possibility to lazy load settings, so that only the settings, which are really needed, are loaded
- Profiler integration for easy debugging
- Ability to use environment variables for easy configuration on automated deployments

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Symfony 6.4 or higher (compatible with Symfony 7.0)
- Symfony/forms and Symfony/validator required if forms should be generated or validation should be used
- twig required if you want to use the twig extension to access settings in your templates
- doctrine/orm and doctrine-bundle required if you want to use the doctrine storage adapter

Installation
------------

[](#installation)

Add the bundle to your symfony project via composer:

```
composer require jbtronics/settings-bundle
```

If you are using symfony flex, the bundle should be automatically enabled. Otherwise you have to add the bundle to your `config/bundles.php` file:

```
return [
    // ...
    Jbtronics\SettingsBundle\JbtronicsSettingsBundle::class => ['all' => true],
];
```

Usage
-----

[](#usage)

*The following section is just a quick overview. See [documentation](https://jbtronics.github.io/settings-bundle/) for full info.*

Settings classes are simple PHP classes, which are annotated with the `#[Settings]` attribute. They must live in the path configured to store settings classes (normally `src/Settings`), in your symfony project. The bundle will automatically find and register all settings classes in this directory.

The properties of the classes are used for storing the different data. Similar to the `#[ORM\Column]` attribute of doctrine, you can use the `#[SettingsParameter]` attribute to make a class property to a managed parameter. The properties can be public, protected or private (as SettingsBundle accesses them via reflection), but you have some kind of possibility to access the properties to get/set the configuration parameters in your software. You have to configure, which type mapper should be used to map the normalized data from the storage backend to the type of property. The bundle comes with a few default type mappers, but you can also implement your own type mappers.

```
