Preferences are configuration variables that are user-managed for which we cannot rely upon container parameters or environment variables.

Overview

Preferences

Preferences are configuration variables that are meant to be user managed for which we cannot rely upon container parameters or environment variables.

This bundle provides a simple API for:

  • Defining a preferences variable schema, with variable name, type, and description.

  • Reading them as environment variables by the container, in order to allow using those variables as services parameters.

  • A form type which handles all basic types (int, type, string) as collections or single-values variables, which you can use in any form.

  • An implementation for storing user values in database using makinacorpus/goat-query.

  • Bus handlers and messages for symfony/messenger, makinacorpus/goat and makinacorpus/corebus.

  • An interface for reading the schema defined in project configuration.

  • An interface for reading values.

Setup

This package is depends on makinacorpus/goat-query.

Simply install this package:

composer require makinacorpus/preferences-bundle

Then add the bundle into your config/bundles.php file:

<?php

return [
    // ... Your other bundles.
    MakinaCorpus\Preferences\PreferencesBundle::class => ['all' => true],
];

Define a custom schema

You can define a schema:

preferences:
    schema:
        app.domain.some_variable:
            label: Some variable
            description: Uncheck this value to deactive this feature
            type: bool
            collection: false
            default: true

Where the number of entries is unlimited. Only limit is your memory because the whole definition will be injected as a bare PHP array into the default array schema implementation.

Please note that because Symfony environment variables processor validates strictly the variables names, all non alpha-numeric and non _ characters will make the environment variable processor fail. If you plan to inject your variables into services using environment variables, you must name your variables accordingly, such as:

preferences:
    schema:
        app_domain_some_variable:
            label: Some variable
            description: Uncheck this value to deactive this feature
            type: bool
            collection: false
            default: true

All options are optional. Defaults are:

preferences:
    enabled: true
    schema:
        app_domain_some_variable:
            label: null
            description: null
            type: string
            allowed_values: null
            collection: false
            hashmap: false
            default: null

Parameters you can set on each variable definition:

  • label: is a human readable short name,
  • description: is a human readable long description,
  • type: can be either of: string, bool, int, float,
  • allowed_values: is an array of arbitrary values, for later validation,
  • collection: if set to true, multiple values are allowed for this variable,
  • hashmap: if set to true, keys are allowed, this is ignored if collection is false,
  • default: arbitrary default value if not configured by the user.

Usage

Inject preferences as service arguments

This package defines a EnvVarProcessorInterface implementation allowing to inject preferences like environment variables, such as:

services:
    my_service:
        class: App\Some\Class
        arguments: ["%env(preference:app_domain_some_variable)%"]

Use Preferences service into other services.

Type hint your injected parameters using MakinaCorpus\Preferences\Preferences then use the get(string $name): mixed method to fetch values.

Long term roadmap

  • Add new repository implementations (Redis, PDO, other...).
  • Implement correctly bus handlers.
  • Implement PHP schema dumper.
You might also like...
A simple shell script which loads a magento environment

A simple shell script to load up a Magento environment and execute PHP code Very experimental and should only be ran on dev servers REQUIRES php pcntl

provides a nested object property based user interface for accessing this configuration data within application code

laminas-config This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steeri

Shortest Path - have a function ShortestPath (strArr) take strArr which will be an array of strings which models a non-looping Graph.

Have the function ShortestPath(strArr) take strArr which will be an array of strings which models a non-looping Graph

Nuber is an open source container management platform it provides a front end to manage your own cloud infrastructure, using Linux Containers virtualization technology

Nuber is an open source container management platform it provides a front end to manage your own cloud infrastructure, using Linux Containers virtualization technology

CDK patterns for serverless container with AWS Fargate

cdk-fargate-patterns CDK patterns for serverless container with AWS Fargate DualAlbFargateService Inspired by Vijay Menon from the AWS blog post intro

Um container colaborativo de inteligência artificial para análise de ativos da b3

B3 Analyser Um container colaborativo de inteligência artificial para análise de ativos da b3 Como colaborar? Faça um FORK do projeto, isto é, copiar

Lumen on Docker - Skeleton project with Nginx, MySQL & PHP 8 | Aws ECS, Google Kubernates, Azure Container Engine

Docker infrastructure for Lumen Description Microservice Lumen is a starting skeleton based on Docker and Lumen Framework. This project helps to devel

This extensions makes it possible to modify the TCA of container children elements

This extensions makes it possible to modify the TCA of container children elements

Container Open Inventory ID send bug fix PocketMine-MP plugin

ContainerOpenFixed Container Open Inventory ID send bug fix PocketMine-MP plugin Example use skh6075\containeropenfixed\IWindowType; use pocketmine\ne

Owner
Makina Corpus
Consulting & development services for web and mobile applications. Working on environmental issues, spatial analysis and data visualisation.
Makina Corpus
A plugin so that players on your server cannot use Frames.

[] AntiFrameEdit | v3.0 A plugin so that players on your server cannot use Frames. ⚡ Features: Personalized messages. Easy to usage. Permissions for p

Jony 5 Dec 18, 2022
This project is very diverse and based upon many languages and libraries such as C++, Python, JavaScript, PHP and MQTT

ADMS-Real-time-project This project is very diverse and based upon many languages and libraries such as C++, Python, JavaScript, PHP and MQTT Advance_

Nitya parikh 1 Dec 1, 2021
bin/magento command to display configured preferences for classes or interfaces

bin/magento command to display configured preferences for classes or interfaces A bin/magento command that will show you the configured preferences fo

David Manners 14 Jul 18, 2022
PHPStorm Live template preferences for Magento 2 Projects

Magento 2 PHPStorm Preferences This project is intended to setup useful PHPStorm Templates for Magento 2 Projects. Disclaimer This project overrides t

Stämpfli AG 229 Jul 18, 2022
A simple library to increase the power of your environment variables.

Environment A simple library (with all methods covered by php unit tests) to increase the power of your environment variables, contribute with this pr

João Paulo Cercal 56 Feb 8, 2022
Color-managed thumbnails for Kirby 3

ImageKit for Kirby 3 This is not directly related for ImageKit for Kirby 2, but based on the same idea of improving Kirby’s built-in image processing

Fabian Michael 13 Nov 21, 2022
urldecode'ing of all HTTP parameters in Lumen project

Request UrlDecode Description This package is intended to perform urldecode of all HTTP parameters in Lumen project. Lumen for some reason does not do

null 1 Dec 13, 2021
A bundle to handle encoding and decoding of parameters using OpenSSL and Doctrine lifecycle events.

SpecShaper Encrypt Bundle A bundle to handle encoding and decoding of parameters using OpenSSL and Doctrine lifecycle events. Features include: Master

Mark Ogilvie 48 Nov 4, 2022
A fully-managed real-time messaging service that allows you to send and receive messages between independent applications.

A fully-managed real-time messaging service that allows you to send and receive messages between independent applications.

Google APIs 58 Dec 23, 2022
Enables developers to modify Magento installations (configuration, data) based on the given environment using n98-magerun.

Enables developers to modify Magento installations (configuration, data) based on the given environment using n98-magerun.

LimeSoda Interactive Marketing GmbH 73 Apr 1, 2022