Skip to content

[Bundles] Passing parameter value to bundle integerNode value you get string value instead of defined value #38873

Closed
@JohJohan

Description

@JohJohan

Symfony version(s) affected: 4.4 (probably others to)

Description
When writing configuration for a bundle and you use a integerNode you cannot use paramater values to set this configuration because the value that is passed is a string. Also when you use beforeNormalization to parse string values you will get the parameter name instead of the parameter value you have set for that parameter.

How to reproduce
Add a integer node like:
configuration.php

->integerNode('price')
  ->beforeNormalization()
    ->ifString()
      ->then(
        static function ($value) {
          return (int) $value;
        }
      )
    ->end()
  ->isRequired()
  ->defaultValue(999)
->end()

Set parameter value:
parameters.yaml

parameters:
  price_value: 1000

Use parameter value to set the integerNode:
bundle.yaml

bundel:
 price: "%price_value%"

Now you will get 0 as $value because passed value to beforeNormalization is %price_value% instead of expected 1000

Possible Solution

  1. Maybe we could do the same as env and do type casting when useing parameters values see https://symfony.com/doc/current/configuration/env_var_processors.html that way we can pass it like:
bundel:
 price: "%int:price_value%"
  1. Or we could pass the value that is set in parameters so we get 1000 instead of %price_value% when we pass the value to bundle configuration

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions