Download the PHP package fedale/setting-bundle without Composer

On this page you can find all versions of the php package fedale/setting-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package setting-bundle

Fedale Setting Bundle

Multi-tenant application settings stored in the database and editable at runtime — not Symfony parameters compiled into the container.

Installation

Register the bundle (Symfony Flex does it for you):

Configuration (optional, defaults shown):

Database schema

The bundle auto-registers the ORM mapping of the Setting entity; generate the migration in your app with php bin/console make:migration. Equivalent schema:

tenant_id = 0 holds the global default configuration; tenant_id > 0 holds the per-tenant overrides.

value is stored as a string; type (string|int|float|bool|json) drives the (de)serialization: scalars stay human-readable (123, not "123"), complex values are stored as JSON under type = 'json'.

Usage

Reading settings in Twig

When TwigBundle is installed, the bundle registers a setting() function. It is read-only — writes are done in PHP via SettingsManagerInterface::set().

Signature:

Examples:

Key points:

Multi-tenant: resolving the current tenant

When tenantId is not passed, the bundle uses TenantProviderInterface. By default (DefaultTenantProvider) the current tenant is always 0. Multi-tenant apps register their own implementation:

Custom storage

To use a source other than Doctrine, implement Fedale\SettingBundle\Contract\SettingStorageInterface and point fedale_setting.provider at the service id. Caching and the per-tenant fallback are still handled by the bundle.

Validating values

By default keys are free-form: any value is accepted. You can opt specific keys into validation, enforced at the single write choke point (SettingsManager::set()), so the rules hold no matter where the write comes from — a form, a CLI command or plain code. Keys without declared rules stay free-form.

Validation builds on symfony/validator (install it: composer require symfony/validator). Declare the per-key constraints by registering a service that implements SettingConstraintsProviderInterface; the bundle ships ArrayConstraintsProvider for the common static-map case:

Then enable validation, pointing it at the provider:

Now a write that breaks a rule throws SettingValidationException instead of persisting:

For dynamic rules (e.g. constraints stored in the database or computed per key), implement SettingConstraintsProviderInterface directly instead of using ArrayConstraintsProvider. Return [] for any key that must stay free-form:

With autowiring, just point constraints_provider at the class id:

How the validation flow fits together

  1. SettingsManagerInterface::set($key, $value, ...) is called (form, CLI or code).
  2. Before persisting, the manager calls the configured SettingValidatorInterface.
  3. With validation enabled, ConstraintsSettingValidator asks your provider for the constraints of $key. No constraints → the value is accepted (free-form).
  4. Otherwise the value is checked with symfony/validator; on failure a SettingValidationException is thrown and nothing is written.

This means the rules are enforced once, at the single write choke point, so you cannot bypass them by writing from a different entry point.

Scoped settings

Free-form keys fit application-wide settings. Some values instead depend on where they apply: a grid option set for every grid or for one grid, a booking rule set for an event type, a resource or a single occurrence. Scoped settings cover that case: a consumer bundle declares its settings, and the bundle resolves each one along a chain of scopes, most specific first.

They are an additional layer: SettingsManagerInterface, the setting table and free-form keys are untouched.

Enabling them

With the default store: null the feature is off: ScopedSettingsResolver::isEnabled() returns false, lookups find nothing and writes throw. The resolver and the writer are always registered, so a bundle can depend on them unconditionally.

The doctrine store uses its own table, mapped only when it is selected; generate the migration with php bin/console make:migration. Equivalent schema:

A lookup reads only the scopes of its chain, through a PSR-6 cache (the pool and ttl of fedale_setting.cache) with one item per tenant, namespace and scope. Levels with many ids, such as occurrences or users, stay cheap.

Declaring a setting

One class per setting, implementing SettingDefinitionInterface or extending AbstractSettingDefinition. With autoconfiguration it is picked up automatically (tag fedale_setting.definition).

Part Meaning
namespace() / key() Identity; [a-z0-9_.], the key is unique within the namespace
type() Bool, Int, Float, String, Enum
supportsScope() The scope levels the setting can be set at
choices() label key => value; required for Enum, null = free input
constraints() Validator constraints checked on write, when symfony/validator is installed
isApplicable($value, $context) Guard at resolve time, with a context supplied by the caller

There is no default value in the definition: when nothing is found the setting is simply missing from the result, and the consumer keeps its own configuration in code.

Resolving: tenant first, then the chain

A scope is a level and, except for global, an id: Scope::global(), new Scope('grid', 'users'). The consumer builds the chain, most specific first. Tenant 0 holds platform defaults, which never beat a tenant's own choice, so the whole chain of the current tenant is walked before the one of tenant 0:

With these stored values:

tenant scope renderer
0 global table
0 grid:users list
5 global cards

tenant 5 gets cards on the users grid (its own global beats the platform's per-grid default), any other tenant gets list there and table elsewhere.

A candidate is skipped, and the lookup moves on, when:

The same lookup with five levels, for a booking rule:

Writing

ScopedSettingsWriter is the single write choke point:

Each value must be a declared setting, settable at that scope, of the right type, one of the choices if any, and pass constraints(). Keys not passed are left untouched.

Custom store

Implement Fedale\SettingBundle\Scoped\Store\ScopedStoreInterface and point fedale_setting.scoped.store at the service id. The store persists strings and does not know the setting types; the bundle wraps it in the PSR-6 cache.

Cache

The settings.0 and settings.{tenantId} layers are cached separately and merged in memory on each read. A set() only invalidates the layer it touches: changing a global default (tenant 0) therefore propagates to all tenants by invalidating a single entry.

License

MIT.


All versions of setting-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
psr/cache Version ^3.0
psr/log Version ^1.1 || ^2.0 || ^3.0
symfony/config Version ^6.4 || ^7.0 || ^8.0
symfony/dependency-injection Version ^6.4 || ^7.0 || ^8.0
symfony/http-kernel Version ^6.4 || ^7.0 || ^8.0
symfony/service-contracts Version ^2.5 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fedale/setting-bundle contains the following files

Loading the files please wait ...