Skip to content

Inconsistent recommendations about Semantic Configurations #2879

Closed
@ChristopherMoll

Description

@ChristopherMoll

The cookbook page on extensions recommends avoiding semantic configuration if it's not needed:

When you create a bundle, you have two choices on how to handle configuration:

Normal Service Configuration (easy):
...

Exposing Semantic Configuration (advanced):
...

The second option - which you'll learn about in this article - is much more flexible, but also requires more time to setup. If you're wondering which method you should use, it's probably a good idea to start with method #1, and then change to #2 later if you need to.

On the other hand, the cookbook page on bundle best practices recommends using semantic configuration even in simpler applications:

To provide more flexibility, a bundle can provide configurable settings by using the Symfony2 built-in mechanisms.
For simple configuration settings, rely on the default parameters entry of the Symfony2 configuration. Symfony2 parameters are simple key/value pairs; a value being any valid PHP value. Each parameter name should start with the bundle alias, though this is just a best-practice suggestion. The rest of the parameter name will use a period (.) to separate different parts (e.g. acme_hello.email.from).
The end user can provide values in any configuration file:

# app/config/config.yml
parameters:
    acme_hello.email.from: fabien@example.com

Retrieve the configuration parameters in your code from the container:

$container->getParameter('acme_hello.email.from');

Even if this mechanism is simple enough, you are highly encouraged to use the semantic configuration described in the cookbook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions