Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JohJohan opened this issue Oct 28, 2020 · 6 comments

Comments

@JohJohan
Copy link
Contributor

JohJohan commented Oct 28, 2020

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
@JohJohan JohJohan added the Bug label Oct 28, 2020
@JohJohan JohJohan changed the title Passing parameter value to bundle integerNode value you get string value instead of defined value [Bundles] Passing parameter value to bundle integerNode value you get string value instead of defined value Oct 28, 2020
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@JohJohan
Copy link
Contributor Author

JohJohan commented May 3, 2021

Hi, the workarround is to just pass the value directly but then you have 2 config values. Let me know if you want me to pick it up i think solution 1 is the most neat one

@carsonbot carsonbot removed the Stalled label May 3, 2021
@ro0NL
Copy link
Contributor

ro0NL commented May 5, 2021

See also #40906, beforeNormalization is up for debate :)

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants