Download the PHP package sherlockode/configuration-bundle without Composer

On this page you can find all versions of the php package sherlockode/configuration-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 configuration-bundle

Sherlockode ConfigurationBundle

This bundle is built to allow users to define configuration options, useful in admin panels. Get rid of the business logic variables in your ENV or parameters.yml file !

Available features:

CircleCI Total Downloads Latest Stable Version

Installation

The best way to install this bundle is to rely on Composer:

Setup

Enable the bundle in the kernel

You will need a Parameter entity in order to store the configuration values in the database.

Configuration

The entity class you just created must be set in the bundle's configuration:

Now you are free to define any configuration entry you'd like by using the parameters key:

Translations

By default parameters labels are not translated in the form provided by the bundle. If you want to use translations you can define a translation_domain key globally and/or for each parameter and use your translation key as the label.

Options

Each type of field may accept a various range of options that can be defined under the options key.

Every field may have a required option to define if the input field will be required (it defaults to true). The other options are up to the field and its needs. For instance, the choice field allow to define multiple and choices options in order to customize the form.

Every field may also have a constraints option to define validation constraints. You can use Symfony built-in constraints or add your own:

Usage

Default controller

All configured parameters can be edited with the provided controller. You may import the routing file in order to access it, the listing will be available at URI /parameters.

You can also modify the default template used by this controller with the templates configuration entry point:

Custom code for the Form

If you have more specific usages, you can build your own form using the ParametersType, a FormType dedicated to editing the parameters. The model data for the form is an associative array of the paths and existing values. You can get the existing parameters from the DB using the service sherlockode_configuration.parameter_manager:

Access configuration values

You are now able to retrieve any configuration value by using the get method from the parameter manager. It is possible to provide a default value to return if the entry has not been set yet.

Import / export from the browser

You can export or import parameters in a yaml file. You have two routes for these operations:

You also can customize the import form template by defining your own in the configuration:

Import / export from CLI

You can export or import your parameters with these two Symfony commands:

These commands rely on the Symfony secrets mechanism. So be sure to generate your credentials with the following command:

Events

When parameters are saved in database, multiple events are dispatched

Field types

Default types

Here are the field types provided in the bundle, located in the namespace Sherlockode\ConfigurationBundle\FieldType :

Custom Field types

In order to add custom field types, you should create a service implementing the FieldTypeInterface interface and tag it with sherlockode_configuration.field (or use autoconfiguration).

The getName() return value is the alias of the field type to use in the configuration (like simple or choice).

Using transformers

Due to the format of the Parameter entity in the database (the value is stored as a string, whatever the parameter type), complex values cannot be stored directly. For instance, we can serialize an array to fit the string type, or we may store the ID of a database entity. The process may vary depending on your needs and the value to store, but the application needs to be aware of the process to transform the PHP data into a string and the opposite process. This is done through transformers.

A transformer is an object implementing the Sherlockode\ConfigurationBundle\Transformer\TransformerInterface. The interface has two methods transform and reverseTransform, similarly to the transformers used by Symfony in the Form Component.

The transform method takes the string representation and returns the PHP value, when the reverseTransform takes your PHP value and returns back the corresponding scalar value.

In order to be used, an instance of the transformer should be returned by the getModelTransformer method of the corresponding field type. If this method returns null, the bundle considers that no transformation is needed.

The bundle also provides a CallbackTransformer that can be used for faster implementations. For instance handling an array can be done like this :

License

This bundle is under the MIT license. Check the details in the dedicated file


All versions of configuration-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
symfony/framework-bundle Version ^6.0 || ^7.0
symfony/validator Version ^6.0 || ^7.0
twig/twig Version ^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 sherlockode/configuration-bundle contains the following files

Loading the files please wait ....